From fa05c0409ed41a0d1acca71f815ce165edaf898b Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 24 Apr 2014 11:55:30 -0400 Subject: [PATCH] browser staff : egUser.hasPermHere() Signed-off-by: Bill Erickson --- Open-ILS/web/js/ui/default/staff/services/user.js | 47 +++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/Open-ILS/web/js/ui/default/staff/services/user.js b/Open-ILS/web/js/ui/default/staff/services/user.js index 515b81c3fb..bb10e76961 100644 --- a/Open-ILS/web/js/ui/default/staff/services/user.js +++ b/Open-ILS/web/js/ui/default/staff/services/user.js @@ -88,6 +88,53 @@ function($q, $timeout, egNet, egAuth, egOrg) { return deferred.promise; }; + /** + * Returns a hash of perm => hasPermBool for each requested permission. + * If the authenticated user has no workstation, no checks are made + * and all permissions return false. + */ + service.hasPermHere = function(permList) { + var response = {}; + + var isArray = true; + if (!angular.isArray(permList)) { + isArray = false; + permList = [permList]; + } + + // no workstation, all are false + if (egAuth.user().wsid() === null) { + console.warn("egUser.hasPermHere() called with no workstation"); + if (isArray) { + response = permList.map(function(perm) { + return response[perm] = false; + }); + } else { + response = false; + } + return $q.when(response); + } + + ws_ou = egAuth.user().ws_ou(); + + return service.hasPermAt(permList) + .then(function(orgMap) { + angular.forEach(orgMap, function(orgs, perm) { + // each permission is mapped to a flat list of org units, + // including descendants. See if our workstation org unit + // is in the list. + angular.forEach(orgs, function(org) { + if ((''+org.id()) == (''+ws_ou)) + response[perm] = true; + }); + if (response[perm] !== true) + response[perm] = false; + }); + if (!isArray) response = response[permList[0]]; + return response; + }); + } + return service; }]); -- 2.11.0