Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete calendar subscriptions as well when deleting user #28419

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions apps/dav/lib/HookManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class HookManager {
/** @var array */
private $calendarsToDelete = [];

/** @var array */
private $subscriptionsToDelete = [];

/** @var array */
private $addressBooksToDelete = [];

Expand Down Expand Up @@ -116,9 +119,11 @@ public function postCreateUser($params) {

public function preDeleteUser($params) {
$uid = $params['uid'];
$userPrincipalUri = 'principals/users/' . $uid;
$this->usersToDelete[$uid] = $this->userManager->get($uid);
$this->calendarsToDelete = $this->calDav->getUsersOwnCalendars('principals/users/' . $uid);
$this->addressBooksToDelete = $this->cardDav->getUsersOwnAddressBooks('principals/users/' . $uid);
$this->calendarsToDelete = $this->calDav->getUsersOwnCalendars($userPrincipalUri);
$this->subscriptionsToDelete = $this->calDav->getSubscriptionsForUser($userPrincipalUri);
$this->addressBooksToDelete = $this->cardDav->getUsersOwnAddressBooks($userPrincipalUri);
}

public function preUnassignedUserId($uid) {
Expand All @@ -137,6 +142,12 @@ public function postDeleteUser($params) {
true // Make sure the data doesn't go into the trashbin, a new user with the same UID would later see it otherwise
);
}

foreach ($this->subscriptionsToDelete as $subscription) {
$this->calDav->deleteSubscription(
$subscription['id'],
);
}
$this->calDav->deleteAllSharesByUser('principals/users/' . $uid);

foreach ($this->addressBooksToDelete as $addressBook) {
Expand Down
49 changes: 27 additions & 22 deletions apps/dav/tests/unit/DAV/HookManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@
use OCP\IL10N;
use OCP\IUser;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;

class HookManagerTest extends TestCase {
/** @var IL10N */
private $l10n;

/** @var EventDispatcherInterface | \PHPUnit\Framework\MockObject\MockObject */
/** @var EventDispatcherInterface | MockObject */
private $eventDispatcher;

protected function setUp(): void {
Expand All @@ -66,24 +67,24 @@ public function test() {
->getMock();
$user->expects($this->once())->method('getUID')->willReturn('newUser');

/** @var IUserManager | \PHPUnit\Framework\MockObject\MockObject $userManager */
/** @var IUserManager | MockObject $userManager */
$userManager = $this->getMockBuilder(IUserManager::class)
->disableOriginalConstructor()
->getMock();

/** @var SyncService | \PHPUnit\Framework\MockObject\MockObject $syncService */
/** @var SyncService | MockObject $syncService */
$syncService = $this->getMockBuilder(SyncService::class)
->disableOriginalConstructor()
->getMock();

/** @var Defaults | \PHPUnit\Framework\MockObject\MockObject $syncService */
/** @var Defaults | MockObject $syncService */
$defaults = $this->getMockBuilder(Defaults::class)
->disableOriginalConstructor()
->getMock();

$defaults->expects($this->once())->method('getColorPrimary')->willReturn('#745bca');

/** @var CalDavBackend | \PHPUnit\Framework\MockObject\MockObject $cal */
/** @var CalDavBackend | MockObject $cal */
$cal = $this->getMockBuilder(CalDavBackend::class)
->disableOriginalConstructor()
->getMock();
Expand All @@ -96,7 +97,7 @@ public function test() {
'components' => 'VEVENT'
]);

/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $card */
/** @var CardDavBackend | MockObject $card */
$card = $this->getMockBuilder(CardDavBackend::class)
->disableOriginalConstructor()
->getMock();
Expand All @@ -115,29 +116,29 @@ public function testWithExisting() {
->getMock();
$user->expects($this->once())->method('getUID')->willReturn('newUser');

/** @var IUserManager | \PHPUnit\Framework\MockObject\MockObject $userManager */
/** @var IUserManager | MockObject $userManager */
$userManager = $this->getMockBuilder(IUserManager::class)
->disableOriginalConstructor()
->getMock();

/** @var SyncService | \PHPUnit\Framework\MockObject\MockObject $syncService */
/** @var SyncService | MockObject $syncService */
$syncService = $this->getMockBuilder(SyncService::class)
->disableOriginalConstructor()
->getMock();

/** @var Defaults | \PHPUnit\Framework\MockObject\MockObject $syncService */
/** @var Defaults | MockObject $syncService */
$defaults = $this->getMockBuilder(Defaults::class)
->disableOriginalConstructor()
->getMock();

/** @var CalDavBackend | \PHPUnit\Framework\MockObject\MockObject $cal */
/** @var CalDavBackend | MockObject $cal */
$cal = $this->getMockBuilder(CalDavBackend::class)
->disableOriginalConstructor()
->getMock();
$cal->expects($this->once())->method('getCalendarsForUserCount')->willReturn(1);
$cal->expects($this->never())->method('createCalendar');

/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $card */
/** @var CardDavBackend | MockObject $card */
$card = $this->getMockBuilder(CardDavBackend::class)
->disableOriginalConstructor()
->getMock();
Expand All @@ -154,23 +155,23 @@ public function testWithBirthdayCalendar() {
->getMock();
$user->expects($this->once())->method('getUID')->willReturn('newUser');

/** @var IUserManager | \PHPUnit\Framework\MockObject\MockObject $userManager */
/** @var IUserManager | MockObject $userManager */
$userManager = $this->getMockBuilder(IUserManager::class)
->disableOriginalConstructor()
->getMock();

/** @var SyncService | \PHPUnit\Framework\MockObject\MockObject $syncService */
/** @var SyncService | MockObject $syncService */
$syncService = $this->getMockBuilder(SyncService::class)
->disableOriginalConstructor()
->getMock();

/** @var Defaults | \PHPUnit\Framework\MockObject\MockObject $syncService */
/** @var Defaults | MockObject $syncService */
$defaults = $this->getMockBuilder(Defaults::class)
->disableOriginalConstructor()
->getMock();
$defaults->expects($this->once())->method('getColorPrimary')->willReturn('#745bca');

/** @var CalDavBackend | \PHPUnit\Framework\MockObject\MockObject $cal */
/** @var CalDavBackend | MockObject $cal */
$cal = $this->getMockBuilder(CalDavBackend::class)
->disableOriginalConstructor()
->getMock();
Expand All @@ -183,7 +184,7 @@ public function testWithBirthdayCalendar() {
'components' => 'VEVENT'
]);

/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $card */
/** @var CardDavBackend | MockObject $card */
$card = $this->getMockBuilder(CardDavBackend::class)
->disableOriginalConstructor()
->getMock();
Expand All @@ -201,35 +202,39 @@ public function testDeleteCalendar() {
->disableOriginalConstructor()
->getMock();

/** @var IUserManager | \PHPUnit\Framework\MockObject\MockObject $userManager */
/** @var IUserManager | MockObject $userManager */
$userManager = $this->getMockBuilder(IUserManager::class)
->disableOriginalConstructor()
->getMock();
$userManager->expects($this->once())->method('get')->willReturn($user);

/** @var SyncService | \PHPUnit\Framework\MockObject\MockObject $syncService */
/** @var SyncService | MockObject $syncService */
$syncService = $this->getMockBuilder(SyncService::class)
->disableOriginalConstructor()
->getMock();
$syncService->expects($this->once())
->method('deleteUser');

/** @var Defaults | \PHPUnit\Framework\MockObject\MockObject $syncService */
/** @var Defaults | MockObject $syncService */
$defaults = $this->getMockBuilder(Defaults::class)
->disableOriginalConstructor()
->getMock();

/** @var CalDavBackend | \PHPUnit\Framework\MockObject\MockObject $cal */
/** @var CalDavBackend | MockObject $cal */
$cal = $this->getMockBuilder(CalDavBackend::class)
->disableOriginalConstructor()
->getMock();
$cal->expects($this->once())->method('getUsersOwnCalendars')->willReturn([
['id' => 'personal']
]);
$cal->expects($this->once())->method('deleteCalendar');
$cal->expects($this->once())->method('getSubscriptionsForUser')->willReturn([
['id' => 'some-subscription']
]);
$cal->expects($this->once())->method('deleteCalendar')->with('personal');
$cal->expects($this->once())->method('deleteSubscription')->with('some-subscription');
$cal->expects($this->once())->method('deleteAllSharesByUser');

/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $card */
/** @var CardDavBackend | MockObject $card */
$card = $this->getMockBuilder(CardDavBackend::class)
->disableOriginalConstructor()
->getMock();
Expand Down