UI: Rename mail server value isDemo to showChangePassword. Fixed send test mail: not work for empty password fields

This commit is contained in:
Vladyslav_Prykhodko 2021-07-30 15:15:24 +03:00
parent c01c075984
commit a6fffcb8c3
5 changed files with 16 additions and 13 deletions

View File

@ -126,6 +126,10 @@ public class AdminController extends BaseController {
accessControlService.checkPermission(getCurrentUser(), Resource.ADMIN_SETTINGS, Operation.READ);
adminSettings = checkNotNull(adminSettings);
if (adminSettings.getKey().equals("mail")) {
if(!adminSettings.getJsonValue().has("password")) {
AdminSettings mailSettings = checkNotNull(adminSettingsService.findAdminSettingsByKey(TenantId.SYS_TENANT_ID, "mail"));
((ObjectNode) adminSettings.getJsonValue()).put("password", mailSettings.getJsonValue().get("password").asText());
}
String email = getCurrentUser().getEmail();
mailService.sendTestMail(adminSettings.getJsonValue(), email);
}

View File

@ -215,7 +215,7 @@ public class DefaultSystemDataLoaderService implements SystemDataLoaderService {
node.put("password", "");
node.put("tlsVersion", "TLSv1.2");//NOSONAR, key used to identify password field (not password value itself)
node.put("enableProxy", false);
node.put("isDemo", true);
node.put("showChangePassword", false);
mailSettings.setJsonValue(node);
adminSettingsService.saveAdminSettings(TenantId.SYS_TENANT_ID, mailSettings);
}

View File

@ -126,10 +126,10 @@
<input matInput formControlName="username" placeholder="{{ 'common.enter-username' | translate }}"
autocomplete="new-username"/>
</mat-form-field>
<mat-checkbox *ngIf="!isDemo" formControlName="changePassword" style="padding-bottom: 16px;">
<mat-checkbox *ngIf="showChangePassword" formControlName="changePassword" style="padding-bottom: 16px;">
{{ 'admin.change-password' | translate }}
</mat-checkbox>
<mat-form-field class="mat-block" *ngIf="mailSettings.get('changePassword').value || isDemo">
<mat-form-field class="mat-block" *ngIf="mailSettings.get('changePassword').value || !showChangePassword">
<mat-label translate>common.password</mat-label>
<input matInput formControlName="password" type="password"
placeholder="{{ 'common.enter-password' | translate }}" autocomplete="new-password">

View File

@ -25,7 +25,7 @@ import { AdminService } from '@core/http/admin.service';
import { ActionNotificationShow } from '@core/notification/notification.actions';
import { TranslateService } from '@ngx-translate/core';
import { HasConfirmForm } from '@core/guards/confirm-on-exit.guard';
import { deepClone, isString } from '@core/utils';
import { isDefinedAndNotNull, isString } from '@core/utils';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@ -39,7 +39,7 @@ export class MailServerComponent extends PageComponent implements OnInit, OnDest
mailSettings: FormGroup;
adminSettings: AdminSettings<MailServerSettings>;
smtpProtocols = ['smtp', 'smtps'];
isDemo = true;
showChangePassword = false;
tlsVersions = ['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3'];
@ -61,10 +61,11 @@ export class MailServerComponent extends PageComponent implements OnInit, OnDest
if (this.adminSettings.jsonValue && isString(this.adminSettings.jsonValue.enableTls)) {
this.adminSettings.jsonValue.enableTls = (this.adminSettings.jsonValue.enableTls as any) === 'true';
}
this.isDemo = this.adminSettings.jsonValue.isDemo;
delete this.adminSettings.jsonValue.isDemo;
this.showChangePassword =
isDefinedAndNotNull(this.adminSettings.jsonValue.showChangePassword) ? this.adminSettings.jsonValue.showChangePassword : true ;
delete this.adminSettings.jsonValue.showChangePassword;
this.mailSettings.reset(this.adminSettings.jsonValue);
this.enableMailPassword(this.isDemo);
this.enableMailPassword(!this.showChangePassword);
this.enableProxyChanged();
}
);
@ -147,11 +148,9 @@ export class MailServerComponent extends PageComponent implements OnInit, OnDest
this.adminSettings.jsonValue = {...this.adminSettings.jsonValue, ...this.mailSettingsFormValue};
this.adminService.saveAdminSettings(this.adminSettings).subscribe(
(adminSettings) => {
adminSettings.jsonValue.password = this.mailSettings.value.password;
this.adminSettings = adminSettings;
const formSettings = deepClone(this.adminSettings.jsonValue);
formSettings.changePassword = this.mailSettings.get('changePassword').value || this.isDemo;
this.mailSettings.reset(formSettings, {emitEvent: false});
this.showChangePassword = true;
this.mailSettings.reset(this.adminSettings.jsonValue);
}
);
}

View File

@ -27,7 +27,7 @@ export interface AdminSettings<T> {
export declare type SmtpProtocol = 'smtp' | 'smtps';
export interface MailServerSettings {
isDemo: boolean;
showChangePassword: boolean;
mailFrom: string;
smtpProtocol: SmtpProtocol;
smtpHost: string;