aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Wurst <ChristophWurst@users.noreply.github.com>2021-08-31 08:59:50 +0200
committerGitHub <noreply@github.com>2021-08-31 08:59:50 +0200
commit613798a54b93ef912493be6f5e207a9ef35ba0ad (patch)
tree3dd5cc0532c0e6bbf93d96e1c9b5504e8957560f
parent506b411dfc43229633ce0a4680334ed7ef6e5e5d (diff)
parent57e2f2a903cad170eb9533b7dccdf4afaa93dd2f (diff)
downloadnextcloud-server-613798a54b93ef912493be6f5e207a9ef35ba0ad.tar.gz
nextcloud-server-613798a54b93ef912493be6f5e207a9ef35ba0ad.zip
Merge pull request #28419 from nextcloud/bug/28419/delete-calendar-subscriptions-when-deleting-user
Delete calendar subscriptions as well when deleting user
-rw-r--r--apps/dav/lib/HookManager.php15
-rw-r--r--apps/dav/tests/unit/DAV/HookManagerTest.php49
2 files changed, 40 insertions, 24 deletions
diff --git a/apps/dav/lib/HookManager.php b/apps/dav/lib/HookManager.php
index 03e7551e971..1287104fd10 100644
--- a/apps/dav/lib/HookManager.php
+++ b/apps/dav/lib/HookManager.php
@@ -58,6 +58,9 @@ class HookManager {
private $calendarsToDelete = [];
/** @var array */
+ private $subscriptionsToDelete = [];
+
+ /** @var array */
private $addressBooksToDelete = [];
/** @var Defaults */
@@ -116,9 +119,11 @@ class HookManager {
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) {
@@ -137,6 +142,12 @@ class HookManager {
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) {
diff --git a/apps/dav/tests/unit/DAV/HookManagerTest.php b/apps/dav/tests/unit/DAV/HookManagerTest.php
index d3cdfbf68f7..503062c75db 100644
--- a/apps/dav/tests/unit/DAV/HookManagerTest.php
+++ b/apps/dav/tests/unit/DAV/HookManagerTest.php
@@ -38,6 +38,7 @@ use OCP\Defaults;
use OCP\IL10N;
use OCP\IUser;
use OCP\IUserManager;
+use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
@@ -45,7 +46,7 @@ class HookManagerTest extends TestCase {
/** @var IL10N */
private $l10n;
- /** @var EventDispatcherInterface | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var EventDispatcherInterface | MockObject */
private $eventDispatcher;
protected function setUp(): void {
@@ -66,24 +67,24 @@ class HookManagerTest extends TestCase {
->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();
@@ -96,7 +97,7 @@ class HookManagerTest extends TestCase {
'components' => 'VEVENT'
]);
- /** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $card */
+ /** @var CardDavBackend | MockObject $card */
$card = $this->getMockBuilder(CardDavBackend::class)
->disableOriginalConstructor()
->getMock();
@@ -115,29 +116,29 @@ class HookManagerTest extends TestCase {
->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();
@@ -154,23 +155,23 @@ class HookManagerTest extends TestCase {
->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();
@@ -183,7 +184,7 @@ class HookManagerTest extends TestCase {
'components' => 'VEVENT'
]);
- /** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $card */
+ /** @var CardDavBackend | MockObject $card */
$card = $this->getMockBuilder(CardDavBackend::class)
->disableOriginalConstructor()
->getMock();
@@ -201,35 +202,39 @@ class HookManagerTest extends TestCase {
->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();