fix: make sure default contact exists by default

Signed-off-by: Hamza <hamzamahjoubi221@gmail.com>
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
pull/53919/head
Hamza 3 months ago committed by Richard Steinmetz
parent d854252e70
commit fa1dd4a717
No known key found for this signature in database
GPG Key ID: 27137D9E7D273FB2
  1. 27
      apps/dav/lib/Service/ExampleContactService.php
  2. 4
      build/integration/collaboration_features/autocomplete.feature

@ -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');

@ -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 |

Loading…
Cancel
Save