Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-70261

Upload Courses tool breaks on locked custom fields

    XMLWordPrintable

    Details

    • Sprint:
      Moppies Kanban

      Description

      Steps to reproduce:

       

      1. Visit /course/customfield.php. Create a new custom field.
      2. Edit the custom field, set "Locked" = "Yes".
      3. Visit /admin/tool/uploadcourse/index.php
      4. Upload a simple course CSV, e.g:
      5. shortname,fullname,category
        test1,Test 1,1

      1. Click "Preview". You should get an error: "Coding error detected, it must be fixed by a programmer: Only course or course category context expected"

       

      This error is caused by incorrect assumptions in /course/classes/customfield/course_handler.php, in the can_edit function:

      return (!$field->get_configdata_property('locked') || guess_if_creator_will_have_course_capability('moodle/course:changelockedcustomfields', $context));
      
      

      When uploading a course, $context will always be an instance of context_system, because the caller passes $instanceid = 0. The function guess_if_creator_will_have_course_capability does not allow $context to be a context_system instance. So if the field in question is locked, that function is called with a context_system instance and a coding error is thrown.

        Attachments

          Activity

            People

            Assignee:
            ilyatregubov Ilya Tregubov
            Reporter:
            seth.a.yoder Seth Yoder
            Peer reviewer:
            Amaia Anabitarte
            Integrator:
            Víctor Déniz Falcón
            Tester:
            Janelle Barcega
            Participants:
            Component watchers:
            Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              18/Jan/21

                Time Tracking

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 hours, 7 minutes
                4h 7m