Skip to content

Commit

Permalink
Add method to clear notification when user is deletd
Browse files Browse the repository at this point in the history
Added a method to clear notification entry of user
when the user is deleted from oC.

Signed-off-by: Sujith H <sharidasan@owncloud.com>
  • Loading branch information
sharidas committed Aug 7, 2018
1 parent d77a3fb commit b42084e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/private/Notification/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

namespace OC\Notification;

use OCP\IUser;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use OCP\Notification\IApp;
use OCP\Notification\IManager;
Expand All @@ -32,6 +33,7 @@
use OCP\Notification\Events\RegisterNotifierEvent;
use OC\Notification\Events\RegisterConsumerEventImpl;
use OC\Notification\Events\RegisterNotifierEventImpl;
use Symfony\Component\EventDispatcher\GenericEvent;

class Manager implements IManager {
/** @var EventDispatcherInterface */
Expand Down Expand Up @@ -72,6 +74,10 @@ public function __construct(EventDispatcherInterface $dispatcher) {
$this->notifiersInfoClosures = [];

$this->builtAppsHolder = [];

$this->dispatcher->addListener('user.afterdelete', function (GenericEvent $event) {
$this->removeUserNotifications($event->getArgument('uid'));
});
}

/**
Expand Down Expand Up @@ -299,4 +305,12 @@ public function getCount(INotification $notification) {

return $count;
}

public function removeUserNotifications($uid) {
$apps = $this->getApps();

foreach ($apps as $app) {
$app->removeUserNotifications($uid);
}
}
}
7 changes: 7 additions & 0 deletions lib/public/Notification/IApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,11 @@ public function markProcessed(INotification $notification);
* @since 9.0.0
*/
public function getCount(INotification $notification);

/**
* @param $uid
* @return null
* @since 10.1.0
*/
public function removeUserNotifications($uid);
}
13 changes: 13 additions & 0 deletions tests/lib/Notification/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,4 +645,17 @@ public function testGetCount() {

$this->assertSame(63, $this->manager->getCount($notification));
}

public function testRemoveUserNotifications() {
$app = $this->createMock(IApp::class);
$app->expects($this->once())
->method('removeUserNotifications')
->with('foo');

$this->manager->registerApp(function () use ($app) {
return $app;
});

$this->manager->removeUserNotifications('foo');
}
}

0 comments on commit b42084e

Please sign in to comment.