From 08b99420abe3d7da1cc6dacacc68ff05c73c4c42 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Mon, 18 Aug 2014 19:17:29 +0200 Subject: [PATCH] Add IUserNotificationEvent::deleteNoAccessNotification() --- .../UserNotificationHandler.class.php | 18 +++++++++++------- .../AbstractUserNotificationEvent.class.php | 7 +++++++ .../event/IUserNotificationEvent.class.php | 8 ++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php b/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php index 2fafb9bc36..7138be36a9 100644 --- a/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php @@ -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 diff --git a/wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php index 46ae4eae46..fa010cb461 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php @@ -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; + } } diff --git a/wcfsetup/install/files/lib/system/user/notification/event/IUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/IUserNotificationEvent.class.php index a52420d79a..4426d07cc9 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/IUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/IUserNotificationEvent.class.php @@ -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(); } -- 2.20.1