diff --git a/jslib b/jslib index 6c840719..7d8143b2 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 6c8407196bf9e79468f8f6449b4377083ee6d36b +Subproject commit 7d8143b288a5352c439c2a789f97f906a4f54e27 diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 71e6a20e..d86d555d 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -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, diff --git a/src/app/organizations/manage/policies.component.html b/src/app/organizations/manage/policies.component.html index a30a5ccf..f1c0be51 100644 --- a/src/app/organizations/manage/policies.component.html +++ b/src/app/organizations/manage/policies.component.html @@ -16,4 +16,4 @@ - + diff --git a/src/app/organizations/manage/policies.component.ts b/src/app/organizations/manage/policies.component.ts index 5995a6f3..dec5772a 100644 --- a/src/app/organizations/manage/policies.component.ts +++ b/src/app/organizations/manage/policies.component.ts @@ -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, 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; + }); + } } diff --git a/src/app/organizations/manage/policy-edit.component.html b/src/app/organizations/manage/policy-edit.component.html new file mode 100644 index 00000000..6bec1e7b --- /dev/null +++ b/src/app/organizations/manage/policy-edit.component.html @@ -0,0 +1,34 @@ + + + + + {{'editPolicy' | i18n}} - {{name}} + + × + + + + + {{'loading' | i18n}} + + + {{description}} + + + + {{'enabled' | i18n}} + + + + + + + diff --git a/src/app/organizations/manage/policy-edit.component.ts b/src/app/organizations/manage/policy-edit.component.ts new file mode 100644 index 00000000..ea6332bc --- /dev/null +++ b/src/app/organizations/manage/policy-edit.component.ts @@ -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; + + 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 { } + } +} diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index c503f658..dabee692 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -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": {
{{description}}