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

    • MOODLE_38_STABLE
    • MOODLE_36_STABLE, MOODLE_37_STABLE
    • MDL-66876-master
    • 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"

      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.

            jleyva Juan Leyva
            dpalou Dani Palou
            Dani Palou Dani Palou
            Adrian Greeve Adrian Greeve
            Janelle Barcega Janelle Barcega
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

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

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