MDL-68788 core_notification: Check if the user is logged in
authorMathew May <mathewm@hotmail.co.nz>
Thu, 21 May 2020 08:24:46 +0000 (16:24 +0800)
committerMathew May <mathewm@hotmail.co.nz>
Thu, 21 May 2020 08:33:25 +0000 (16:33 +0800)
lib/amd/build/notification.min.js
lib/amd/build/notification.min.js.map
lib/amd/src/notification.js
lib/outputrenderers.php

index ae72462..42cdec9 100644 (file)
Binary files a/lib/amd/build/notification.min.js and b/lib/amd/build/notification.min.js differ
index ed26296..1d721de 100644 (file)
Binary files a/lib/amd/build/notification.min.js.map and b/lib/amd/build/notification.min.js.map differ
index 0822899..62cec7e 100644 (file)
@@ -292,8 +292,9 @@ export const exception = async ex => {
  *
  * @param {Number} contextId
  * @param {Array} notificationList
+ * @param {Boolean} userLoggedIn
  */
-export const init = (contextId, notificationList) => {
+export const init = (contextId, notificationList, userLoggedIn) => {
     currentContextId = contextId;
 
     // Setup the message target region if it isn't setup already
@@ -302,8 +303,11 @@ export const init = (contextId, notificationList) => {
     // Add provided notifications.
     addNotifications(notificationList);
 
-    // Perform an initial poll for any new notifications.
-    fetchNotifications();
+    // If the user is not logged in then we can not fetch anything for them.
+    if (userLoggedIn) {
+        // Perform an initial poll for any new notifications.
+        fetchNotifications();
+    }
 };
 
 // To maintain backwards compatability we export default here.
index 2e589f5..9d5cc16 100644 (file)
@@ -1414,7 +1414,8 @@ class core_renderer extends renderer_base {
         if (!empty($this->page->context->id)) {
             $this->page->requires->js_call_amd('core/notification', 'init', array(
                 $this->page->context->id,
-                \core\notification::fetch_as_array($this)
+                \core\notification::fetch_as_array($this),
+                isloggedin()
             ));
         }
         $footer = str_replace($this->unique_end_html_token, $this->page->requires->get_end_code(), $footer);