perm scoped org selector
authorJason Etheridge <jason@EquinoxOLI.org>
Wed, 2 Nov 2022 07:01:23 +0000 (03:01 -0400)
committerJason Etheridge <jason@EquinoxOLI.org>
Wed, 2 Nov 2022 07:01:36 +0000 (03:01 -0400)
for stat cat entries fm editor.  keep the template for the "sticky" org

Signed-off-by: Jason Etheridge <jason@EquinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/admin/local/stat_cat/stat_cat_entries.component.html
Open-ILS/src/eg2/src/app/staff/admin/local/stat_cat/stat_cat_entries.component.ts

index 431f8ef..465b381 100644 (file)
@@ -2,7 +2,7 @@
     i18n-bannerText></eg-staff-banner>
 
 <ng-template #orgTemplate>
-    <eg-org-select [hideOrgs]="hiddenOrgs" (onChange)="setOwner($event)" 
+    <eg-org-select [limitPerms]="limitPerms" (onChange)="setOwner($event)" 
         [initialOrgId]="statCatOrgId"></eg-org-select>
 </ng-template>
 
index 19a0f15..a63d2b1 100644 (file)
@@ -21,7 +21,7 @@ export class StatCatEntriesComponent implements OnInit {
     statCatId: number; // parent stat cat id
     statCatOrgId: number; // parent stat cat org id
     statCatOrg: IdlObject; // parent stat cat org Idl
-    hiddenOrgs: any[];  // List of invalid orgs for a new entry
+    limitPerms: any[]; // For use with the org template for the FM editor
     statCatType: 'Copy' | 'Patron';  // parent type
     defaultNewRecord: IdlObject;
     copyDataSource: GridDataSource = new GridDataSource();
@@ -86,6 +86,7 @@ export class StatCatEntriesComponent implements OnInit {
             'UPDATE_PATRON_STAT_CAT_ENTRY'], true)
             .then(userPerms => {
             this.userPerms = userPerms;
+            console.debug('checkPerms', userPerms);
             if (this.statCatType === 'Copy') {
                 this.userPerms.canEdit =
                     this.userPerms.UPDATE_COPY_STAT_CAT_ENTRY.indexOf(this.statCatOrg) !== -1;
@@ -104,17 +105,29 @@ export class StatCatEntriesComponent implements OnInit {
         });
     }
 
+    setLimitPerms(mode) {
+        if (this.statCatType === 'Copy') {
+            if (mode === 'create') {
+                this.limitPerms = ['CREATE_COPY_STAT_CAT_ENTRY'];
+            } else {
+                this.limitPerms = ['UPDATE_COPY_STAT_CAT_ENTRY'];
+            }
+        } else {
+            if (mode === 'create') {
+                this.limitPerms = ['CREATE_PATRON_STAT_CAT_ENTRY'];
+            } else {
+                this.limitPerms = ['UPDATE_PATRON_STAT_CAT_ENTRY'];
+            }
+        }
+        console.debug('setLimitPerms',this.limitPerms);
+    }
+
     getParentData = (searchIdl) => {
         return this.pcrud.search(searchIdl, {id: this.statCatId}, {}
         ).subscribe(rec => {
             this.statCatOrg = rec.owner();
             this.statCatOrgId = rec.owner();
             this.checkPerms();
-            const allOrgIds = this.org.list().map(x => x.id());
-            const statCatDescendantIds = this.org.descendants(rec.owner(), true);
-            this.hiddenOrgs = allOrgIds.filter(org => {
-                return !statCatDescendantIds.includes(org);
-            });
             return rec;
         });
     }
@@ -160,6 +173,7 @@ export class StatCatEntriesComponent implements OnInit {
         this.defaultNewRecord.owner(this.statCatOrg);
         this.defaultNewRecord.stat_cat(this.statCatId);
         currentDialog.mode = 'create';
+        this.setLimitPerms('create');
         currentDialog.recordId = null;
         currentDialog.record = this.defaultNewRecord;
         currentDialog.open({size: 'lg'}).subscribe(
@@ -189,6 +203,7 @@ export class StatCatEntriesComponent implements OnInit {
         const currentDialog = lookupResponse.currentDialog;
         const currentGrid = lookupResponse.currentGrid;
         currentDialog.mode = 'update';
+        this.setLimitPerms('update');
         currentDialog.recordId = idlThing[0].id();
         currentDialog.open({size: 'lg'}).subscribe(
             id => {