-
-
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.
fixup! feat: add example contact on first login
Signed-off-by: Hamza Mahjoubi <[email protected]>
- Loading branch information
Showing
9 changed files
with
3,628 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,25 +6,29 @@ | |
|
||
namespace OCA\DAV\Controller; | ||
|
||
use OCA\Contacts\AppInfo\Application; | ||
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 IAppData $appData, | ||
private IAppDataFactory $appDataFactory, | ||
private IAppManager $appManager, | ||
) { | ||
parent::__construct(Application::APP_ID, $request); | ||
$this->appData = $this->appDataFactory->get('dav'); | ||
} | ||
|
||
|
||
|
@@ -44,44 +48,32 @@ public function setAppConfig($key, $allow) { | |
} | ||
|
||
public function setDefaultContact($contactData) { | ||
if (!$this->config->getAppValue(Application::APP_ID, 'enableDefaultContact', 'yes')) { | ||
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'); | ||
} | ||
$file = (!$folder->fileExists('defaultContact.vcf')) ? $folder->newFile('defaultContact.vcf') : $folder->getFile('defaultContact.vcf'); | ||
$file->putContent($contactData); | ||
return new JSONResponse([], Http::STATUS_OK); | ||
} | ||
|
||
private function setInitialDefaultContact() { | ||
$cardData = 'BEGIN:VCARD' . PHP_EOL . | ||
'VERSION:3.0' . PHP_EOL . | ||
'PRODID:-//Nextcloud Contacts v' . $this->appManager->getAppVersion('contacts') . PHP_EOL . | ||
'UID: janeDoe' . PHP_EOL . | ||
'FN:Jane Doe' . PHP_EOL . | ||
'ADR;TYPE=HOME:;;123 Street Street;City;State;;Country' . PHP_EOL . | ||
'EMAIL;TYPE=WORK:[email protected]' . PHP_EOL . | ||
'TEL;TYPE=HOME,VOICE:+999999999999' . PHP_EOL . | ||
'TITLE:Manager' . PHP_EOL . | ||
'ORG:Company' . PHP_EOL . | ||
'BDAY;VALUE=DATE:20000101' . PHP_EOL . | ||
'URL;VALUE=URI:https://example.com/' . PHP_EOL . | ||
'REV;VALUE=DATE-AND-OR-TIME:20241227T144820Z' . PHP_EOL . | ||
'END:VCARD'; | ||
$folder = $this->appData->getFolder('defaultContact'); | ||
$file = $folder->newFile('defaultContact.vcf'); | ||
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) { | ||
$this->appData->newFolder('defaultContact'); | ||
return false; | ||
} | ||
return $folder->fileExists('defaultContact.vcf'); | ||
|
3,555 changes: 3,555 additions & 0 deletions
3,555
apps/dav/lib/ExampleContentFiles/exampleContact.vcf
Large diffs are not rendered by default.
Oops, something went wrong.
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
Oops, something went wrong.