-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add example contact on first login
Signed-off-by: Hamza Mahjoubi <[email protected]>
- Loading branch information
Showing
133 changed files
with
4,592 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\DAV\Controller; | ||
|
||
use OCA\DAV\AppInfo\Application; | ||
use OCP\App\IAppManager; | ||
use OCP\AppFramework\ApiController; | ||
use OCP\AppFramework\Http; | ||
use OCP\AppFramework\Http\JSONResponse; | ||
use OCP\Files\AppData\IAppDataFactory; | ||
use OCP\Files\IAppData; | ||
use OCP\Files\NotFoundException; | ||
use OCP\IConfig; | ||
use OCP\IRequest; | ||
|
||
class ExampleContentController extends ApiController { | ||
|
||
/** @var IAppData */ | ||
private $appData; | ||
public function __construct( | ||
IRequest $request, | ||
private IConfig $config, | ||
private IAppDataFactory $appDataFactory, | ||
private IAppManager $appManager, | ||
) { | ||
parent::__construct(Application::APP_ID, $request); | ||
$this->appData = $this->appDataFactory->get('dav'); | ||
} | ||
|
||
public function setEnableDefaultContact($allow) { | ||
$key = 'enableDefaultContact' ; | ||
if ($allow === 'yes' && !$this->defaultContactExists()) { | ||
$this->setCard(); | ||
} | ||
$this->config->setAppValue(Application::APP_ID, $key, $allow); | ||
return new JSONResponse([], Http::STATUS_OK); | ||
} | ||
|
||
public function setDefaultContact(?string $contactData = null) { | ||
if (!$this->config->getAppValue(Application::APP_ID, 'enableDefaultContact', 'no')) { | ||
return new JSONResponse([], Http::STATUS_FORBIDDEN); | ||
} | ||
$this->setCard($contactData); | ||
return new JSONResponse([], Http::STATUS_OK); | ||
} | ||
|
||
private function setCard(?string $cardData = null) { | ||
try { | ||
$folder = $this->appData->getFolder('defaultContact'); | ||
} catch (NotFoundException $e) { | ||
$folder = $this->appData->newFolder('defaultContact'); | ||
} | ||
|
||
if (is_null($cardData)) { | ||
$cardData = file_get_contents(__DIR__ . '/../ExampleContentFiles/exampleContact.vcf'); | ||
} | ||
|
||
$file = (!$folder->fileExists('defaultContact.vcf')) ? $folder->newFile('defaultContact.vcf') : $folder->getFile('defaultContact.vcf'); | ||
$file->putContent($cardData); | ||
} | ||
|
||
private function defaultContactExists(): bool { | ||
try { | ||
$folder = $this->appData->getFolder('defaultContact'); | ||
} catch (NotFoundException $e) { | ||
return false; | ||
} | ||
return $folder->fileExists('defaultContact.vcf'); | ||
} | ||
|
||
} |
Oops, something went wrong.