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 { PeopleComponent as OrgPeopleComponent } from './organizations/manage/people.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 { UserConfirmComponent as OrgUserConfirmComponent } from './organizations/manage/user-confirm.component';
|
||||
import { UserGroupsComponent as OrgUserGroupsComponent } from './organizations/manage/user-groups.component';
|
||||
|
@ -312,6 +313,7 @@ registerLocaleData(localeZhTw, 'zh-TW');
|
|||
OrgManageCollectionsComponent,
|
||||
OrgManageComponent,
|
||||
OrgPeopleComponent,
|
||||
OrgPolicyEditComponent,
|
||||
OrgPoliciesComponent,
|
||||
OrgReusedPasswordsReportComponent,
|
||||
OrgRotateApiKeyComponent,
|
||||
|
@ -388,6 +390,7 @@ registerLocaleData(localeZhTw, 'zh-TW');
|
|||
OrgEntityEventsComponent,
|
||||
OrgEntityUsersComponent,
|
||||
OrgGroupAddEditComponent,
|
||||
OrgPolicyEditComponent,
|
||||
OrgRotateApiKeyComponent,
|
||||
OrgUserAddEditComponent,
|
||||
OrgUserConfirmComponent,
|
||||
|
|
|
@ -16,4 +16,4 @@
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<ng-template #edit></ng-template>
|
||||
<ng-template #editTemplate></ng-template>
|
||||
|
|
|
@ -10,8 +10,7 @@ import {
|
|||
Router,
|
||||
} from '@angular/router';
|
||||
|
||||
import { ToasterService } from 'angular2-toaster';
|
||||
import { Angulartics2 } from 'angulartics2';
|
||||
import { PolicyType } from 'jslib/enums/policyType';
|
||||
|
||||
import { ApiService } from 'jslib/abstractions/api.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 { Utils } from 'jslib/misc/utils';
|
||||
|
||||
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({
|
||||
selector: 'app-org-policies',
|
||||
templateUrl: 'policies.component.html',
|
||||
})
|
||||
export class PoliciesComponent implements OnInit {
|
||||
@ViewChild('edit', { read: ViewContainerRef }) editModalRef: ViewContainerRef;
|
||||
@ViewChild('editTemplate', { read: ViewContainerRef }) editModalRef: ViewContainerRef;
|
||||
|
||||
loading = true;
|
||||
organizationId: string;
|
||||
|
@ -45,25 +40,24 @@ export class PoliciesComponent implements OnInit {
|
|||
|
||||
constructor(private apiService: ApiService, private route: ActivatedRoute,
|
||||
private i18nService: I18nService, private componentFactoryResolver: ComponentFactoryResolver,
|
||||
private analytics: Angulartics2, private toasterService: ToasterService,
|
||||
private platformUtilsService: PlatformUtilsService, private userService: UserService,
|
||||
private router: Router) {
|
||||
this.policies = [
|
||||
{
|
||||
name: 'Two-step Login',
|
||||
description: 'vbxcvbxvcbxc',
|
||||
description: 'Enforce two-step login options.',
|
||||
type: PolicyType.TwoFactorAuthentication,
|
||||
enabled: false,
|
||||
},
|
||||
{
|
||||
name: 'Master Password',
|
||||
description: 'vbxcvb',
|
||||
description: 'Set requirements on master password strength.',
|
||||
type: PolicyType.MasterPassword,
|
||||
enabled: false,
|
||||
},
|
||||
{
|
||||
name: 'Password Generator',
|
||||
description: 'rye5tbfgdbfghj',
|
||||
description: 'Limit the parameters of the password generator.',
|
||||
type: PolicyType.PasswordGenerator,
|
||||
enabled: false,
|
||||
},
|
||||
|
@ -93,4 +87,28 @@ export class PoliciesComponent implements OnInit {
|
|||
});
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
|
@ -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": {
|
||||
"message": "Policies"
|
||||
},
|
||||
"editPolicy": {
|
||||
"message": "Edit Policy"
|
||||
},
|
||||
"groups": {
|
||||
"message": "Groups"
|
||||
},
|
||||
|
@ -2359,6 +2362,15 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"editedPolicyId": {
|
||||
"message": "Edited policy $ID$.",
|
||||
"placeholders": {
|
||||
"id": {
|
||||
"content": "$1",
|
||||
"example": "Master Password"
|
||||
}
|
||||
}
|
||||
},
|
||||
"createdGroupId": {
|
||||
"message": "Created group $ID$.",
|
||||
"placeholders": {
|
||||
|
|
Loading…
Reference in New Issue