diff --git a/apps/dav/lib/Service/ExampleContactService.php b/apps/dav/lib/Service/ExampleContactService.php index 6ed6c66cbb3..a5e6d55a1ac 100644 --- a/apps/dav/lib/Service/ExampleContactService.php +++ b/apps/dav/lib/Service/ExampleContactService.php @@ -52,12 +52,27 @@ class ExampleContactService { return $folder->getFile('defaultContact.vcf')->getContent(); } - public function setCard(?string $cardData = null) { + private function createInitialDefaultContact(): void { + if ($this->defaultContactExists()) { + return; + } try { - $folder = $this->appData->getFolder('defaultContact'); - } catch (NotFoundException $e) { $folder = $this->appData->newFolder('defaultContact'); + $cardData = file_get_contents(__DIR__ . '/../ExampleContentFiles/exampleContact.vcf'); + if (!$cardData) { + throw new \Exception('Could not read exampleContact.vcf'); + } + $file = (!$folder->fileExists('defaultContact.vcf')) ? $folder->newFile('defaultContact.vcf') : $folder->getFile('defaultContact.vcf'); + $file->putContent($cardData); + $this->appConfig->setAppValueBool('hasCustomDefaultContact', false); + + } catch (\Exception $e) { + $this->logger->error('Could not create initial default contact', ['exception' => $e]); } + } + + public function setCard(?string $cardData = null) { + $folder = $this->appData->getFolder('defaultContact'); $isCustom = true; if (is_null($cardData)) { @@ -69,7 +84,7 @@ class ExampleContactService { throw new \Exception('Could not read exampleContact.vcf'); } - $file = (!$folder->fileExists('defaultContact.vcf')) ? $folder->newFile('defaultContact.vcf') : $folder->getFile('defaultContact.vcf'); + $file = $folder->getFile('defaultContact.vcf'); $file->putContent($cardData); $this->appConfig->setAppValueBool('hasCustomDefaultContact', $isCustom); @@ -89,6 +104,10 @@ class ExampleContactService { return; } + if (!$this->defaultContactExists()) { + $this->createInitialDefaultContact(); + } + try { $folder = $this->appData->getFolder('defaultContact'); $defaultContactFile = $folder->getFile('defaultContact.vcf'); diff --git a/build/integration/collaboration_features/autocomplete.feature b/build/integration/collaboration_features/autocomplete.feature index 7efc646f08d..5044758a70f 100644 --- a/build/integration/collaboration_features/autocomplete.feature +++ b/build/integration/collaboration_features/autocomplete.feature @@ -50,6 +50,7 @@ Feature: autocomplete Then get email autocomplete for "example" | id | source | | autocomplete | users | + | leon@example.com | emails | | user@example.com | emails | Then get email autocomplete for "auto" | id | source | @@ -57,6 +58,7 @@ Feature: autocomplete Then get email autocomplete for "example" | id | source | | autocomplete | users | + | leon@example.com | emails | | user@example.com | emails | Then get email autocomplete for "autocomplete@example.com" | id | source | @@ -72,12 +74,14 @@ Feature: autocomplete When parameter "shareapi_restrict_user_enumeration_full_match" of app "core" is set to "no" Then get email autocomplete for "example" | id | source | + | leon@example.com | emails | | user@example.com | emails | When parameter "shareapi_restrict_user_enumeration_full_match" of app "core" is set to "yes" Then get email autocomplete for "auto" | id | source | Then get email autocomplete for "example" | id | source | + | leon@example.com | emails | | user@example.com | emails | Then get email autocomplete for "autocomplete@example.com" | id | source |