Merge pull request #1698 from nextcloud/backport-1558-remove-notifications-upon-user-deletion-9
[stable9] Remove notifications upon user deletion
This commit is contained in:
commit
f82ef09150
|
@ -212,11 +212,15 @@ class User implements IUser {
|
|||
|
||||
\OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid);
|
||||
\OC::$server->getCommentsManager()->deleteReadMarksFromUser($this);
|
||||
}
|
||||
|
||||
$notification = \OC::$server->getNotificationManager()->createNotification();
|
||||
$notification->setUser($this->uid);
|
||||
\OC::$server->getNotificationManager()->markProcessed($notification);
|
||||
|
||||
if ($this->emitter) {
|
||||
$this->emitter->emit('\OC\User', 'postDelete', array($this));
|
||||
}
|
||||
}
|
||||
return !($result === false);
|
||||
}
|
||||
|
||||
|
|
|
@ -435,7 +435,19 @@ class User extends \Test\TestCase {
|
|||
$this->assertEquals(2, $hooksCalled);
|
||||
}
|
||||
|
||||
public function testDeleteHooks() {
|
||||
public function dataDeleteHooks() {
|
||||
return [
|
||||
[true, 2],
|
||||
[false, 1],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataDeleteHooks
|
||||
* @param bool $result
|
||||
* @param int $expectedHooks
|
||||
*/
|
||||
public function testDeleteHooks($result, $expectedHooks) {
|
||||
$hooksCalled = 0;
|
||||
$test = $this;
|
||||
|
||||
|
@ -444,7 +456,10 @@ class User extends \Test\TestCase {
|
|||
*/
|
||||
$backend = $this->getMock('\Test\Util\User\Dummy');
|
||||
$backend->expects($this->once())
|
||||
->method('deleteUser');
|
||||
->method('deleteUser')
|
||||
->willReturn($result);
|
||||
$emitter = new PublicEmitter();
|
||||
$user = new \OC\User\User('foo', $backend, $emitter);
|
||||
|
||||
/**
|
||||
* @param \OC\User\User $user
|
||||
|
@ -454,13 +469,62 @@ class User extends \Test\TestCase {
|
|||
$test->assertEquals('foo', $user->getUID());
|
||||
};
|
||||
|
||||
$emitter = new PublicEmitter();
|
||||
$emitter->listen('\OC\User', 'preDelete', $hook);
|
||||
$emitter->listen('\OC\User', 'postDelete', $hook);
|
||||
|
||||
$user = new \OC\User\User('foo', $backend, $emitter);
|
||||
$this->assertTrue($user->delete());
|
||||
$this->assertEquals(2, $hooksCalled);
|
||||
$config = $this->getMockBuilder('OCP\IConfig')->getMock();
|
||||
$commentsManager = $this->getMockBuilder('OCP\Comments\ICommentsManager')->getMock();
|
||||
$notificationManager = $this->getMockBuilder('OCP\Notification\IManager')->getMock();
|
||||
|
||||
if ($result) {
|
||||
$config->expects($this->once())
|
||||
->method('deleteAllUserValues')
|
||||
->with('foo');
|
||||
|
||||
$commentsManager->expects($this->once())
|
||||
->method('deleteReferencesOfActor')
|
||||
->with('users', 'foo');
|
||||
$commentsManager->expects($this->once())
|
||||
->method('deleteReadMarksFromUser')
|
||||
->with($user);
|
||||
|
||||
$notification = $this->getMockBuilder('OCP\Notification\INotification')->getMock();
|
||||
$notification->expects($this->once())
|
||||
->method('setUser')
|
||||
->with('foo');
|
||||
|
||||
$notificationManager->expects($this->once())
|
||||
->method('createNotification')
|
||||
->willReturn($notification);
|
||||
$notificationManager->expects($this->once())
|
||||
->method('markProcessed')
|
||||
->with($notification);
|
||||
} else {
|
||||
$config->expects($this->never())
|
||||
->method('deleteAllUserValues');
|
||||
|
||||
$commentsManager->expects($this->never())
|
||||
->method('deleteReferencesOfActor');
|
||||
$commentsManager->expects($this->never())
|
||||
->method('deleteReadMarksFromUser');
|
||||
|
||||
$notificationManager->expects($this->never())
|
||||
->method('createNotification');
|
||||
$notificationManager->expects($this->never())
|
||||
->method('markProcessed');
|
||||
}
|
||||
|
||||
$this->overwriteService('NotificationManager', $notificationManager);
|
||||
$this->overwriteService('CommentsManager', $commentsManager);
|
||||
$this->overwriteService('AllConfig', $config);
|
||||
|
||||
$this->assertSame($result, $user->delete());
|
||||
|
||||
$this->restoreService('AllConfig');
|
||||
$this->restoreService('CommentsManager');
|
||||
$this->restoreService('NotificationManager');
|
||||
|
||||
$this->assertEquals($expectedHooks, $hooksCalled);
|
||||
}
|
||||
|
||||
public function testGetCloudId() {
|
||||
|
|
Loading…
Reference in New Issue