Commit a6fffcb8c3ae134a6ad5ca833e5037bf082d68ff

Authored by Vladyslav_Prykhodko
1 parent c01c0759

UI: Rename mail server value isDemo to showChangePassword. Fixed send test mail:…

… not work for empty password fields
@@ -126,6 +126,10 @@ public class AdminController extends BaseController { @@ -126,6 +126,10 @@ public class AdminController extends BaseController {
126 accessControlService.checkPermission(getCurrentUser(), Resource.ADMIN_SETTINGS, Operation.READ); 126 accessControlService.checkPermission(getCurrentUser(), Resource.ADMIN_SETTINGS, Operation.READ);
127 adminSettings = checkNotNull(adminSettings); 127 adminSettings = checkNotNull(adminSettings);
128 if (adminSettings.getKey().equals("mail")) { 128 if (adminSettings.getKey().equals("mail")) {
  129 + if(!adminSettings.getJsonValue().has("password")) {
  130 + AdminSettings mailSettings = checkNotNull(adminSettingsService.findAdminSettingsByKey(TenantId.SYS_TENANT_ID, "mail"));
  131 + ((ObjectNode) adminSettings.getJsonValue()).put("password", mailSettings.getJsonValue().get("password").asText());
  132 + }
129 String email = getCurrentUser().getEmail(); 133 String email = getCurrentUser().getEmail();
130 mailService.sendTestMail(adminSettings.getJsonValue(), email); 134 mailService.sendTestMail(adminSettings.getJsonValue(), email);
131 } 135 }
@@ -215,7 +215,7 @@ public class DefaultSystemDataLoaderService implements SystemDataLoaderService { @@ -215,7 +215,7 @@ public class DefaultSystemDataLoaderService implements SystemDataLoaderService {
215 node.put("password", ""); 215 node.put("password", "");
216 node.put("tlsVersion", "TLSv1.2");//NOSONAR, key used to identify password field (not password value itself) 216 node.put("tlsVersion", "TLSv1.2");//NOSONAR, key used to identify password field (not password value itself)
217 node.put("enableProxy", false); 217 node.put("enableProxy", false);
218 - node.put("isDemo", true); 218 + node.put("showChangePassword", false);
219 mailSettings.setJsonValue(node); 219 mailSettings.setJsonValue(node);
220 adminSettingsService.saveAdminSettings(TenantId.SYS_TENANT_ID, mailSettings); 220 adminSettingsService.saveAdminSettings(TenantId.SYS_TENANT_ID, mailSettings);
221 } 221 }
@@ -126,10 +126,10 @@ @@ -126,10 +126,10 @@
126 <input matInput formControlName="username" placeholder="{{ 'common.enter-username' | translate }}" 126 <input matInput formControlName="username" placeholder="{{ 'common.enter-username' | translate }}"
127 autocomplete="new-username"/> 127 autocomplete="new-username"/>
128 </mat-form-field> 128 </mat-form-field>
129 - <mat-checkbox *ngIf="!isDemo" formControlName="changePassword" style="padding-bottom: 16px;"> 129 + <mat-checkbox *ngIf="showChangePassword" formControlName="changePassword" style="padding-bottom: 16px;">
130 {{ 'admin.change-password' | translate }} 130 {{ 'admin.change-password' | translate }}
131 </mat-checkbox> 131 </mat-checkbox>
132 - <mat-form-field class="mat-block" *ngIf="mailSettings.get('changePassword').value || isDemo"> 132 + <mat-form-field class="mat-block" *ngIf="mailSettings.get('changePassword').value || !showChangePassword">
133 <mat-label translate>common.password</mat-label> 133 <mat-label translate>common.password</mat-label>
134 <input matInput formControlName="password" type="password" 134 <input matInput formControlName="password" type="password"
135 placeholder="{{ 'common.enter-password' | translate }}" autocomplete="new-password"> 135 placeholder="{{ 'common.enter-password' | translate }}" autocomplete="new-password">
@@ -25,7 +25,7 @@ import { AdminService } from '@core/http/admin.service'; @@ -25,7 +25,7 @@ import { AdminService } from '@core/http/admin.service';
25 import { ActionNotificationShow } from '@core/notification/notification.actions'; 25 import { ActionNotificationShow } from '@core/notification/notification.actions';
26 import { TranslateService } from '@ngx-translate/core'; 26 import { TranslateService } from '@ngx-translate/core';
27 import { HasConfirmForm } from '@core/guards/confirm-on-exit.guard'; 27 import { HasConfirmForm } from '@core/guards/confirm-on-exit.guard';
28 -import { deepClone, isString } from '@core/utils'; 28 +import { isDefinedAndNotNull, isString } from '@core/utils';
29 import { Subject } from 'rxjs'; 29 import { Subject } from 'rxjs';
30 import { takeUntil } from 'rxjs/operators'; 30 import { takeUntil } from 'rxjs/operators';
31 31
@@ -39,7 +39,7 @@ export class MailServerComponent extends PageComponent implements OnInit, OnDest @@ -39,7 +39,7 @@ export class MailServerComponent extends PageComponent implements OnInit, OnDest
39 mailSettings: FormGroup; 39 mailSettings: FormGroup;
40 adminSettings: AdminSettings<MailServerSettings>; 40 adminSettings: AdminSettings<MailServerSettings>;
41 smtpProtocols = ['smtp', 'smtps']; 41 smtpProtocols = ['smtp', 'smtps'];
42 - isDemo = true; 42 + showChangePassword = false;
43 43
44 tlsVersions = ['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3']; 44 tlsVersions = ['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3'];
45 45
@@ -61,10 +61,11 @@ export class MailServerComponent extends PageComponent implements OnInit, OnDest @@ -61,10 +61,11 @@ export class MailServerComponent extends PageComponent implements OnInit, OnDest
61 if (this.adminSettings.jsonValue && isString(this.adminSettings.jsonValue.enableTls)) { 61 if (this.adminSettings.jsonValue && isString(this.adminSettings.jsonValue.enableTls)) {
62 this.adminSettings.jsonValue.enableTls = (this.adminSettings.jsonValue.enableTls as any) === 'true'; 62 this.adminSettings.jsonValue.enableTls = (this.adminSettings.jsonValue.enableTls as any) === 'true';
63 } 63 }
64 - this.isDemo = this.adminSettings.jsonValue.isDemo;  
65 - delete this.adminSettings.jsonValue.isDemo; 64 + this.showChangePassword =
  65 + isDefinedAndNotNull(this.adminSettings.jsonValue.showChangePassword) ? this.adminSettings.jsonValue.showChangePassword : true ;
  66 + delete this.adminSettings.jsonValue.showChangePassword;
66 this.mailSettings.reset(this.adminSettings.jsonValue); 67 this.mailSettings.reset(this.adminSettings.jsonValue);
67 - this.enableMailPassword(this.isDemo); 68 + this.enableMailPassword(!this.showChangePassword);
68 this.enableProxyChanged(); 69 this.enableProxyChanged();
69 } 70 }
70 ); 71 );
@@ -147,11 +148,9 @@ export class MailServerComponent extends PageComponent implements OnInit, OnDest @@ -147,11 +148,9 @@ export class MailServerComponent extends PageComponent implements OnInit, OnDest
147 this.adminSettings.jsonValue = {...this.adminSettings.jsonValue, ...this.mailSettingsFormValue}; 148 this.adminSettings.jsonValue = {...this.adminSettings.jsonValue, ...this.mailSettingsFormValue};
148 this.adminService.saveAdminSettings(this.adminSettings).subscribe( 149 this.adminService.saveAdminSettings(this.adminSettings).subscribe(
149 (adminSettings) => { 150 (adminSettings) => {
150 - adminSettings.jsonValue.password = this.mailSettings.value.password;  
151 this.adminSettings = adminSettings; 151 this.adminSettings = adminSettings;
152 - const formSettings = deepClone(this.adminSettings.jsonValue);  
153 - formSettings.changePassword = this.mailSettings.get('changePassword').value || this.isDemo;  
154 - this.mailSettings.reset(formSettings, {emitEvent: false}); 152 + this.showChangePassword = true;
  153 + this.mailSettings.reset(this.adminSettings.jsonValue);
155 } 154 }
156 ); 155 );
157 } 156 }
@@ -27,7 +27,7 @@ export interface AdminSettings<T> { @@ -27,7 +27,7 @@ export interface AdminSettings<T> {
27 export declare type SmtpProtocol = 'smtp' | 'smtps'; 27 export declare type SmtpProtocol = 'smtp' | 'smtps';
28 28
29 export interface MailServerSettings { 29 export interface MailServerSettings {
30 - isDemo: boolean; 30 + showChangePassword: boolean;
31 mailFrom: string; 31 mailFrom: string;
32 smtpProtocol: SmtpProtocol; 32 smtpProtocol: SmtpProtocol;
33 smtpHost: string; 33 smtpHost: string;