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

Changing the wwwroot in any way breaks notification delivery

XMLWordPrintable

    • MOODLE_402_STABLE

      During my work on MDL-76722 I discovered that if I change the wwwroot of my site, in any way, notifications stop being delivered.

      That's because the app's sqlite database contains a list of sites (in the sites_2 table), where the SiteId is a hash of:

      $CFG->wwwroot . $username
      

      That siteid is sent as the siteid in the airnotifier plugin here: https://github.com/moodle/moodle/blob/126028c/message/output/airnotifier/message_output_airnotifier.php#L67-L68

      Unfortunately that means that if we want to support multi-homed sites (not officially supported yet, but we want to), then the md5 will change, and notifications will stop being received on the app.

      On the app side, I see the following in the adb logs (Android app):

      04-06 09:57:37.524 12438 12593 V cordova-plugin-push (PushPlugin): Extras To JSON Result: {"title":"Example","additionalData":{"fullmessage":"This is a test message send at: Thursday, 6 April 2023, 2:57 AM","processor":"moodle","date":"1680746240","site":"3b6811f4a2e2fccb0d9f4212ad67d8ce","notif":"1","sitefullname":"Example","encrypted":"1","coldstart":false,"wwwroot":"http:\/\/dobedobedoh.au.ngrok.io\/sm","foreground":true}}
      04-06 09:57:37.526 12438 12449 W System  : A resource failed to call close.
      04-06 09:57:37.542 12438 12438 I chromium: [INFO:CONSOLE(2)] "ERROR Error: Uncaught (in promise): CoreError: SiteId not found.
      04-06 09:57:37.542 12438 12438 I chromium: CoreError: SiteId not found.
      04-06 09:57:37.542 12438 12438 I chromium:     at CoreSitesProvider.<anonymous> (http://localhost/main.32ec4d783b02319f5f60.js:2:615727)
      04-06 09:57:37.542 12438 12438 I chromium:     at Generator.throw (<anonymous>)
      04-06 09:57:37.542 12438 12438 I chromium:     at rejected (http://localhost/main.32ec4d783b02319f5f60.js:2:4805140)
      04-06 09:57:37.542 12438 12438 I chromium:     at ZoneDelegate.invoke (http://localhost/polyfills.017993acac9fae00e880.js:2:30482)
      04-06 09:57:37.542 12438 12438 I chromium:     at Object.onInvoke (http://localhost/main.32ec4d783b02319f5f60.js:2:4173078)
      04-06 09:57:37.542 12438 12438 I chromium:     at ZoneDelegate.invoke (http://localhost/polyfills.017993acac9fae00e880.js:2:30422)
      04-06 09:57:37.542 12438 12438 I chromium:     at Zone.run (http://localhost/polyfills.017993acac9fae00e880.js:2:25847)
      04-06 09:57:37.542 12438 12438 I chromium:     at http://localhost/polyfills.017993acac9fae00e880.js:2:37572
      04-06 09:57:37.542 12438 12438 I chromium:     at ZoneDelegate.invokeTask (http://localhost/polyfills.017993acac9fae00e880.js:2:31116)
      04-06 09:57:37.542 12438 12438 I chromium:     at Object.onInvokeTask (http://localhost/main.32ec4d783b02319f5f60.js:2:4172957)", source: http://localhost/main.32ec4d783b02319f5f60.js (2)
      

      We really need to fix this because it:

      • prevents notifications from working without the user logging out of the app
      • it breaks in a way that is silent - there is no error message in the app, or in Moodle
      • I was unable to find any documentation around this requirement

      I would suggest that instead of an md5 of the $CFG->wwwroot . $username we instead use a shasum containing a concatentation of:

      • $CFG->siteidentifier
      • a separator character
      • the userid

      For example:

      $siteid = sha1($CFG->siteidentifier . "::" . $eventdata->userto->id);
      

      To get to that point, we probably need to introduce a new field in the app's database and on next login/token refresh event we add the new siteid. We can update the air notifeir task to send this siteid as well as the existing one, and check for both.

      Over time we can remove the legacy field.

            Unassigned Unassigned
            dobedobedoh Andrew Lyons
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:

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