[open-ils-commits] r19223 - in branches/rel_2_0/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:28:06 EST 2011
Author: erickson
Date: 2011-01-19 17:28:01 -0500 (Wed, 19 Jan 2011)
New Revision: 19223
Modified:
branches/rel_2_0/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js
branches/rel_2_0/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: branches/rel_2_0/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js
===================================================================
--- branches/rel_2_0/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js 2011-01-19 22:27:14 UTC (rev 19222)
+++ branches/rel_2_0/Open-ILS/web/js/dojo/openils/widget/FilteringTreeSelect.js 2011-01-19 22:28:01 UTC (rev 19223)
@@ -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: branches/rel_2_0/Open-ILS/web/js/ui/default/actor/user/register.js
===================================================================
--- branches/rel_2_0/Open-ILS/web/js/ui/default/actor/user/register.js 2011-01-19 22:27:14 UTC (rev 19222)
+++ branches/rel_2_0/Open-ILS/web/js/ui/default/actor/user/register.js 2011-01-19 22:28:01 UTC (rev 19223)
@@ -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);
@@ -148,7 +149,57 @@
}
}
+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');
@@ -613,12 +664,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';
@@ -631,6 +688,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