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

Badge notifications are sent with an object as contexturl

    • MOODLE_405_STABLE
    • MDL-83080-405
    • MDL-83080-500
    • Hide

      Note

      Testing instructions don't require complete setup/registration of site as per instructions from MDL-78307 to create a site, instead we just verify the data is in the correct shape at the point we expect it to be

      Setup

      1. Ensure site is using a public URL (Ngrok)
      2. Register the site on the apps portal
      3. Generate Airnotifier access key
      4. Back on your own site enable/configure web services
      5. Use the app to connect to your public URL (in order to register your device)

      Test

      1. Apply the following diff (horrible hack):

        $ git diff
        diff --git a/message/output/airnotifier/message_output_airnotifier.php b/message/output/airnotifier/message_output_airnotifier.php
        index 5ab8915ed45..45f5ee5be95 100644
        --- a/message/output/airnotifier/message_output_airnotifier.php
        +++ b/message/output/airnotifier/message_output_airnotifier.php
        @@ -46,6 +46,9 @@ class message_output_airnotifier extends message_output {
                 global $CFG, $DB;
                 require_once($CFG->libdir . '/filelib.php');
         
        +        print_object($eventdata);
        +        die;
        +
                 if (!empty($CFG->noemailever)) {
                     // Hidden setting for development sites, set in config.php if needed.
                     debugging('$CFG->noemailever active, no airnotifier message sent.', DEBUG_MINIMAL);
        

      2. Navigate to Badges > Manage badges in site administration
      3. Create a badge
      4. Add Manual issue by role: Teacher criteria to badge
      5. Enable access to badge
      6. Award badge to yourself
      7. Examine the structure dumped to the page
      8. Confirm that the contexturl property is the string representation of a URL (& not a \core\url / moodle_url instance), e.g.:

        '<WWWROOT>/badges/badge.php?hash=<HASH>'
        

      Show
      Note Testing instructions don't require complete setup/registration of site as per instructions from MDL-78307 to create a site, instead we just verify the data is in the correct shape at the point we expect it to be Setup Ensure site is using a public URL (Ngrok) Register the site on the apps portal Generate Airnotifier access key Back on your own site enable/configure web services Use the app to connect to your public URL (in order to register your device) Test Apply the following diff (horrible hack): $ git diff diff --git a/message/output/airnotifier/message_output_airnotifier.php b/message/output/airnotifier/message_output_airnotifier.php index 5ab8915ed45..45f5ee5be95 100644 --- a/message/output/airnotifier/message_output_airnotifier.php +++ b/message/output/airnotifier/message_output_airnotifier.php @@ -46,6 +46,9 @@ class message_output_airnotifier extends message_output { global $CFG, $DB; require_once($CFG->libdir . '/filelib.php'); + print_object($eventdata); + die; + if (!empty($CFG->noemailever)) { // Hidden setting for development sites, set in config.php if needed. debugging('$CFG->noemailever active, no airnotifier message sent.', DEBUG_MINIMAL); Navigate to Badges > Manage badges in site administration Create a badge Add Manual issue by role: Teacher criteria to badge Enable access to badge Award badge to yourself Examine the structure dumped to the page Confirm that the contexturl property is the string representation of a URL (& not a \core\url / moodle_url instance), e.g.: '<WWWROOT>/badges/badge.php?hash=<HASH>'
    • Hide

      Code verified against automated checks.

      Checked MDL-83080 using repository: https://github.com/paulholden/moodle/

      More information about this report

      Built on: Wed Jun 4 13:41:41 UTC 2025

      Show
      Code verified against automated checks. Checked MDL-83080 using repository: https://github.com/paulholden/moodle/ MOODLE_405_STABLE (0 errors / 0 warnings) [branch: MDL-83080-405 | CI Job ] MOODLE_500_STABLE (0 errors / 0 warnings) [branch: MDL-83080-500 | CI Job ] main (0 errors / 0 warnings) [branch: MDL-83080 | CI Job ] More information about this report Built on: Wed Jun 4 13:41:41 UTC 2025

      Notifications sent for awarded badges contain a contexturl that is a URL object instead of a string.

      I don't know how to reproduce the bug in an easy way, since it's only affecting push notifications in the upcoming version of the app. Please look at the function badges_notify_badge_award:

      • The URL object is created here.
      • The URL object is set as contexturl of the sent notifications here and here, without converting the URL object to string.

      This is similar to bug MDL-78307.

            pholden Paul Holden
            albert.gasset@moodle.com Albert Gasset
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:

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