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

core_filters_get_available_in_context: Cannot use object of type context_module as array

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide
      1. As admin, enable "Mobile services": Site administration ► Mobile app ► Mobile settings
      2. Create a Token in the mobile app service for one user NOT enrolled in any course (and not the admin):
        • Click on Site administration ► Plugins ► Web services ► Manage tokens
      3. Now, copy the course module id of any activity or resource within any course in the site (a course the user does not have access to)
      4. Next, you can do a CURL REST call simulating a WS client with the user.
        • You need to replace the wstoken, and the URL of your moodle instance and replacing the X (value of the contexts[0][instanceid] parameter) with the course module id you copied

          curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'contexts[0][contextlevel]=module&contexts[0][instanceid]=X&wsfunction=core_filters_get_available_in_context&wstoken=12a2a65aeea2a177055e233f9e303218' | python -m "json.tool"

      5. Confirm that after executing the request:
        • You get a warning structure including a warning with "item" set to "context"
      Show
      As admin, enable "Mobile services": Site administration ► Mobile app ► Mobile settings Create a Token in the mobile app service for one user NOT enrolled in any course (and not the admin): Click on Site administration ► Plugins ► Web services ► Manage tokens Now, copy the course module id of any activity or resource within any course in the site (a course the user does not have access to) Next, you can do a CURL REST call simulating a WS client with the user. You need to replace the wstoken, and the URL of your moodle instance and replacing the X (value of the contexts [0] [instanceid] parameter) with the course module id you copied curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'contexts [0] [contextlevel] =module&contexts [0] [instanceid] =X&wsfunction=core_filters_get_available_in_context&wstoken=12a2a65aeea2a177055e233f9e303218' | python -m "json.tool" Confirm that after executing the request: You get a warning structure including a warning with "item" set to "context"
    • Affected Branches:
      MOODLE_38_STABLE
    • Fixed Branches:
      MOODLE_36_STABLE, MOODLE_37_STABLE
    • Pull from Repository:
    • Pull 3.6 Branch:
    • Pull 3.7 Branch:
    • Pull Master Branch:
      MDL-66876-master

      Description

      In this line, the context is treated as an array, but it's an object. This triggers an exception: Cannot use object of type context_module as array.

      To reproduce it:

      1. Create an activity that isn't visible for students. Copy the id of the activity.
      2. Create a token for a student user in that course.
      3. Call the WS core_filters_get_available_in_context and pass a context with contextlevel=module and the instanceid equal to the id you copied in step 1.

        Attachments

          Activity

            People

            • Assignee:
              jleyva Juan Leyva
              Reporter:
              dpalou Dani Palou
              Peer reviewer:
              Dani Palou
              Integrator:
              Adrian Greeve
              Tester:
              Janelle Barcega
              Participants:
              Component watchers:
              Jake Dallimore, Jun Pataleta, Juan Leyva, Jake Dallimore, Jun Pataleta
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                11/Nov/19

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 55 minutes
                1h 55m