Skip to content

Commit 902d8b0

Browse files
authored
Merge pull request #57544 from nextcloud/refactor/mail-settings-vue
refactor(settings): migrate mail settings to Vue
2 parents c9ac8cf + 6ec212f commit 902d8b0

File tree

59 files changed

+1275
-743
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1275
-743
lines changed

apps/settings/lib/Controller/MailSettingsController.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ public function setMailSettings(
5656
string $mail_smtpmode,
5757
string $mail_smtpsecure,
5858
string $mail_smtphost,
59-
?string $mail_smtpauth,
59+
?bool $mail_smtpauth,
6060
string $mail_smtpport,
6161
string $mail_sendmailmode,
62+
?bool $mail_noverify = null,
6263
): DataResponse {
6364
$mail_smtpauth = $mail_smtpauth == '1';
6465

@@ -76,6 +77,15 @@ public function setMailSettings(
7677
$configs[$key] = empty($value) ? null : $value;
7778
}
7879

80+
if ($mail_noverify !== null) {
81+
$options = $this->config->getSystemValue('mail_smtpstreamoptions', []);
82+
$options['ssl'] ??= [];
83+
$options['ssl']['allow_self_signed'] = $mail_noverify;
84+
$options['ssl']['verify_peer'] = !$mail_noverify;
85+
$options['ssl']['verify_peer_name'] = !$mail_noverify;
86+
$configs['mail_smtpstreamoptions'] = $options;
87+
}
88+
7989
// Delete passwords from config in case no auth is specified
8090
if (!$mail_smtpauth) {
8191
$configs['mail_smtpname'] = null;
@@ -91,23 +101,18 @@ public function setMailSettings(
91101

92102
/**
93103
* Store the credentials used for SMTP in the config
94-
*
95-
* @param string $mail_smtpname
96-
* @param string $mail_smtppassword
97-
* @return DataResponse
98104
*/
99105
#[AuthorizedAdminSetting(settings: Overview::class)]
100106
#[PasswordConfirmationRequired]
101-
public function storeCredentials($mail_smtpname, $mail_smtppassword) {
107+
public function storeCredentials(string $mail_smtpname, ?string $mail_smtppassword): DataResponse {
102108
if ($mail_smtppassword === '********') {
103109
return new DataResponse($this->l10n->t('Invalid SMTP password.'), Http::STATUS_BAD_REQUEST);
104110
}
105111

106-
$this->config->setSystemValues([
107-
'mail_smtpname' => $mail_smtpname,
108-
'mail_smtppassword' => $mail_smtppassword,
109-
]);
110-
112+
if ($mail_smtppassword !== null) {
113+
$this->config->setSystemValue('mail_smtppassword', $mail_smtppassword);
114+
}
115+
$this->config->setSystemValue('mail_smtpname', $mail_smtpname);
111116
$this->config->setAppValue('core', 'emailTestSuccessful', '0');
112117

113118
return new DataResponse();

apps/settings/lib/Settings/Admin/Mail.php

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@
77
namespace OCA\Settings\Settings\Admin;
88

99
use OCP\AppFramework\Http\TemplateResponse;
10+
use OCP\AppFramework\Services\IInitialState;
1011
use OCP\IBinaryFinder;
1112
use OCP\IConfig;
1213
use OCP\IL10N;
14+
use OCP\IURLGenerator;
1315
use OCP\Server;
1416
use OCP\Settings\IDelegatedSettings;
17+
use OCP\Util;
1518

1619
class Mail implements IDelegatedSettings {
17-
/**
18-
* @param IConfig $config
19-
* @param IL10N $l
20-
*/
20+
2121
public function __construct(
2222
private IConfig $config,
2323
private IL10N $l,
24+
private IInitialState $initialState,
25+
private IURLGenerator $urlGenerator,
2426
) {
2527
}
2628

@@ -30,30 +32,59 @@ public function __construct(
3032
public function getForm() {
3133
$finder = Server::get(IBinaryFinder::class);
3234

33-
$parameters = [
34-
// Mail
35-
'sendmail_is_available' => $finder->findBinaryPath('sendmail') !== false,
35+
$smtpModeOptions = [
36+
['label' => 'SMTP', 'id' => 'smtp'],
37+
];
38+
if ($finder->findBinaryPath('sendmail') !== false) {
39+
$smtpModeOptions[] = ['label' => 'Sendmail', 'id' => 'sendmail'];
40+
}
41+
if ($finder->findBinaryPath('qmail') !== false) {
42+
$smtpModeOptions[] = ['label' => 'qmail', 'id' => 'qmail'];
43+
}
44+
45+
$this->initialState->provideInitialState('settingsAdminMail', [
46+
'configIsReadonly' => $this->config->getSystemValueBool('config_is_read_only', false),
47+
'docUrl' => $this->urlGenerator->linkToDocs('admin-email'),
48+
49+
'smtpModeOptions' => $smtpModeOptions,
50+
'smtpEncryptionOptions' => [
51+
['label' => $this->l->t('None / STARTTLS'), 'id' => ''],
52+
['label' => 'SSL/TLS', 'id' => 'ssl'],
53+
],
54+
'smtpSendmailModeOptions' => [
55+
['label' => 'smtp (-bs)', 'id' => 'smtp'],
56+
['label' => 'pipe (-t -i)', 'id' => 'pipe'],
57+
],
58+
]);
59+
60+
$smtpPassword = $this->config->getSystemValue('mail_smtppassword', '');
61+
if ($smtpPassword !== '') {
62+
$smtpPassword = '********';
63+
}
64+
65+
$smtpMode = $this->config->getSystemValue('mail_smtpmode', '');
66+
if ($smtpMode === '' || $smtpMode === 'php') {
67+
$smtpMode = 'smtp';
68+
}
69+
70+
$smtpOptions = $this->config->getSystemValue('mail_smtpstreamoptions', []);
71+
$this->initialState->provideInitialState('settingsAdminMailConfig', [
3672
'mail_domain' => $this->config->getSystemValue('mail_domain', ''),
3773
'mail_from_address' => $this->config->getSystemValue('mail_from_address', ''),
38-
'mail_smtpmode' => $this->config->getSystemValue('mail_smtpmode', ''),
74+
'mail_smtpmode' => $smtpMode,
3975
'mail_smtpsecure' => $this->config->getSystemValue('mail_smtpsecure', ''),
4076
'mail_smtphost' => $this->config->getSystemValue('mail_smtphost', ''),
4177
'mail_smtpport' => $this->config->getSystemValue('mail_smtpport', ''),
4278
'mail_smtpauth' => $this->config->getSystemValue('mail_smtpauth', false),
4379
'mail_smtpname' => $this->config->getSystemValue('mail_smtpname', ''),
44-
'mail_smtppassword' => $this->config->getSystemValue('mail_smtppassword', ''),
80+
'mail_smtppassword' => $smtpPassword,
4581
'mail_sendmailmode' => $this->config->getSystemValue('mail_sendmailmode', 'smtp'),
46-
];
47-
48-
if ($parameters['mail_smtppassword'] !== '') {
49-
$parameters['mail_smtppassword'] = '********';
50-
}
5182

52-
if ($parameters['mail_smtpmode'] === '' || $parameters['mail_smtpmode'] === 'php') {
53-
$parameters['mail_smtpmode'] = 'smtp';
54-
}
83+
'mail_noverify' => $smtpOptions['ssl']['allow_self_signed'] ?? false,
84+
]);
5585

56-
return new TemplateResponse('settings', 'settings/admin/additional-mail', $parameters, '');
86+
Util::addScript('settings', 'vue-settings-admin-mail');
87+
return new TemplateResponse('settings', 'settings/admin/additional-mail', renderAs: '');
5788
}
5889

5990
/**
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*!
2+
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import Vue from 'vue'
7+
import AdminSettingsMailServer from './views/AdminSettingsMailServer.vue'
8+
9+
const app = new Vue(AdminSettingsMailServer)
10+
app.$mount('#vue-admin-settings-mail')

apps/settings/src/admin-settings-sharing.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
/**
1+
/*!
22
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5+
56
import Vue from 'vue'
67
import AdminSettingsSharing from './views/AdminSettingsSharing.vue'
78

apps/settings/src/admin.js

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)