Simplify admin domain management

This commit is contained in:
the-djmaze 2022-02-24 13:36:57 +01:00
parent 962ddde1f3
commit b5114fa73a
2 changed files with 40 additions and 89 deletions

View file

@ -1,4 +1,4 @@
import { pInt, pString, forEachObjectEntry } from 'Common/Utils'; import { pInt, forEachObjectEntry } from 'Common/Utils';
import { i18n, getNotification } from 'Common/Translator'; import { i18n, getNotification } from 'Common/Translator';
import Remote from 'Remote/Admin/Fetch'; import Remote from 'Remote/Admin/Fetch';
@ -112,16 +112,16 @@ class DomainPopupView extends AbstractViewPopup {
imapSecure: value => { imapSecure: value => {
if (this.enableSmartPorts()) { if (this.enableSmartPorts()) {
const port = pInt(this.imapPort()); const port = pInt(this.imapPort());
switch (pString(value)) { switch (pInt(value)) {
case '0': case 0:
case '2': case 2:
if (993 === port) { if (993 === port) {
this.imapPort('143'); this.imapPort(143);
} }
break; break;
case '1': case 1:
if (143 === port) { if (143 === port) {
this.imapPort('993'); this.imapPort(993);
} }
break; break;
// no default // no default
@ -132,20 +132,20 @@ class DomainPopupView extends AbstractViewPopup {
smtpSecure: value => { smtpSecure: value => {
if (this.enableSmartPorts()) { if (this.enableSmartPorts()) {
const port = pInt(this.smtpPort()); const port = pInt(this.smtpPort());
switch (pString(value)) { switch (pInt(value)) {
case '0': case 0:
if (465 === port || 587 === port) { if (465 === port || 587 === port) {
this.smtpPort('25'); this.smtpPort(25);
} }
break; break;
case '1': case 1:
if (25 === port || 587 === port) { if (25 === port || 587 === port) {
this.smtpPort('465'); this.smtpPort(465);
} }
break; break;
case '2': case 2:
if (25 === port || 465 === port) { if (25 === port || 465 === port) {
this.smtpPort('587'); this.smtpPort(587);
} }
break; break;
// no default // no default
@ -178,10 +178,7 @@ class DomainPopupView extends AbstractViewPopup {
} }
testConnectionCommand() { testConnectionCommand() {
this.testingDone(false); this.clearTesting(false);
this.testingImapError(false);
this.testingSieveError(false);
this.testingSmtpError(false);
this.testing(true); this.testing(true);
Remote.request('AdminDomainTest', Remote.request('AdminDomainTest',
@ -237,56 +234,36 @@ class DomainPopupView extends AbstractViewPopup {
onShow(oDomain) { onShow(oDomain) {
this.saving(false); this.saving(false);
this.clearTesting(); this.clearTesting();
this.clearForm(); this.clearForm();
if (oDomain) { if (oDomain) {
this.enableSmartPorts(false); this.enableSmartPorts(false);
this.edit(true); this.edit(true);
forEachObjectEntry(oDomain, (key, value) => this[key] && this[key](value));
this.name(oDomain.Name);
this.imapHost(oDomain.IncHost);
this.imapPort('' + pInt(oDomain.IncPort));
this.imapSecure(oDomain.IncSecure);
this.imapShortLogin(!!oDomain.IncShortLogin);
this.useSieve(!!oDomain.UseSieve);
this.sieveHost(oDomain.SieveHost);
this.sievePort('' + pInt(oDomain.SievePort));
this.sieveSecure(oDomain.SieveSecure);
this.smtpHost(oDomain.OutHost);
this.smtpPort('' + pInt(oDomain.OutPort));
this.smtpSecure(oDomain.OutSecure);
this.smtpShortLogin(!!oDomain.OutShortLogin);
this.smtpAuth(!!oDomain.OutAuth);
this.smtpSetSender(!!oDomain.OutSetSender);
this.smtpPhpMail(!!oDomain.OutUsePhpMail);
this.whiteList(oDomain.WhiteList);
this.aliasName(oDomain.AliasName);
this.enableSmartPorts(true); this.enableSmartPorts(true);
} }
} }
getDefaults() { getDefaults() {
return { return {
enableSmartPorts: false,
savingError: '', savingError: '',
name: '', name: '',
imapHost: '', imapHost: '',
imapPort: '143', imapPort: 143,
imapSecure: 0, imapSecure: 0,
imapShortLogin: false, imapShortLogin: false,
useSieve: false, useSieve: false,
sieveHost: '', sieveHost: '',
sievePort: '4190', sievePort: 4190,
sieveSecure: 0, sieveSecure: 0,
smtpHost: '', smtpHost: '',
smtpPort: '25', smtpPort: 25,
smtpSecure: 0, smtpSecure: 0,
smtpShortLogin: false, smtpShortLogin: false,
smtpAuth: true, smtpAuth: true,
@ -294,9 +271,7 @@ class DomainPopupView extends AbstractViewPopup {
smtpPhpMail: false, smtpPhpMail: false,
whiteList: '', whiteList: '',
aliasName: '', aliasName: ''
enableSmartPorts: false
}; };
} }

View file

@ -400,52 +400,28 @@ class Domain implements \JsonSerializable
); );
} }
public function ToSimpleJSON() : array
{
return array(
'Name' => $this->sName,
'IncHost' => $this->sIncHost,
'IncPort' => $this->iIncPort,
'IncSecure' => $this->iIncSecure,
'IncShortLogin' => $this->bIncShortLogin,
'UseSieve' => $this->bUseSieve,
'SieveHost' => $this->sSieveHost,
'SievePort' => $this->iSievePort,
'SieveSecure' => $this->iSieveSecure,
'OutHost' => $this->sOutHost,
'OutPort' => $this->iOutPort,
'OutSecure' => $this->iOutSecure,
'OutShortLogin' => $this->bOutShortLogin,
'OutAuth' => $this->bOutAuth,
'OutSetSender' => $this->bOutSetSender,
'OutUsePhpMail' => $this->bOutUsePhpMail,
'WhiteList' => $this->sWhiteList,
'AliasName' => $this->sAliasName
);
}
public function jsonSerialize() public function jsonSerialize()
{ {
return array( return array(
// '@Object' => 'Object/Domain', // '@Object' => 'Object/Domain',
'Name' => \MailSo\Base\Utils::IdnToUtf8($this->sName), 'name' => \MailSo\Base\Utils::IdnToUtf8($this->sName),
'IncHost' => \MailSo\Base\Utils::IdnToUtf8($this->sIncHost), 'imapHost' => \MailSo\Base\Utils::IdnToUtf8($this->sIncHost),
'IncPort' => $this->iIncPort, 'imapPort' => $this->iIncPort,
'IncSecure' => $this->iIncSecure, 'imapSecure' => $this->iIncSecure,
'IncShortLogin' => $this->bIncShortLogin, 'imapShortLogin' => $this->bIncShortLogin,
'UseSieve' => $this->bUseSieve, 'useSieve' => $this->bUseSieve,
'SieveHost' => \MailSo\Base\Utils::IdnToUtf8($this->sSieveHost), 'sieveHost' => \MailSo\Base\Utils::IdnToUtf8($this->sSieveHost),
'SievePort' => $this->iSievePort, 'sievePort' => $this->iSievePort,
'SieveSecure' => $this->iSieveSecure, 'sieveSecure' => $this->iSieveSecure,
'OutHost' => \MailSo\Base\Utils::IdnToUtf8($this->sOutHost), 'smtpHost' => \MailSo\Base\Utils::IdnToUtf8($this->sOutHost),
'OutPort' => $this->iOutPort, 'smtpPort' => $this->iOutPort,
'OutSecure' => $this->iOutSecure, 'smtpSecure' => $this->iOutSecure,
'OutShortLogin' => $this->bOutShortLogin, 'smtpShortLogin' => $this->bOutShortLogin,
'OutAuth' => $this->bOutAuth, 'smtpAuth' => $this->bOutAuth,
'OutSetSender' => $this->bOutSetSender, 'smtpSetSender' => $this->bOutSetSender,
'OutUsePhpMail' => $this->bOutUsePhpMail, 'smtpPhpMail' => $this->bOutUsePhpMail,
'WhiteList' => $this->sWhiteList, 'whiteList' => $this->sWhiteList,
'AliasName' => $this->sAliasName 'aliasName' => $this->sAliasName
); );
} }
} }