mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
fix: make sure default contact exists by default
Signed-off-by: Hamza <hamzamahjoubi221@gmail.com> Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
This commit is contained in:
parent
a0de176ecb
commit
a3fbc67648
2 changed files with 29 additions and 6 deletions
|
|
@ -52,12 +52,27 @@ class ExampleContactService {
|
|||
return $folder->getFile('defaultContact.vcf')->getContent();
|
||||
}
|
||||
|
||||
public function setCard(?string $cardData = null) {
|
||||
try {
|
||||
$folder = $this->appData->getFolder('defaultContact');
|
||||
} catch (NotFoundException $e) {
|
||||
$folder = $this->appData->newFolder('defaultContact');
|
||||
private function createInitialDefaultContact(): void {
|
||||
if ($this->defaultContactExists()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
$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…
Reference in a new issue