-
-
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
22 changed files
with
799 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/** | ||
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\DAV\Controller; | ||
|
||
use OCA\Contacts\AppInfo\Application; | ||
use OCP\App\IAppManager; | ||
use OCP\AppFramework\ApiController; | ||
use OCP\AppFramework\Http; | ||
use OCP\AppFramework\Http\JSONResponse; | ||
use OCP\Files\IAppData; | ||
use OCP\Files\NotFoundException; | ||
use OCP\IConfig; | ||
use OCP\IRequest; | ||
|
||
class ExampleContentController extends ApiController { | ||
|
||
public function __construct( | ||
IRequest $request, | ||
private IConfig $config, | ||
private IAppData $appData, | ||
private IAppManager $appManager, | ||
) { | ||
parent::__construct(Application::APP_ID, $request); | ||
} | ||
|
||
|
||
/** | ||
* update appconfig (admin setting) | ||
* | ||
* @param string allow the value to set | ||
* | ||
* @return JSONResponse an empty JSONResponse with respective http status code | ||
*/ | ||
public function setAppConfig($key, $allow) { | ||
if ($allow === 'yes' && $key === 'enableDefaultContact' && !$this->defaultContactExists()) { | ||
$this->setInitialDefaultContact(); | ||
} | ||
$this->config->setAppValue(Application::APP_ID, $key, $allow); | ||
return new JSONResponse([], Http::STATUS_OK); | ||
} | ||
|
||
public function setDefaultContact($contactData) { | ||
if (!$this->config->getAppValue(Application::APP_ID, 'enableDefaultContact', 'yes')) { | ||
return new JSONResponse([], Http::STATUS_FORBIDDEN); | ||
} | ||
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'); | ||
$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'); | ||
} | ||
|
||
} |
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,65 @@ | ||
<?php | ||
/** | ||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\DAV\Settings; | ||
|
||
use OCA\DAV\AppInfo\Application; | ||
use OCP\App\IAppManager; | ||
use OCP\AppFramework\Http\TemplateResponse; | ||
use OCP\AppFramework\Services\IInitialState; | ||
use OCP\IConfig; | ||
use OCP\Settings\IDelegatedSettings; | ||
|
||
class ExampleContentSettings implements IDelegatedSettings { | ||
|
||
private const defaults = [ | ||
'enableDefaultContact' => 'yes', | ||
]; | ||
|
||
/** | ||
* ExampleContentSettings constructor. | ||
* | ||
* @param IConfig $config | ||
* @param IInitialState $initialState | ||
*/ | ||
public function __construct( | ||
private IConfig $config, | ||
private IInitialState $initialState, | ||
private IAppManager $appManager, | ||
) { | ||
} | ||
|
||
public function getForm(): TemplateResponse { | ||
$enableDefaultContact = $this->config->getAppValue(Application::APP_ID, 'enableDefaultContact', 'yes'); | ||
$this->initialState->provideInitialState(Application::APP_ID, 'enableDefaultContact', $enableDefaultContact); | ||
return new TemplateResponse(Application::APP_ID, 'settings-example-content'); | ||
} | ||
|
||
public function getSection(): ?string { | ||
/* if (!$this->appManager->isEnabledForUser('contacts')) { | ||
return null; | ||
}*/ | ||
|
||
return 'groupware'; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getPriority() { | ||
return 10; | ||
} | ||
|
||
public function getName(): ?string { | ||
return 'Example Content'; | ||
} | ||
|
||
public function getAuthorizedAppConfig(): array { | ||
return [ | ||
'dav' => ['/(' . implode('|', array_keys(self::defaults)) . ')/'] | ||
]; | ||
} | ||
|
||
} |
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,13 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
import Vue from 'vue' | ||
import { translate } from '@nextcloud/l10n' | ||
import ExampleContactSettings from './views/ExampleContactSettings.vue' | ||
|
||
Vue.prototype.$t = translate | ||
|
||
const View = Vue.extend(ExampleContactSettings); | ||
|
||
(new View({})).$mount('#settings-example-content') |
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,114 @@ | ||
<!-- | ||
- SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
- SPDX-License-Identifier: AGPL-3.0-or-later | ||
--> | ||
|
||
<template> | ||
<NcSettingsSection id="exmaple-content" | ||
:name="$t('dav', 'Example Content')" | ||
:description="$t('dav', 'Set example content to be created on new user first login.')"> | ||
<p> | ||
<input id="enable-default-contact" | ||
v-model="enableDefaultContact" | ||
type="checkbox" | ||
class="checkbox" | ||
@change="updateEnableDefaultContact"> | ||
<label for="enable-default-contact"> {{ $t('dav',"Default contact is added to the user's own address book on user's first login.") }} </label> | ||
<NcButton v-if="enableDefaultContact" | ||
class="import-button" | ||
type="primary" | ||
@click="toggleModal"> | ||
<template #icon> | ||
<IconUpload :size="20" /> | ||
</template> | ||
{{ $t('contacts', 'Import contact') }} | ||
</NcButton> | ||
<NcDialog :open.sync="isModalOpen" | ||
:name="$t('contacts', 'Import contacts')" | ||
:buttons="buttons"> | ||
<div> | ||
<p>{{ $t('dav', 'Importing a new .vcf file will delete the existing default contact and replace it with the new one. Do you want to continue?') }}</p> | ||
<input id="contact-import" | ||
ref="contact-import-input" | ||
:disabled="loading" | ||
type="file" | ||
class="hidden-visually" | ||
@change="processFile"> | ||
</div> | ||
</NcDialog> | ||
</p> | ||
</NcSettingsSection> | ||
</template> | ||
<script> | ||
import axios from '@nextcloud/axios' | ||
import { generateUrl } from '@nextcloud/router' | ||
import { loadState } from '@nextcloud/initial-state' | ||
import { NcDialog, NcButton, NcSettingsSection } from '@nextcloud/vue' | ||
import { showSuccess } from '@nextcloud/dialogs' | ||
import IconUpload from 'vue-material-design-icons/Upload.vue' | ||
import IconCancel from '@mdi/svg/svg/cancel.svg' | ||
import IconCheck from '@mdi/svg/svg/check.svg' | ||
|
||
export default { | ||
name: 'ExampleContactSettings', | ||
components: { | ||
NcDialog, | ||
NcButton, | ||
NcSettingsSection, | ||
IconUpload, | ||
}, | ||
data() { | ||
return { | ||
enableDefaultContact: loadState('contacts', 'enableDefaultContact') === 'yes', | ||
isModalOpen: false, | ||
loading: false, | ||
buttons: [ | ||
{ | ||
label: this.$t('contacts', 'Cancel'), | ||
icon: IconCancel, | ||
callback: () => { this.isModalOpen = false }, | ||
}, | ||
{ | ||
label: this.$t('contacts', 'Import'), | ||
type: 'primary', | ||
icon: IconCheck, | ||
callback: () => { this.clickImportInput() }, | ||
}, | ||
], | ||
} | ||
}, | ||
methods: { | ||
updateEnableDefaultContact() { | ||
axios.put(generateUrl('apps/dav/api/defaultcontact/config/{key}', { key: 'enableDefaultContact' }), { | ||
allow: this.enableDefaultContact ? 'yes' : 'no', | ||
}) | ||
}, | ||
toggleModal() { | ||
this.isModalOpen = !this.isModalOpen | ||
}, | ||
clickImportInput() { | ||
this.$refs['contact-import-input'].click() | ||
}, | ||
|
||
processFile(event) { | ||
this.loading = true | ||
|
||
const file = event.target.files[0] | ||
const reader = new FileReader() | ||
|
||
reader.onload = () => { | ||
this.isModalOpen = false | ||
axios.put(generateUrl('/apps/dav/api/defaultcontact/contact'), { contactData: reader.result }) | ||
event.target.value = '' | ||
} | ||
reader.readAsText(file) | ||
showSuccess(this.$t('dav', 'Contact imported successfully')) | ||
}, | ||
}, | ||
} | ||
</script> | ||
<style lang="scss" scoped> | ||
.import-button { | ||
margin-top: 1rem; | ||
} | ||
</style> |
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,11 @@ | ||
<?php | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
script('dav', 'settings-example-content'); | ||
|
||
?> | ||
|
||
<div id="settings-example-content"></div> |
Oops, something went wrong.