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

Web services: override_webservice_execution callback not always honoured

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.8.4, 3.8.5
    • Fix Version/s: 3.8.6, 3.9.3
    • Component/s: Web Services
    • Labels:
    • Testing Instructions:
      Hide
      1. Download sabotage-add-activity-no-versions.patch and apply it to your Moodle instance.

        git apply /path/to/sabotage-add-activity-no-versions.patch
        

        This updates html block and forum to add webservice overrides.

      2. Purge caches (e.g. via mdk purge)
      3. Go to any course page and turn editing on.
      4. Click the 'Add an activity or resource' button
      5. Confirm that the dialogue comes up with NO activity options to add (it has been successfully sabotaged)
      For 38
      1. As a student enrolled in a course C1, access C1's course page
      2. Go to the Dashboard and check the "Recently accessed courses" block. You should see C1 on there.
      3. Replace "mod_forum_override_webservice_execution()"'s content in "mod/forum/lib.php" with the following code:

         // Check if it's the function we want to override.
            if ($function->name !== 'core_course_get_recent_courses') {
                return false;
            }
            return [];
        

        (This is the code being added by sabotage-add-activity-no-versions.patch . We're just updating it to adapt for 38 since the WS function core_course_get_course_content_items has only been introduced in 39.)

      4. Refresh the dashboard.
      5. Confirm that the recently accessed courses block is now empty.

      Note: At the end of the test, make sure to reset your instance to undo the changes from sabotage-add-activity-no-versions.patch. e.g.

      git reset --hard origin/[BRANCH_NAME]
      

      Show
      Download sabotage-add-activity-no-versions.patch and apply it to your Moodle instance. git apply /path/to/sabotage-add-activity-no-versions.patch This updates html block and forum to add webservice overrides. Purge caches (e.g. via mdk purge ) Go to any course page and turn editing on. Click the 'Add an activity or resource' button Confirm that the dialogue comes up with NO activity options to add (it has been successfully sabotaged) For 38 As a student enrolled in a course C1, access C1's course page Go to the Dashboard and check the " Recently accessed courses " block. You should see C1 on there. Replace " mod_forum_override_webservice_execution() "'s content in " mod/forum/lib.php " with the following code: // Check if it's the function we want to override. if ($function->name !== 'core_course_get_recent_courses') { return false; } return []; (This is the code being added by sabotage-add-activity-no-versions.patch . We're just updating it to adapt for 38 since the WS function core_course_get_course_content_items has only been introduced in 39.) Refresh the dashboard. Confirm that the recently accessed courses block is now empty. Note: At the end of the test, make sure to reset your instance to undo the changes from sabotage-add-activity-no-versions.patch . e.g. git reset --hard origin/[BRANCH_NAME]
    • Affected Branches:
      MOODLE_38_STABLE
    • Fixed Branches:
      MOODLE_38_STABLE, MOODLE_39_STABLE
    • Pull 3.8 Branch:
      MDL-69663-m38
    • Pull 3.9 Branch:
      MDL-69663-m39
    • Pull 3.10 Branch:
      MDL-69663-m310
    • Pull Master Branch:
      MDL-69663-master

      Description

      The override_webservice_execution callback is broken if there are multiple implementors in different types of plugin.

      Specifically the problem is this code:

                  foreach ($callbacks as $plugintype => $plugins) {
                      foreach ($plugins as $plugin => $callback) {
                          $result = $callback($externalfunctioninfo, $params);
                          if ($result !== false) {
                              break;
                          }
                      }
                  }
      

      Note that the 'break' line only breaks out of the inner loop.

      An example scenario is:

      • A theme implements a callback function, checks the function name is core_xxx, if so does something, if not returns false
      • A local plugin implements a callback function, checks the function name is core_yyy, if so does something, if not returns false
      • Webservice call occurs with function core_xxx. The theme callback returns a modified result, but the code then goes on to call the local plugin which returns false, and therefore the 'original' standard function call is used.

        Attachments

          Activity

            People

            Assignee:
            quen Sam Marshall
            Reporter:
            quen Sam Marshall
            Peer reviewer:
            Tim Hunt
            Integrator:
            Jun Pataleta
            Tester:
            Janelle Barcega
            Participants:
            Component watchers:
            Juan Leyva, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              9/Nov/20

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 hours
                3h