LP#1775466 fm-editor and admin page org perm limits
authorBill Erickson <berickxx@gmail.com>
Wed, 1 Aug 2018 22:17:46 +0000 (18:17 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 1 Aug 2018 22:17:49 +0000 (18:17 -0400)
Apply view org perm limits in the admin page org selector.

Apply view/update/create org perm limits to org-selector's inside of
fm-editor panes.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html
Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts
Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts
Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.html
Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts

index 800165e..721423c 100644 (file)
             <eg-org-select *ngIf="field.datatype == 'org_unit'"
               placeholder="{{field.label}}..."
               i18n-placeholder
+              [limitPerms]="modePerms[mode]"
               [applyDefault]="field.orgDefaultAllowed"
               [initialOrgId]="record[field.name]()"
               (onChange)="record[field.name]($event)">
index 8162775..ebde009 100644 (file)
@@ -45,6 +45,10 @@ export class FmRecordEditorComponent
     // TODO: allow this to be update in real time by the caller?
     record: IdlObject;
 
+    // Permissions extracted from the permacrud defs in the IDL
+    // for the current IDL class
+    modePerms: {[mode: string]: string};
+
     @Input() customFieldTemplates:
         {[fieldName: string]: CustomFieldTemplate} = {};
 
@@ -164,6 +168,13 @@ export class FmRecordEditorComponent
             });
         }
 
+        const pc = this.idlDef.permacrud || {};
+        this.modePerms = {
+            view:   pc.retrieve ? pc.retrieve.perms : [],
+            create: pc.create ? pc.create.perms : [],
+            update: pc.update ? pc.update.perms : [],
+        };
+
         // create a new record from scratch
         this.pkeyIsEditable = !('pkey_sequence' in this.idlDef);
         this.record = this.idl.create(this.idlClass);
index bd63ed5..bc3bf85 100644 (file)
@@ -103,9 +103,7 @@ export class OrgSelectComponent implements OnInit {
       private store: StoreService,
       private org: OrgService,
       private perm: PermService
-    ) {
-        this.permLimitOrgs = [];
-    }
+    ) { }
 
     ngOnInit() {
 
@@ -130,8 +128,14 @@ export class OrgSelectComponent implements OnInit {
     // 
     applyPermLimitOrgs(perms: string[]) {
 
-        if (!perms || perms.length === 0) {
-            this.permLimitOrgs = [];
+        if (!perms) {
+            return;
+        }
+
+        // handle lazy clients that pass null perm names
+        perms = perms.filter(p => p !== null && p !== undefined);
+
+        if (perms.length === 0) {
             return;
         }
 
@@ -181,7 +185,7 @@ export class OrgSelectComponent implements OnInit {
                     this.hidden.filter(id => org.id() === id).length === 0
                 );
 
-                if (this.permLimitOrgs && this.permLimitOrgs.length) {
+                if (this.permLimitOrgs) {
                     // Avoid showing org units where the user does
                     // not have the requested permission.
                     orgs = orgs.filter(org => 
index 600db00..9435dc2 100644 (file)
@@ -12,6 +12,7 @@
           <span class="input-group-text">{{orgFieldLabel}}</span>
         </div>
         <eg-org-select 
+          [limitPerms]="viewPerms"
           [initialOrg]="contextOrg"
           (onChange)="orgOnChange($event)">
         </eg-org-select>
index 2713c78..003a2da 100644 (file)
@@ -64,6 +64,7 @@ export class AdminPageComponent implements OnInit {
 
     contextOrg: IdlObject;
     orgFieldLabel: string;
+    viewPerms: string;
 
     constructor(
         private idl: IdlService,
@@ -101,6 +102,14 @@ export class AdminPageComponent implements OnInit {
         this.idlClassDef = this.idl.classes[this.idlClass];
         this.pkeyField = this.idlClassDef.pkey || 'id';
         this.persistKey = 'admin.' + this.idlClassDef.table;
+
+        // Limit the view org selector to orgs where the user has 
+        // permacrud-encoded view permissions.
+        const pc = this.idlClassDef.permacrud;
+        if (pc && pc.retrieve) {
+            this.viewPerms = pc.retrieve.perms;
+        }
+
         this.applyOrgValues();
 
         // If the caller provides not data source, create a generic one.