mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 10:09:20 +03:00
feat: add admin settings for nextcloudAddressbook related changes
This commit is contained in:
parent
bda1c28eb7
commit
19ddcfbf37
3 changed files with 116 additions and 17 deletions
|
|
@ -7,11 +7,21 @@ class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBoo
|
|||
use RainLoop\Providers\AddressBook\CardDAV;
|
||||
private $contactsManager;
|
||||
|
||||
private const DEFAULT_URI = 'webmail';
|
||||
private const SETTINGS_KEY = 'nextCloudAddressBookUri';
|
||||
|
||||
function __construct()
|
||||
private string $defaultUri = 'webmail';
|
||||
private string $defaultName = 'WebMail';
|
||||
private string $defaultDescription = 'Recipients from snappymail';
|
||||
private bool $ignoreSystemAddressBook = true;
|
||||
|
||||
|
||||
function __construct(string $defaultUri = 'webmail', string $defaultName = 'WebMail', string $defaultDescription = 'Recipients from snappymail', bool $ignoreSystemAddressBook = true)
|
||||
{
|
||||
$this->defaultUri = $defaultUri;
|
||||
$this->defaultName = $defaultName;
|
||||
$this->defaultDescription = $defaultDescription;
|
||||
$this->ignoreSystemAddressBook = $ignoreSystemAddressBook;
|
||||
|
||||
$this->GetSavedAddressBookKey();
|
||||
}
|
||||
|
||||
|
|
@ -19,9 +29,11 @@ class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBoo
|
|||
{
|
||||
$this->contactsManager = \OC::$server->getContactsManager();
|
||||
|
||||
foreach ($this->contactsManager->getUserAddressBooks() as $addressBook) {
|
||||
if ($addressBook->isSystemAddressBook()) {
|
||||
$this->contactsManager->unregisterAddressBook($addressBook);
|
||||
if ($this->ignoreSystemAddressBook) {
|
||||
foreach ($this->contactsManager->getUserAddressBooks() as $addressBook) {
|
||||
if ($addressBook->isSystemAddressBook()) {
|
||||
$this->contactsManager->unregisterAddressBook($addressBook);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -33,8 +45,8 @@ class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBoo
|
|||
|
||||
if ($addressBookId === null) {
|
||||
return $cardDavBackend->createAddressBook($principalUri, $uri, array_filter([
|
||||
'{DAV:}displayname' => 'WebMail',
|
||||
'{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'Recipients from snappymail',
|
||||
'{DAV:}displayname' => $this->defaultName,
|
||||
'{urn:ietf:params:xml:ns:carddav}addressbook-description' => $this->defaultDescription,
|
||||
]));
|
||||
}
|
||||
|
||||
|
|
@ -181,6 +193,6 @@ class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBoo
|
|||
|
||||
private function GetSavedUri(): string
|
||||
{
|
||||
return $this->Settings()->GetConf(self::SETTINGS_KEY, self::DEFAULT_URI);
|
||||
return $this->Settings()->GetConf(self::SETTINGS_KEY, $this->defaultUri);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
REQUIRED = '2.36.2';
|
||||
|
||||
|
||||
private const DEFAULT_ADDRESSBOOK_NAME = 'WebMail';
|
||||
private const DEFAULT_ADDRESSBOOK_DESCRIPTION = 'Recipients from snappymail';
|
||||
private const DEFAULT_ADDRESSBOOK_URI = 'webmail';
|
||||
private const ADDRESSBOOK_SETTINGS_KEY = 'nextCloudAddressBookUri';
|
||||
|
||||
|
|
@ -46,9 +48,15 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
$this->addHook('smtp.before-login', 'beforeLogin');
|
||||
$this->addHook('sieve.before-login', 'beforeLogin');
|
||||
|
||||
$this->addJs('js/addressbook.js');
|
||||
$this->addJsonHook('NextcloudGetAddressBooks', 'GetAddressBooks');
|
||||
$this->addJsonHook('NextcloudUpdateAddressBook', 'UpdateAddressBook');
|
||||
if ($this->Config()->Get('plugin', 'enableNcAddressbook', false)) {
|
||||
$this->addJs('js/addressbook.js');
|
||||
$this->addJsonHook('NextcloudGetAddressBooks', 'GetAddressBooks');
|
||||
$this->addJsonHook('NextcloudUpdateAddressBook', 'UpdateAddressBook');
|
||||
}
|
||||
|
||||
if ($this->Config()->Get('plugin', 'disableInhouseAddressbook', false)) {
|
||||
$this->addJs('js/hideInhouseAddressbook.js');
|
||||
}
|
||||
} else {
|
||||
\SnappyMail\Log::debug('Nextcloud', 'NOT integrated');
|
||||
// \OC::$server->getConfig()->getAppValue('snappymail', 'snappymail-no-embed');
|
||||
|
|
@ -62,10 +70,12 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
|
||||
$contactsManager = \OC::$server->getContactsManager();
|
||||
|
||||
$selectedUri = $this->Settings()->GetConf(self::ADDRESSBOOK_SETTINGS_KEY, self::DEFAULT_ADDRESSBOOK_URI);
|
||||
$defaultUri = $this->Config()->Get('plugin', 'defaultNCAddressbookUri', self::DEFAULT_ADDRESSBOOK_URI);
|
||||
$selectedUri = $this->UserSettings()->GetConf(self::ADDRESSBOOK_SETTINGS_KEY, $defaultUri);
|
||||
$ignoreSystemAddressbook = $this->Config()->Get('plugin', 'ignoreSystemAddressbook', true);
|
||||
|
||||
foreach ($contactsManager->getUserAddressBooks() as $addressBook) {
|
||||
if ($addressBook->isSystemAddressBook()) {
|
||||
if ($ignoreSystemAddressbook && $addressBook->isSystemAddressBook()) {
|
||||
$contactsManager->unregisterAddressBook($addressBook);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -89,7 +99,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
public function UpdateAddressBook(): array
|
||||
{
|
||||
$uri = $this->jsonParam('uri');
|
||||
$oSettings = $this->Settings();
|
||||
$oSettings = $this->UserSettings();
|
||||
if (\is_string($uri)) {
|
||||
$oSettings->SetConf(self::ADDRESSBOOK_SETTINGS_KEY, $uri);
|
||||
$this->SettingsProvider()->Save($this->Account(), $oSettings);
|
||||
|
|
@ -422,12 +432,24 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
$this->Config()->Get('plugin', 'ignoreSystemAddressbook', true)
|
||||
);
|
||||
}
|
||||
if ('address-book' === $sName) {
|
||||
|
||||
if ('address-book' === $sName && $this->Config()->Get('plugin', 'enableNcAddressbook', false)) {
|
||||
if (!\is_array($mResult)) {
|
||||
$mResult = array();
|
||||
}
|
||||
include_once __DIR__ . '/NextcloudAddressBook.php';
|
||||
$mResult = new NextcloudAddressBook();
|
||||
|
||||
$ignoreSystemAddressbook = $this->Config()->Get('plugin', 'ignoreSystemAddressbook', true);
|
||||
$defaultName = $this->Config()->Get('plugin', 'defaultNCAddressbookName', self::DEFAULT_ADDRESSBOOK_NAME);
|
||||
$defaultDescription = $this->Config()->Get('plugin', 'defaultNCAddressbookDescription', self::DEFAULT_ADDRESSBOOK_DESCRIPTION);
|
||||
$defaultUri = $this->Config()->Get('plugin', 'defaultNCAddressbookUri', self::DEFAULT_ADDRESSBOOK_URI);
|
||||
|
||||
$mResult = new NextcloudAddressBook(
|
||||
$defaultUri,
|
||||
$defaultName,
|
||||
$defaultDescription,
|
||||
$ignoreSystemAddressbook
|
||||
);
|
||||
}
|
||||
/*
|
||||
if ($this->Config()->Get('plugin', 'storage', false) && ('storage' === $sName || 'storage-local' === $sName)) {
|
||||
|
|
@ -453,6 +475,26 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
->SetDefaultValue(false)
|
||||
*/
|
||||
\RainLoop\Plugins\Property::NewInstance('calendar')->SetLabel('Enable "Put ICS in calendar"')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||
->SetDefaultValue(false),
|
||||
|
||||
\RainLoop\Plugins\Property::NewInstance('enableNcAddressbook')->SetLabel('Enable User to choose Nextcloud addressbook for recipients')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||
->SetDefaultValue(false),
|
||||
|
||||
\RainLoop\Plugins\Property::NewInstance('defaultNCAddressbookUri')->SetLabel('Default nextcloud addressbook URI for recipinets')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING)
|
||||
->SetDefaultValue('webmail'),
|
||||
|
||||
\RainLoop\Plugins\Property::NewInstance('defaultNCAddressbookName')->SetLabel('Default nextcloud addressbook Name for recipinets')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING)
|
||||
->SetDefaultValue(self::DEFAULT_ADDRESSBOOK_NAME),
|
||||
|
||||
\RainLoop\Plugins\Property::NewInstance('defaultNCAddressbookDescription')->SetLabel('Default nextcloud addressbook description for recipinets')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING)
|
||||
->SetDefaultValue(self::DEFAULT_ADDRESSBOOK_DESCRIPTION),
|
||||
|
||||
\RainLoop\Plugins\Property::NewInstance('disableInhouseAddressbook')->SetLabel('Disable SnappyMail internal addressbook. This is recomended if nextcloud addressbook is being used.')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||
->SetDefaultValue(false)
|
||||
);
|
||||
|
|
@ -496,7 +538,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
return \RainLoop\Api::Actions()->SettingsProvider(true);
|
||||
}
|
||||
|
||||
private function Settings(): \RainLoop\Settings
|
||||
private function UserSettings(): \RainLoop\Settings
|
||||
{
|
||||
return $this->SettingsProvider()->Load($this->Account());
|
||||
}
|
||||
|
|
|
|||
45
plugins/nextcloud/js/hideInhouseAddressbook.js
Normal file
45
plugins/nextcloud/js/hideInhouseAddressbook.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
(rl => {
|
||||
if (rl) {
|
||||
addEventListener('rl-view-model', e => {
|
||||
if ('MailFolderList' === e.detail.viewModelTemplateID) {
|
||||
const container = e.detail.viewModelDom.querySelector('.buttonContacts');
|
||||
if (container) {
|
||||
container.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
addEventListener('rl-view-model', e => {
|
||||
if ('SystemDropDown' === e.detail.viewModelTemplateID) {
|
||||
const container = e.detail.viewModelDom.querySelector('.dropdown-menu');
|
||||
if (container) {
|
||||
for (i = 0; i < container.children.length; i++) {
|
||||
const element = container.children[i];
|
||||
const attr = element.getAttribute("data-bind");
|
||||
if (attr && attr.includes("visible: allowContacts")) {
|
||||
element.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
addEventListener('rl-view-model', e => {
|
||||
if ('PopupsCompose' === e.detail.viewModelTemplateID) {
|
||||
const container = e.detail.viewModelDom.querySelector('.pull-right');
|
||||
if (container) {
|
||||
for (i = 0; i < container.children.length; i++) {
|
||||
const element = container.children[i];
|
||||
const attr = element.getAttribute("data-bind");
|
||||
if (attr && attr.includes("visible: allowContacts")) {
|
||||
element.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
})(window.rl);
|
||||
Loading…
Add table
Add a link
Reference in a new issue