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

Upload Courses tool breaks on locked custom fields

    XMLWordPrintable

Details

    • MOODLE_310_STABLE, MOODLE_39_STABLE
    • MOODLE_310_STABLE, MOODLE_39_STABLE
    • MDL-70261-master
    • Hide
      1. Create a course
      2. Go to course/customfield.php and create a short text custom field with shortname test of type short text
      3. Edit field and set it to locked
      4. create a csv file 

        shortname,fullname,category,customfield_test
        testcourse,Test course,1,blabla
        

      5. Go to admin/tool/uploadcourse/index.php and upload your csv file. Click preview
      6. Ensure you are able to preview you course, no exception is thrown.
      7. Ensure after uploading a course you can see custom field is set in course setting
      Show
      Create a course Go to course/customfield.php and create a short text custom field with shortname test of type short text Edit field and set it to locked create a csv file  shortname,fullname,category,customfield_test testcourse,Test course, 1 ,blabla Go to admin/tool/uploadcourse/index.php and upload your csv file. Click preview Ensure you are able to preview you course, no exception is thrown. Ensure after uploading a course you can see custom field is set in course setting
    • 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

            ilyatregubov Ilya Tregubov
            seth.a.yoder Seth Yoder
            Amaia Anabitarte Amaia Anabitarte
            Victor Déniz Falcón Victor Déniz Falcón
            Janelle Barcega Janelle Barcega
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

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

                Clockify

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.