[open-ils-commits] r19221 - in trunk/Open-ILS/web/js: dojo/openils/widget ui/default/actor/user (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Jan 19 17:27:19 EST 2011


Author: erickson
Date: 2011-01-19 17:27:14 -0500 (Wed, 19 Jan 2011)
New Revision: 19221

Modified:
   trunk/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js
   trunk/Open-ILS/web/js/ui/default/actor/user/register.js
Log:
remove disallowed permission groups from the perm group selector in user registration; see bug 699914

Modified: trunk/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js	2011-01-19 22:05:53 UTC (rev 19220)
+++ trunk/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js	2011-01-19 22:27:14 UTC (rev 19221)
@@ -42,7 +42,7 @@
                 if(this.dataList.length > 0) {
                     var storeData = fieldmapper[this.className].initStoreData();
                     storeData.items = this.dataList;
-                    this.store = new dojo.data.ItemFileReadStore({data:storeData});
+                    this.store = new dojo.data.ItemFileWriteStore({data:storeData});
                 }
                 this.inherited(arguments);
 

Modified: trunk/Open-ILS/web/js/ui/default/actor/user/register.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/actor/user/register.js	2011-01-19 22:05:53 UTC (rev 19220)
+++ trunk/Open-ILS/web/js/ui/default/actor/user/register.js	2011-01-19 22:27:14 UTC (rev 19221)
@@ -126,6 +126,7 @@
     surveyTemplate = tbody.removeChild(dojo.byId('survey-row-template'));
     surveyQuestionTemplate = tbody.removeChild(dojo.byId('survey-question-row-template'));
 
+    checkGrpAppPerm(); // to do the initial load
     loadStaticFields();
     if(patron.isnew() && patron.addresses().length == 0) 
         uEditNewAddr(null, uEditAddrVirtId, true);
@@ -150,7 +151,57 @@
     lock_ready = true;
 }
 
+var permGroups;
+var noPermGroups = [];
+// Returns true if the user is allowed to edit the selected group
+function checkGrpAppPerm(grpId) {
 
+    if(!permGroups) {
+
+        // get the groups
+        permGroups = new openils.PermaCrud().retrieveAll('pgt');
+        var permGroupPerms = []
+
+        // collect the group permissions
+        dojo.forEach(permGroups, 
+            function(grp) {
+                if(grp.application_perm())
+                    permGroupPerms.push(grp.application_perm());
+            }
+        );
+
+        // see which of the group application perms I do not have
+        var myPerms = fieldmapper.standardRequest(
+            ['open-ils.actor', 'open-ils.actor.user.has_work_perm_at.batch'],
+            [openils.User.authtoken, permGroupPerms]
+        );
+
+        var failedPerms = [];
+        for(var p in myPerms) { 
+            if(myPerms[p].length == 0) 
+                failedPerms.push(p); 
+        }
+
+        // identify which groups I cannot edit because I do not have permisssion
+
+        function checkTree(grp, failed) {
+            failed = failed || failedPerms.indexOf(grp.application_perm()) > -1;
+            if(failed) noPermGroups.push(grp.id()+'');
+            dojo.forEach(
+                permGroups.filter(function(g) { return g.parent() == grp.id() } ),
+                function(child) {
+                    checkTree(child, failed);
+                }
+            );
+        }
+
+        checkTree(permGroups.filter(function(g) { return g.parent() == null })[0]);
+    }
+
+    return noPermGroups.indexOf(grpId+'') == -1;
+}
+
+
 function drawAllCards() {
 
     var tbody = dojo.byId('uedit-all-cards-tbody');
@@ -615,12 +666,18 @@
         // not overwritten when the profile groups arrive and update
         wargs.forceSync = true;
         wargs.disableQuery = {usergroup : 'f'};
+        if(!patron.isnew() && !checkGrpAppPerm(patron.profile()))
+            wargs.readOnly = true;
     } else {
         wargs.forceSync = false;
     }
 
     var widget = new openils.widget.AutoFieldWidget(wargs);
-    widget.build();
+    widget.build(
+        function(w, ww) {
+            if(fmfield == 'profile') { trimGrpTree(ww); }
+        }
+    );
 
     // now put it back before we register the widget
     if(isPasswd2) fmfield = 'passwd2';
@@ -633,6 +690,19 @@
     return widget;
 }
 
+function trimGrpTree(autoWidget) {
+    var store = autoWidget.widget.store;
+    if(!store) return;
+    // remove all groups that this user are not allowed to edit, 
+    // except the profile group of an existing user
+    store.fetch({onItem : 
+        function(item) {
+            if(!checkGrpAppPerm(item.id[0]) && patron.profile() != item.id[0])
+                store.deleteItem(item);
+        }
+    });
+}
+
 function findWidget(wtype, fmfield, callback) {
     return widgetPile.filter(
         function(i){



More information about the open-ils-commits mailing list