Skip to content

Commit 0ce0a54

Browse files
fix[frontend](federation): added email configuration initial parameters load
1 parent ad75464 commit 0ce0a54

3 files changed

Lines changed: 47 additions & 4 deletions

File tree

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {Component} from '@angular/core';
1+
import {Component, OnInit} from '@angular/core';
2+
import {UtmConfigParamsService} from '../../../shared/services/config/utm-config-params.service';
3+
import {SectionConfigParamType} from '../../../shared/types/configuration/section-config-param.type';
24
import {
35
FEDERATION_EMAIL_CONFIG_PARAMS,
46
FEDERATION_EMAIL_CONFIG_SECTION
@@ -9,7 +11,46 @@ import {
911
templateUrl: './federation-email-config.page.component.html',
1012
styleUrls: ['./federation-email-config.page.component.scss']
1113
})
12-
export class FederationEmailConfigPageComponent {
14+
export class FederationEmailConfigPageComponent implements OnInit {
1315
readonly section = FEDERATION_EMAIL_CONFIG_SECTION;
14-
readonly params = FEDERATION_EMAIL_CONFIG_PARAMS;
16+
readonly params: SectionConfigParamType[] = FEDERATION_EMAIL_CONFIG_PARAMS.map(p => ({...p}));
17+
18+
constructor(private paramsService: UtmConfigParamsService) {}
19+
20+
ngOnInit(): void {
21+
this.paramsService.query({
22+
page: 0,
23+
size: 10000,
24+
'sectionId.equals': this.section.id,
25+
sort: 'id,asc'
26+
}).subscribe(response => {
27+
const byShort = new Map<string, SectionConfigParamType>();
28+
(response.body || []).forEach(p => byShort.set(p.confParamShort, p));
29+
this.params.forEach(p => {
30+
const server = byShort.get(p.confParamShort);
31+
if (server) {
32+
p.id = server.id;
33+
p.confParamValue = server.confParamValue;
34+
}
35+
});
36+
this.maskPasswordIfPreviouslySet();
37+
});
38+
}
39+
40+
private maskPasswordIfPreviouslySet(): void {
41+
const password = this.params.find(p => p.confParamShort === 'utmstack.mail.password');
42+
if (!password || !this.isEmpty(password.confParamValue)) {
43+
return;
44+
}
45+
const others = this.params.filter(p => p !== password);
46+
const allOthersFilled = others.length > 0 && others.every(p => !this.isEmpty(p.confParamValue));
47+
if (allOthersFilled) {
48+
password.confParamPlaceholder = '••••••••';
49+
password.confParamRequired = false;
50+
}
51+
}
52+
53+
private isEmpty(value: unknown): boolean {
54+
return value === null || value === undefined || value === '';
55+
}
1556
}

frontend/src/app/shared/components/utm/config/app-config-sections/app-config-sections.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ <h6 class="font-weight-semibold mb-2">{{section.section | titlecase}}</h6>
8282
[id]="'sectionParam'+conf.id"
8383
[required]="conf.confParamRequired"
8484
[disabled]="checkDisable(conf)"
85+
[placeholder]="conf.confParamPlaceholder || ''"
8586
[type]="conf.confParamDatatype" class="form-control pr-5">
8687

8788
<i *ngIf="allowCopy(conf)"

frontend/src/app/shared/types/configuration/section-config-param.type.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export class SectionConfigParamType {
44
confParamDatatype?: ConfigDataTypeEnum;
55
confParamDescription?: string;
66
confParamLarge?: string;
7-
confParamRequired?: true;
7+
confParamRequired?: boolean;
88
confParamShort?: string;
99
confParamValue?: any;
1010
id?: number;
@@ -15,6 +15,7 @@ export class SectionConfigParamType {
1515
confParamRestartRequired: boolean;
1616
confParamOption: string;
1717
confParamRegexp?: string;
18+
confParamPlaceholder?: string;
1819
}
1920

2021
export enum ConfigDataTypeEnum {

0 commit comments

Comments
 (0)