mirror of
https://github.com/bitwarden/browser.git
synced 2025-03-01 03:31:15 +01:00
policy edit
This commit is contained in:
parent
5b770084c9
commit
f6fb56229e
2
jslib
2
jslib
@ -1 +1 @@
|
|||||||
Subproject commit 6c8407196bf9e79468f8f6449b4377083ee6d36b
|
Subproject commit 7d8143b288a5352c439c2a789f97f906a4f54e27
|
@ -52,6 +52,7 @@ import { GroupsComponent as OrgGroupsComponent } from './organizations/manage/gr
|
|||||||
import { ManageComponent as OrgManageComponent } from './organizations/manage/manage.component';
|
import { ManageComponent as OrgManageComponent } from './organizations/manage/manage.component';
|
||||||
import { PeopleComponent as OrgPeopleComponent } from './organizations/manage/people.component';
|
import { PeopleComponent as OrgPeopleComponent } from './organizations/manage/people.component';
|
||||||
import { PoliciesComponent as OrgPoliciesComponent } from './organizations/manage/policies.component';
|
import { PoliciesComponent as OrgPoliciesComponent } from './organizations/manage/policies.component';
|
||||||
|
import { PolicyEditComponent as OrgPolicyEditComponent } from './organizations/manage/policy-edit.component';
|
||||||
import { UserAddEditComponent as OrgUserAddEditComponent } from './organizations/manage/user-add-edit.component';
|
import { UserAddEditComponent as OrgUserAddEditComponent } from './organizations/manage/user-add-edit.component';
|
||||||
import { UserConfirmComponent as OrgUserConfirmComponent } from './organizations/manage/user-confirm.component';
|
import { UserConfirmComponent as OrgUserConfirmComponent } from './organizations/manage/user-confirm.component';
|
||||||
import { UserGroupsComponent as OrgUserGroupsComponent } from './organizations/manage/user-groups.component';
|
import { UserGroupsComponent as OrgUserGroupsComponent } from './organizations/manage/user-groups.component';
|
||||||
@ -312,6 +313,7 @@ registerLocaleData(localeZhTw, 'zh-TW');
|
|||||||
OrgManageCollectionsComponent,
|
OrgManageCollectionsComponent,
|
||||||
OrgManageComponent,
|
OrgManageComponent,
|
||||||
OrgPeopleComponent,
|
OrgPeopleComponent,
|
||||||
|
OrgPolicyEditComponent,
|
||||||
OrgPoliciesComponent,
|
OrgPoliciesComponent,
|
||||||
OrgReusedPasswordsReportComponent,
|
OrgReusedPasswordsReportComponent,
|
||||||
OrgRotateApiKeyComponent,
|
OrgRotateApiKeyComponent,
|
||||||
@ -388,6 +390,7 @@ registerLocaleData(localeZhTw, 'zh-TW');
|
|||||||
OrgEntityEventsComponent,
|
OrgEntityEventsComponent,
|
||||||
OrgEntityUsersComponent,
|
OrgEntityUsersComponent,
|
||||||
OrgGroupAddEditComponent,
|
OrgGroupAddEditComponent,
|
||||||
|
OrgPolicyEditComponent,
|
||||||
OrgRotateApiKeyComponent,
|
OrgRotateApiKeyComponent,
|
||||||
OrgUserAddEditComponent,
|
OrgUserAddEditComponent,
|
||||||
OrgUserConfirmComponent,
|
OrgUserConfirmComponent,
|
||||||
|
@ -16,4 +16,4 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<ng-template #edit></ng-template>
|
<ng-template #editTemplate></ng-template>
|
||||||
|
@ -10,8 +10,7 @@ import {
|
|||||||
Router,
|
Router,
|
||||||
} from '@angular/router';
|
} from '@angular/router';
|
||||||
|
|
||||||
import { ToasterService } from 'angular2-toaster';
|
import { PolicyType } from 'jslib/enums/policyType';
|
||||||
import { Angulartics2 } from 'angulartics2';
|
|
||||||
|
|
||||||
import { ApiService } from 'jslib/abstractions/api.service';
|
import { ApiService } from 'jslib/abstractions/api.service';
|
||||||
import { I18nService } from 'jslib/abstractions/i18n.service';
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||||
@ -20,20 +19,16 @@ import { UserService } from 'jslib/abstractions/user.service';
|
|||||||
|
|
||||||
import { PolicyResponse } from 'jslib/models/response/policyResponse';
|
import { PolicyResponse } from 'jslib/models/response/policyResponse';
|
||||||
|
|
||||||
import { Utils } from 'jslib/misc/utils';
|
|
||||||
|
|
||||||
import { ModalComponent } from '../../modal.component';
|
import { ModalComponent } from '../../modal.component';
|
||||||
import { EntityUsersComponent } from './entity-users.component';
|
|
||||||
import { GroupAddEditComponent } from './group-add-edit.component';
|
|
||||||
|
|
||||||
import { PolicyType } from 'jslib/enums/policyType';
|
import { PolicyEditComponent } from './policy-edit.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-org-policies',
|
selector: 'app-org-policies',
|
||||||
templateUrl: 'policies.component.html',
|
templateUrl: 'policies.component.html',
|
||||||
})
|
})
|
||||||
export class PoliciesComponent implements OnInit {
|
export class PoliciesComponent implements OnInit {
|
||||||
@ViewChild('edit', { read: ViewContainerRef }) editModalRef: ViewContainerRef;
|
@ViewChild('editTemplate', { read: ViewContainerRef }) editModalRef: ViewContainerRef;
|
||||||
|
|
||||||
loading = true;
|
loading = true;
|
||||||
organizationId: string;
|
organizationId: string;
|
||||||
@ -45,25 +40,24 @@ export class PoliciesComponent implements OnInit {
|
|||||||
|
|
||||||
constructor(private apiService: ApiService, private route: ActivatedRoute,
|
constructor(private apiService: ApiService, private route: ActivatedRoute,
|
||||||
private i18nService: I18nService, private componentFactoryResolver: ComponentFactoryResolver,
|
private i18nService: I18nService, private componentFactoryResolver: ComponentFactoryResolver,
|
||||||
private analytics: Angulartics2, private toasterService: ToasterService,
|
|
||||||
private platformUtilsService: PlatformUtilsService, private userService: UserService,
|
private platformUtilsService: PlatformUtilsService, private userService: UserService,
|
||||||
private router: Router) {
|
private router: Router) {
|
||||||
this.policies = [
|
this.policies = [
|
||||||
{
|
{
|
||||||
name: 'Two-step Login',
|
name: 'Two-step Login',
|
||||||
description: 'vbxcvbxvcbxc',
|
description: 'Enforce two-step login options.',
|
||||||
type: PolicyType.TwoFactorAuthentication,
|
type: PolicyType.TwoFactorAuthentication,
|
||||||
enabled: false,
|
enabled: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Master Password',
|
name: 'Master Password',
|
||||||
description: 'vbxcvb',
|
description: 'Set requirements on master password strength.',
|
||||||
type: PolicyType.MasterPassword,
|
type: PolicyType.MasterPassword,
|
||||||
enabled: false,
|
enabled: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Password Generator',
|
name: 'Password Generator',
|
||||||
description: 'rye5tbfgdbfghj',
|
description: 'Limit the parameters of the password generator.',
|
||||||
type: PolicyType.PasswordGenerator,
|
type: PolicyType.PasswordGenerator,
|
||||||
enabled: false,
|
enabled: false,
|
||||||
},
|
},
|
||||||
@ -93,4 +87,28 @@ export class PoliciesComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
edit(p: any) {
|
||||||
|
if (this.modal != null) {
|
||||||
|
this.modal.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
||||||
|
this.modal = this.editModalRef.createComponent(factory).instance;
|
||||||
|
const childComponent = this.modal.show<PolicyEditComponent>(
|
||||||
|
PolicyEditComponent, this.editModalRef);
|
||||||
|
|
||||||
|
childComponent.name = p.name;
|
||||||
|
childComponent.description = p.description;
|
||||||
|
childComponent.type = p.type;
|
||||||
|
childComponent.organizationId = this.organizationId;
|
||||||
|
childComponent.onSavedPolicy.subscribe(() => {
|
||||||
|
this.modal.close();
|
||||||
|
this.load();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.modal.onClosed.subscribe(() => {
|
||||||
|
this.modal = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
34
src/app/organizations/manage/policy-edit.component.html
Normal file
34
src/app/organizations/manage/policy-edit.component.html
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<div class="modal fade" tabindex="-1" role="dialog" aria-modal="true" aria-labelledby="policiesEditTitle">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<form class="modal-content" #form (ngSubmit)="submit()" [appApiAction]="formPromise" ngNativeValidate>
|
||||||
|
<div class="modal-header">
|
||||||
|
<h2 class="modal-title" id="policiesEditTitle">{{'editPolicy' | i18n}} - {{name}}</h2>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" appA11yTitle="{{'close' | i18n}}">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body" *ngIf="loading">
|
||||||
|
<i class="fa fa-spinner fa-spin text-muted" title="{{'loading' | i18n}}" aria-hidden="true"></i>
|
||||||
|
<span class="sr-only">{{'loading' | i18n}}</span>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body" *ngIf="!loading">
|
||||||
|
<p class="text-muted">{{description}}</p>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="checkbox" id="enabled" [(ngModel)]="enabled"
|
||||||
|
name="Enabled">
|
||||||
|
<label class="form-check-label" for="enabled">{{'enabled' | i18n}}</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="submit" class="btn btn-primary btn-submit" [disabled]="form.loading">
|
||||||
|
<i class="fa fa-spinner fa-spin" title="{{'loading' | i18n}}" aria-hidden="true"></i>
|
||||||
|
<span>{{'save' | i18n}}</span>
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn btn-outline-secondary"
|
||||||
|
data-dismiss="modal">{{'cancel' | i18n}}</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
75
src/app/organizations/manage/policy-edit.component.ts
Normal file
75
src/app/organizations/manage/policy-edit.component.ts
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
import {
|
||||||
|
Component,
|
||||||
|
EventEmitter,
|
||||||
|
Input,
|
||||||
|
OnInit,
|
||||||
|
Output,
|
||||||
|
} from '@angular/core';
|
||||||
|
|
||||||
|
import { ToasterService } from 'angular2-toaster';
|
||||||
|
import { Angulartics2 } from 'angulartics2';
|
||||||
|
|
||||||
|
import { ApiService } from 'jslib/abstractions/api.service';
|
||||||
|
import { CollectionService } from 'jslib/abstractions/collection.service';
|
||||||
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||||
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||||
|
|
||||||
|
import { PolicyType } from 'jslib/enums/policyType';
|
||||||
|
|
||||||
|
import { PolicyRequest } from 'jslib/models/request/policyRequest';
|
||||||
|
|
||||||
|
import { PolicyResponse } from 'jslib/models/response/policyResponse';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-policy-edit',
|
||||||
|
templateUrl: 'policy-edit.component.html',
|
||||||
|
})
|
||||||
|
export class PolicyEditComponent implements OnInit {
|
||||||
|
@Input() name: string;
|
||||||
|
@Input() description: string;
|
||||||
|
@Input() type: PolicyType;
|
||||||
|
@Input() organizationId: string;
|
||||||
|
@Output() onSavedPolicy = new EventEmitter();
|
||||||
|
|
||||||
|
loading = true;
|
||||||
|
enabled = false;
|
||||||
|
formPromise: Promise<any>;
|
||||||
|
|
||||||
|
private policy: PolicyResponse;
|
||||||
|
|
||||||
|
constructor(private apiService: ApiService, private i18nService: I18nService,
|
||||||
|
private analytics: Angulartics2, private toasterService: ToasterService,
|
||||||
|
private collectionService: CollectionService, private platformUtilsService: PlatformUtilsService) { }
|
||||||
|
|
||||||
|
async ngOnInit() {
|
||||||
|
await this.load();
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async load() {
|
||||||
|
try {
|
||||||
|
this.policy = await this.apiService.getPolicy(this.organizationId, this.type);
|
||||||
|
this.enabled = this.policy.enabled;
|
||||||
|
} catch (e) {
|
||||||
|
if (e.statusCode === 404) {
|
||||||
|
this.enabled = false;
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async submit() {
|
||||||
|
const request = new PolicyRequest();
|
||||||
|
request.enabled = this.enabled;
|
||||||
|
request.type = this.type;
|
||||||
|
request.data = '';
|
||||||
|
try {
|
||||||
|
this.formPromise = this.apiService.putPolicy(this.organizationId, this.type, request);
|
||||||
|
await this.formPromise;
|
||||||
|
this.analytics.eventTrack.next({ action: 'Edited Policy' });
|
||||||
|
this.toasterService.popAsync('success', null, this.i18nService.t('editedPolicyId', this.name));
|
||||||
|
this.onSavedPolicy.emit();
|
||||||
|
} catch { }
|
||||||
|
}
|
||||||
|
}
|
@ -2050,6 +2050,9 @@
|
|||||||
"policies": {
|
"policies": {
|
||||||
"message": "Policies"
|
"message": "Policies"
|
||||||
},
|
},
|
||||||
|
"editPolicy": {
|
||||||
|
"message": "Edit Policy"
|
||||||
|
},
|
||||||
"groups": {
|
"groups": {
|
||||||
"message": "Groups"
|
"message": "Groups"
|
||||||
},
|
},
|
||||||
@ -2359,6 +2362,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"editedPolicyId": {
|
||||||
|
"message": "Edited policy $ID$.",
|
||||||
|
"placeholders": {
|
||||||
|
"id": {
|
||||||
|
"content": "$1",
|
||||||
|
"example": "Master Password"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"createdGroupId": {
|
"createdGroupId": {
|
||||||
"message": "Created group $ID$.",
|
"message": "Created group $ID$.",
|
||||||
"placeholders": {
|
"placeholders": {
|
||||||
|
Loading…
Reference in New Issue
Block a user