1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-22 03:03:43 +00:00

configure some policy data

This commit is contained in:
Kyle Spearrin
2020-01-29 17:49:20 -05:00
parent f7f70408c9
commit 088301c4be
3 changed files with 107 additions and 2 deletions

View File

@@ -31,10 +31,27 @@ export class PolicyEditComponent implements OnInit {
@Input() organizationId: string;
@Output() onSavedPolicy = new EventEmitter();
policyType = PolicyType;
loading = true;
enabled = false;
formPromise: Promise<any>;
// Master password
masterPassMinLength?: number;
// TODO
// Password generator
passGenMinLength?: number;
passGenMinNumbers?: number;
passGenMinSpecial?: number;
passGenUseNumbers?: boolean;
passGenUseSpecial?: boolean;
passGenUseUpper?: boolean;
passGenUseLower?: boolean;
private policy: PolicyResponse;
constructor(private apiService: ApiService, private i18nService: I18nService,
@@ -49,7 +66,28 @@ export class PolicyEditComponent implements OnInit {
async load() {
try {
this.policy = await this.apiService.getPolicy(this.organizationId, this.type);
this.enabled = this.policy.enabled;
if (this.policy != null) {
this.enabled = this.policy.enabled;
if (this.policy.data != null) {
switch (this.type) {
case PolicyType.PasswordGenerator:
this.passGenMinLength = this.policy.data.minLength;
this.passGenMinNumbers = this.policy.data.minNumbers;
this.passGenMinSpecial = this.policy.data.minSpecial;
this.passGenUseLower = this.policy.data.useLower;
this.passGenUseUpper = this.policy.data.useUpper;
this.passGenUseSpecial = this.policy.data.useSpecial;
this.passGenUseNumbers = this.policy.data.useNumbers;
break;
case PolicyType.MasterPassword:
this.masterPassMinLength = this.policy.data.minLength;
break;
default:
break;
}
}
}
} catch (e) {
if (e.statusCode === 404) {
this.enabled = false;
@@ -64,6 +102,26 @@ export class PolicyEditComponent implements OnInit {
request.enabled = this.enabled;
request.type = this.type;
request.data = null;
switch (this.type) {
case PolicyType.PasswordGenerator:
request.data = {
minLength: this.passGenMinLength,
minNumbers: this.passGenMinNumbers,
minSpecial: this.passGenMinSpecial,
useNumbers: this.passGenUseNumbers,
useSpecial: this.passGenUseSpecial,
useLower: this.passGenUseLower,
useUpper: this.passGenUseUpper,
};
break;
case PolicyType.MasterPassword:
request.data = {
minLength: this.masterPassMinLength,
};
break;
default:
break;
}
try {
this.formPromise = this.apiService.putPolicy(this.organizationId, this.type, request);
await this.formPromise;