2018-06-26 05:16:59 +02:00
|
|
|
import { Component, OnInit } from "@angular/core";
|
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
|
|
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
|
|
import { UpdateDomainsRequest } from "@bitwarden/common/models/request/updateDomainsRequest";
|
2018-06-26 05:16:59 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "app-domain-rules",
|
|
|
|
templateUrl: "domain-rules.component.html",
|
|
|
|
})
|
|
|
|
export class DomainRulesComponent implements OnInit {
|
|
|
|
loading = true;
|
|
|
|
custom: string[] = [];
|
2018-06-26 17:50:23 +02:00
|
|
|
global: any[] = [];
|
2018-06-26 05:16:59 +02:00
|
|
|
formPromise: Promise<any>;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private apiService: ApiService,
|
|
|
|
private i18nService: I18nService,
|
2021-12-07 20:41:45 +01:00
|
|
|
private platformUtilsService: PlatformUtilsService,
|
|
|
|
private logService: LogService
|
|
|
|
) {}
|
2018-06-26 05:16:59 +02:00
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
const response = await this.apiService.getSettingsDomains();
|
|
|
|
this.loading = false;
|
2018-06-26 17:50:23 +02:00
|
|
|
if (response.equivalentDomains != null) {
|
2021-02-03 18:41:33 +01:00
|
|
|
this.custom = response.equivalentDomains.map((d) => d.join(", "));
|
2018-06-26 17:50:23 +02:00
|
|
|
}
|
|
|
|
if (response.globalEquivalentDomains != null) {
|
|
|
|
this.global = response.globalEquivalentDomains.map((d) => {
|
2021-12-17 15:57:11 +01:00
|
|
|
return {
|
2018-06-26 17:50:23 +02:00
|
|
|
domains: d.domains.join(", "),
|
|
|
|
excluded: d.excluded,
|
|
|
|
key: d.type,
|
|
|
|
};
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
2018-06-26 17:50:23 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-06-26 17:50:23 +02:00
|
|
|
|
|
|
|
toggleExcluded(globalDomain: any) {
|
|
|
|
globalDomain.excluded = !globalDomain.excluded;
|
|
|
|
}
|
|
|
|
|
|
|
|
customize(globalDomain: any) {
|
|
|
|
globalDomain.excluded = true;
|
|
|
|
this.custom.push(globalDomain.domains);
|
|
|
|
}
|
|
|
|
|
|
|
|
remove(index: number) {
|
|
|
|
this.custom.splice(index, 1);
|
2018-06-26 05:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
add() {
|
2021-02-03 18:41:33 +01:00
|
|
|
this.custom.push("");
|
2018-06-26 17:50:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async submit() {
|
|
|
|
const request = new UpdateDomainsRequest();
|
|
|
|
request.excludedGlobalEquivalentDomains = this.global
|
|
|
|
.filter((d) => d.excluded)
|
|
|
|
.map((d) => d.key);
|
|
|
|
if (request.excludedGlobalEquivalentDomains.length === 0) {
|
|
|
|
request.excludedGlobalEquivalentDomains = null;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-06-26 17:50:23 +02:00
|
|
|
request.equivalentDomains = this.custom
|
2021-12-07 20:41:45 +01:00
|
|
|
.filter((d) => d != null && d.trim() !== "")
|
|
|
|
.map((d) => d.split(",").map((d2) => d2.trim()));
|
|
|
|
if (request.equivalentDomains.length === 0) {
|
|
|
|
request.equivalentDomains = null;
|
2018-06-26 17:50:23 +02:00
|
|
|
}
|
2018-06-26 05:16:59 +02:00
|
|
|
|
2018-06-26 17:50:23 +02:00
|
|
|
try {
|
|
|
|
this.formPromise = this.apiService.putSettingsDomains(request);
|
|
|
|
await this.formPromise;
|
|
|
|
this.platformUtilsService.showToast("success", null, this.i18nService.t("domainsUpdated"));
|
2021-10-20 18:30:04 +02:00
|
|
|
} catch (e) {
|
2018-06-26 17:50:23 +02:00
|
|
|
this.logService.error(e);
|
2018-06-26 05:16:59 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2018-06-26 17:50:23 +02:00
|
|
|
indexTrackBy(index: number, obj: any): any {
|
|
|
|
return index;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-06-26 05:16:59 +02:00
|
|
|
}
|