Skip to content

Commit fa1dd4a

Browse files
hamza221st3iny
authored andcommitted
fix: make sure default contact exists by default
Signed-off-by: Hamza <[email protected]> Signed-off-by: Richard Steinmetz <[email protected]>
1 parent d854252 commit fa1dd4a

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

apps/dav/lib/Service/ExampleContactService.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,27 @@ public function getCard(): ?string {
5252
return $folder->getFile('defaultContact.vcf')->getContent();
5353
}
5454

55-
public function setCard(?string $cardData = null) {
55+
private function createInitialDefaultContact(): void {
56+
if ($this->defaultContactExists()) {
57+
return;
58+
}
5659
try {
57-
$folder = $this->appData->getFolder('defaultContact');
58-
} catch (NotFoundException $e) {
5960
$folder = $this->appData->newFolder('defaultContact');
61+
$cardData = file_get_contents(__DIR__ . '/../ExampleContentFiles/exampleContact.vcf');
62+
if (!$cardData) {
63+
throw new \Exception('Could not read exampleContact.vcf');
64+
}
65+
$file = (!$folder->fileExists('defaultContact.vcf')) ? $folder->newFile('defaultContact.vcf') : $folder->getFile('defaultContact.vcf');
66+
$file->putContent($cardData);
67+
$this->appConfig->setAppValueBool('hasCustomDefaultContact', false);
68+
69+
} catch (\Exception $e) {
70+
$this->logger->error('Could not create initial default contact', ['exception' => $e]);
6071
}
72+
}
73+
74+
public function setCard(?string $cardData = null) {
75+
$folder = $this->appData->getFolder('defaultContact');
6176

6277
$isCustom = true;
6378
if (is_null($cardData)) {
@@ -69,7 +84,7 @@ public function setCard(?string $cardData = null) {
6984
throw new \Exception('Could not read exampleContact.vcf');
7085
}
7186

72-
$file = (!$folder->fileExists('defaultContact.vcf')) ? $folder->newFile('defaultContact.vcf') : $folder->getFile('defaultContact.vcf');
87+
$file = $folder->getFile('defaultContact.vcf');
7388
$file->putContent($cardData);
7489

7590
$this->appConfig->setAppValueBool('hasCustomDefaultContact', $isCustom);
@@ -89,6 +104,10 @@ public function createDefaultContact(int $addressBookId): void {
89104
return;
90105
}
91106

107+
if (!$this->defaultContactExists()) {
108+
$this->createInitialDefaultContact();
109+
}
110+
92111
try {
93112
$folder = $this->appData->getFolder('defaultContact');
94113
$defaultContactFile = $folder->getFile('defaultContact.vcf');

build/integration/collaboration_features/autocomplete.feature

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ Feature: autocomplete
5050
Then get email autocomplete for "example"
5151
| id | source |
5252
| autocomplete | users |
53+
| leon@example.com | emails |
5354
| user@example.com | emails |
5455
Then get email autocomplete for "auto"
5556
| id | source |
5657
| autocomplete | users |
5758
Then get email autocomplete for "example"
5859
| id | source |
5960
| autocomplete | users |
61+
| leon@example.com | emails |
6062
| user@example.com | emails |
6163
Then get email autocomplete for "[email protected]"
6264
| id | source |
@@ -72,12 +74,14 @@ Feature: autocomplete
7274
When parameter "shareapi_restrict_user_enumeration_full_match" of app "core" is set to "no"
7375
Then get email autocomplete for "example"
7476
| id | source |
77+
| leon@example.com | emails |
7578
| user@example.com | emails |
7679
When parameter "shareapi_restrict_user_enumeration_full_match" of app "core" is set to "yes"
7780
Then get email autocomplete for "auto"
7881
| id | source |
7982
Then get email autocomplete for "example"
8083
| id | source |
84+
| leon@example.com | emails |
8185
| user@example.com | emails |
8286
Then get email autocomplete for "[email protected]"
8387
| id | source |

0 commit comments

Comments
 (0)