From 2528e702f218f9a500d531068037cd65401cfb84 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Fri, 28 Feb 2025 17:17:15 +0100 Subject: [PATCH] fix(dav): Create SAB at installation Signed-off-by: Christoph Wurst --- apps/dav/appinfo/info.xml | 3 ++ .../composer/composer/autoload_classmap.php | 1 + .../dav/composer/composer/autoload_static.php | 1 + apps/dav/lib/CardDAV/SyncService.php | 11 +++-- .../Migration/CreateSystemAddressBookStep.php | 30 ++++++++++++ .../CreateSystemAddressBookStepTest.php | 47 +++++++++++++++++++ 6 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 apps/dav/lib/Migration/CreateSystemAddressBookStep.php create mode 100644 apps/dav/tests/unit/Migration/CreateSystemAddressBookStepTest.php diff --git a/apps/dav/appinfo/info.xml b/apps/dav/appinfo/info.xml index a438a4dd06346..6abc8ac9d80d1 100644 --- a/apps/dav/appinfo/info.xml +++ b/apps/dav/appinfo/info.xml @@ -49,6 +49,9 @@ OCA\DAV\Migration\ChunkCleanup + + OCA\DAV\Migration\CreateSystemAddressBookStep + diff --git a/apps/dav/composer/composer/autoload_classmap.php b/apps/dav/composer/composer/autoload_classmap.php index 09eb4ba17bd84..19db47d7cab6e 100644 --- a/apps/dav/composer/composer/autoload_classmap.php +++ b/apps/dav/composer/composer/autoload_classmap.php @@ -306,6 +306,7 @@ 'OCA\\DAV\\Migration\\BuildSocialSearchIndexBackgroundJob' => $baseDir . '/../lib/Migration/BuildSocialSearchIndexBackgroundJob.php', 'OCA\\DAV\\Migration\\CalDAVRemoveEmptyValue' => $baseDir . '/../lib/Migration/CalDAVRemoveEmptyValue.php', 'OCA\\DAV\\Migration\\ChunkCleanup' => $baseDir . '/../lib/Migration/ChunkCleanup.php', + 'OCA\\DAV\\Migration\\CreateSystemAddressBookStep' => $baseDir . '/../lib/Migration/CreateSystemAddressBookStep.php', 'OCA\\DAV\\Migration\\DeleteSchedulingObjects' => $baseDir . '/../lib/Migration/DeleteSchedulingObjects.php', 'OCA\\DAV\\Migration\\FixBirthdayCalendarComponent' => $baseDir . '/../lib/Migration/FixBirthdayCalendarComponent.php', 'OCA\\DAV\\Migration\\RefreshWebcalJobRegistrar' => $baseDir . '/../lib/Migration/RefreshWebcalJobRegistrar.php', diff --git a/apps/dav/composer/composer/autoload_static.php b/apps/dav/composer/composer/autoload_static.php index a2048fcdf0591..2965b78beb2b5 100644 --- a/apps/dav/composer/composer/autoload_static.php +++ b/apps/dav/composer/composer/autoload_static.php @@ -321,6 +321,7 @@ class ComposerStaticInitDAV 'OCA\\DAV\\Migration\\BuildSocialSearchIndexBackgroundJob' => __DIR__ . '/..' . '/../lib/Migration/BuildSocialSearchIndexBackgroundJob.php', 'OCA\\DAV\\Migration\\CalDAVRemoveEmptyValue' => __DIR__ . '/..' . '/../lib/Migration/CalDAVRemoveEmptyValue.php', 'OCA\\DAV\\Migration\\ChunkCleanup' => __DIR__ . '/..' . '/../lib/Migration/ChunkCleanup.php', + 'OCA\\DAV\\Migration\\CreateSystemAddressBookStep' => __DIR__ . '/..' . '/../lib/Migration/CreateSystemAddressBookStep.php', 'OCA\\DAV\\Migration\\DeleteSchedulingObjects' => __DIR__ . '/..' . '/../lib/Migration/DeleteSchedulingObjects.php', 'OCA\\DAV\\Migration\\FixBirthdayCalendarComponent' => __DIR__ . '/..' . '/../lib/Migration/FixBirthdayCalendarComponent.php', 'OCA\\DAV\\Migration\\RefreshWebcalJobRegistrar' => __DIR__ . '/..' . '/../lib/Migration/RefreshWebcalJobRegistrar.php', diff --git a/apps/dav/lib/CardDAV/SyncService.php b/apps/dav/lib/CardDAV/SyncService.php index cc3d324faf1ff..c31a70b2aa56d 100644 --- a/apps/dav/lib/CardDAV/SyncService.php +++ b/apps/dav/lib/CardDAV/SyncService.php @@ -119,6 +119,12 @@ public function ensureSystemAddressBookExists(string $principal, string $uri, ar } } + public function ensureLocalSystemAddressBookExists(): ?array { + return $this->ensureSystemAddressBookExists('principals/system/system', 'system', [ + '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' + ]); + } + private function prepareUri(string $host, string $path): string { /* * The trailing slash is important for merging the uris together. @@ -275,10 +281,7 @@ public function deleteUser($userOrCardId) { */ public function getLocalSystemAddressBook() { if (is_null($this->localSystemAddressBook)) { - $systemPrincipal = 'principals/system/system'; - $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' - ]); + $this->localSystemAddressBook = $this->ensureLocalSystemAddressBookExists(); } return $this->localSystemAddressBook; diff --git a/apps/dav/lib/Migration/CreateSystemAddressBookStep.php b/apps/dav/lib/Migration/CreateSystemAddressBookStep.php new file mode 100644 index 0000000000000..ec07c72e7a755 --- /dev/null +++ b/apps/dav/lib/Migration/CreateSystemAddressBookStep.php @@ -0,0 +1,30 @@ +syncService->ensureLocalSystemAddressBookExists(); + } +} diff --git a/apps/dav/tests/unit/Migration/CreateSystemAddressBookStepTest.php b/apps/dav/tests/unit/Migration/CreateSystemAddressBookStepTest.php new file mode 100644 index 0000000000000..bbecd0607b495 --- /dev/null +++ b/apps/dav/tests/unit/Migration/CreateSystemAddressBookStepTest.php @@ -0,0 +1,47 @@ +syncService = $this->createMock(SyncService::class); + + $this->step = new CreateSystemAddressBookStep( + $this->syncService, + ); + } + + public function testGetName(): void { + $name = $this->step->getName(); + + self::assertEquals('Create system address book', $name); + } + + public function testRun(): void { + $output = $this->createMock(IOutput::class); + + $this->step->run($output); + + $this->addToAssertionCount(1); + } + +}