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

[stable20] Delete calendar subscriptions as well when deleting user #28654

Closed
wants to merge 1 commit into from
Closed
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 @@ -58,6 +58,9 @@ class HookManager {
/** @var array */
private $calendarsToDelete = [];

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

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

Expand Down Expand Up @@ -112,9 +115,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 @@ -130,6 +135,12 @@ public function postDeleteUser($params) {
foreach ($this->calendarsToDelete as $calendar) {
$this->calDav->deleteCalendar($calendar['id']);
}

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

foreach ($this->addressBooksToDelete as $addressBook) {
Expand Down
33 changes: 19 additions & 14 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 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as on stable22 and stable 21, there are a few more cases here where \PHPUnit\Framework\MockObject\ should be removed. I guess some reorder in master is the reason why the backport was incomplete as some of these cases were not backported. Everything else is fine.

private $eventDispatcher;

protected function setUp(): void {
Expand All @@ -66,12 +67,12 @@ 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();
Expand All @@ -85,7 +86,7 @@ public function test() {
'principals/users/newUser',
'personal', ['{DAV:}displayname' => 'Personal']);

/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $card */
/** @var CardDavBackend | MockObject $card */
$card = $this->getMockBuilder(CardDavBackend::class)
->disableOriginalConstructor()
->getMock();
Expand All @@ -104,12 +105,12 @@ 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();
Expand All @@ -121,7 +122,7 @@ public function testWithExisting() {
$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 @@ -138,12 +139,12 @@ 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();
Expand All @@ -157,7 +158,7 @@ public function testWithBirthdayCalendar() {
'principals/users/newUser',
'personal', ['{DAV:}displayname' => 'Personal']);

/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $card */
/** @var CardDavBackend | MockObject $card */
$card = $this->getMockBuilder(CardDavBackend::class)
->disableOriginalConstructor()
->getMock();
Expand All @@ -175,13 +176,13 @@ 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();
Expand All @@ -195,10 +196,14 @@ public function testDeleteCalendar() {
$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