Add IUserNotificationEvent::deleteNoAccessNotification()
authorMatthias Schmidt <gravatronics@live.com>
Mon, 18 Aug 2014 17:17:29 +0000 (19:17 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Mon, 18 Aug 2014 17:17:29 +0000 (19:17 +0200)
wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php
wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php
wcfsetup/install/files/lib/system/user/notification/event/IUserNotificationEvent.class.php

index 2fafb9bc366fb0ff34c95a9858bd9405995f2ed2..7138be36a9523722e756532c5fdab0d87918b92c 100644 (file)
@@ -421,6 +421,17 @@ class UserNotificationHandler extends SingletonFactory {
                        $notifications[] = $data;
                }
                
+               // check access
+               foreach ($notifications as $index => $notificationData) {
+                       if (!$notificationData['event']->checkAccess()) {
+                               if ($notificationData['event']->deleteNoAccessNotification()) {
+                                       $deleteNotifications[] = $notificationObjects[$notificationData['notificationID']];
+                               }
+                               
+                               unset($notifications[$index]);
+                       }
+               }
+               
                if (!empty($deleteNotifications)) {
                        $notificationAction = new UserNotificationAction($deleteNotifications, 'delete');
                        $notificationAction->executeAction();
@@ -429,13 +440,6 @@ class UserNotificationHandler extends SingletonFactory {
                        UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'userNotificationCount');
                }
                
-               // check access
-               foreach ($notifications as $index => $notificationData) {
-                       if (!$notificationData['event']->checkAccess()) {
-                               unset($notifications[$index]);
-                       }
-               }
-               
                return array(
                        'count' => count($notifications),
                        'notifications' => $notifications
index 46ae4eae46af3df1a94443741124275496a671b8..fa010cb461ab171a01e495c03c1557a6319b91a4 100644 (file)
@@ -232,4 +232,11 @@ abstract class AbstractUserNotificationEvent extends DatabaseObjectDecorator imp
        public function checkAccess() {
                return true;
        }
+       
+       /**
+        * @see \wcf\system\user\notification\event\IUserNotificationEvent::deleteNoAccessNotification()
+        */
+       public function deleteNoAccessNotification() {
+               return true;
+       }
 }
index a52420d79adede9cc5f291d476e20e8ddae4c757..4426d07cc91979fc6bf8824a93360fe8be1f8f1d 100644 (file)
@@ -133,4 +133,12 @@ interface IUserNotificationEvent extends IDatabaseObjectProcessor {
         * @return      boolean
         */
        public function checkAccess();
+       
+       /**
+        * Returns true if a notification should be deleted if the related object
+        * is not accessible.
+        * 
+        * @return      boolean
+        */
+       public function deleteNoAccessNotification();
 }