aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/lib
diff options
context:
space:
mode:
authorSebastianKrupinski <krupinskis05@gmail.com>2024-09-17 07:45:44 -0400
committerSebastianKrupinski <krupinskis05@gmail.com>2024-11-12 13:19:35 -0500
commit3e870695bc4989e5e2c6f59c44ed5dbd501a7673 (patch)
tree73083164c8d239499610d71f063a4aaae50a7191 /apps/settings/lib
parentde1c175d39f2513f3a99e393c9ea70175e43ae10 (diff)
downloadnextcloud-server-3e870695bc4989e5e2c6f59c44ed5dbd501a7673.tar.gz
nextcloud-server-3e870695bc4989e5e2c6f59c44ed5dbd501a7673.zip
feat: mail provider settingsfeat/mail-provider-settings
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
Diffstat (limited to 'apps/settings/lib')
-rw-r--r--apps/settings/lib/AppInfo/Application.php11
-rw-r--r--apps/settings/lib/Listener/MailProviderListener.php61
-rw-r--r--apps/settings/lib/Settings/Admin/MailProvider.php52
3 files changed, 124 insertions, 0 deletions
diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php
index d3d12a6c53d..688e6ebbed5 100644
--- a/apps/settings/lib/AppInfo/Application.php
+++ b/apps/settings/lib/AppInfo/Application.php
@@ -15,6 +15,7 @@ use OC\Server;
use OCA\Settings\Hooks;
use OCA\Settings\Listener\AppPasswordCreatedActivityListener;
use OCA\Settings\Listener\GroupRemovedListener;
+use OCA\Settings\Listener\MailProviderListener;
use OCA\Settings\Listener\UserAddedToGroupActivityListener;
use OCA\Settings\Listener\UserRemovedFromGroupActivityListener;
use OCA\Settings\Mailer\NewUserMailHelper;
@@ -22,6 +23,7 @@ use OCA\Settings\Middleware\SubadminMiddleware;
use OCA\Settings\Search\AppSearch;
use OCA\Settings\Search\SectionSearch;
use OCA\Settings\Search\UserSearch;
+use OCA\Settings\Settings\Admin\MailProvider;
use OCA\Settings\SetupChecks\AllowedAdminRanges;
use OCA\Settings\SetupChecks\AppDirsWithDifferentOwner;
use OCA\Settings\SetupChecks\BruteForceThrottler;
@@ -86,6 +88,8 @@ use OCP\Group\Events\GroupDeletedEvent;
use OCP\Group\Events\UserAddedEvent;
use OCP\Group\Events\UserRemovedEvent;
use OCP\IServerContainer;
+use OCP\Settings\Events\DeclarativeSettingsGetValueEvent;
+use OCP\Settings\Events\DeclarativeSettingsSetValueEvent;
use OCP\Settings\IManager;
use OCP\Util;
@@ -113,10 +117,17 @@ class Application extends App implements IBootstrap {
$context->registerEventListener(UserRemovedEvent::class, UserRemovedFromGroupActivityListener::class);
$context->registerEventListener(GroupDeletedEvent::class, GroupRemovedListener::class);
+ // Register Mail Provider listeners
+ $context->registerEventListener(DeclarativeSettingsGetValueEvent::class, MailProviderListener::class);
+ $context->registerEventListener(DeclarativeSettingsSetValueEvent::class, MailProviderListener::class);
+
// Register well-known handlers
$context->registerWellKnownHandler(SecurityTxtHandler::class);
$context->registerWellKnownHandler(ChangePasswordHandler::class);
+ // Register Settings Form(s)
+ $context->registerDeclarativeSettings(MailProvider::class);
+
/**
* Core class wrappers
*/
diff --git a/apps/settings/lib/Listener/MailProviderListener.php b/apps/settings/lib/Listener/MailProviderListener.php
new file mode 100644
index 00000000000..974378c0006
--- /dev/null
+++ b/apps/settings/lib/Listener/MailProviderListener.php
@@ -0,0 +1,61 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Listener;
+
+use OCA\Settings\AppInfo\Application;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\IAppConfig;
+use OCP\Settings\Events\DeclarativeSettingsGetValueEvent;
+use OCP\Settings\Events\DeclarativeSettingsSetValueEvent;
+
+/** @template-implements IEventListener<DeclarativeSettingsGetValueEvent|DeclarativeSettingsSetValueEvent> */
+class MailProviderListener implements IEventListener {
+
+ public function __construct(
+ private IAppConfig $config,
+ ) {
+ }
+
+ public function handle(Event $event): void {
+
+ /** @var DeclarativeSettingsGetValueEvent|DeclarativeSettingsSetValueEvent $event */
+ if ($event->getApp() !== Application::APP_ID) {
+ return;
+ }
+
+ if ($event instanceof DeclarativeSettingsGetValueEvent) {
+ $this->handleGetValue($event);
+ return;
+ }
+
+ if ($event instanceof DeclarativeSettingsSetValueEvent) {
+ $this->handleSetValue($event);
+ return;
+ }
+
+ }
+
+ private function handleGetValue(DeclarativeSettingsGetValueEvent $event): void {
+
+ if ($event->getFieldId() === 'mail_providers_enabled') {
+ $event->setValue((int)$this->config->getValueBool('core', 'mail_providers_enabled', true));
+ }
+
+ }
+
+ private function handleSetValue(DeclarativeSettingsSetValueEvent $event): void {
+
+ if ($event->getFieldId() === 'mail_providers_enabled') {
+ $this->config->setValueBool('core', 'mail_providers_enabled', (bool)$event->getValue());
+ $event->stopPropagation();
+ }
+
+ }
+
+}
diff --git a/apps/settings/lib/Settings/Admin/MailProvider.php b/apps/settings/lib/Settings/Admin/MailProvider.php
new file mode 100644
index 00000000000..edbb484b16e
--- /dev/null
+++ b/apps/settings/lib/Settings/Admin/MailProvider.php
@@ -0,0 +1,52 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Settings\Admin;
+
+use OCP\IL10N;
+use OCP\Settings\DeclarativeSettingsTypes;
+use OCP\Settings\IDeclarativeSettingsForm;
+
+class MailProvider implements IDeclarativeSettingsForm {
+
+ public function __construct(
+ private IL10N $l,
+ ) {
+ }
+
+ public function getSchema(): array {
+ return [
+ 'id' => 'mail-provider-support',
+ 'priority' => 10,
+ 'section_type' => DeclarativeSettingsTypes::SECTION_TYPE_ADMIN,
+ 'section_id' => 'server',
+ 'storage_type' => DeclarativeSettingsTypes::STORAGE_TYPE_EXTERNAL,
+ 'title' => $this->l->t('Mail Providers'),
+ 'description' => $this->l->t('Mail provider enables sending emails directly through the user\'s personal email account. At present, this functionality is limited to calendar invitations. It requires Nextcloud Mail 4.1 and an email account in Nextcloud Mail that matches the user\'s email address in Nextcloud.'),
+
+ 'fields' => [
+ [
+ 'id' => 'mail_providers_enabled',
+ 'title' => $this->l->t('Send emails using'),
+ 'type' => DeclarativeSettingsTypes::RADIO,
+ 'default' => 1,
+ 'options' => [
+ [
+ 'name' => $this->l->t('Users\'s email account'),
+ 'value' => 1
+ ],
+ [
+ 'name' => $this->l->t('System email account'),
+ 'value' => 0
+ ],
+ ],
+ ],
+ ],
+ ];
+ }
+
+}