From: Bill Erickson Date: Thu, 24 Apr 2014 15:55:30 +0000 (-0400) Subject: browser staff : egUser.hasPermHere() X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=fa05c0409ed41a0d1acca71f815ce165edaf898b;p=working%2FEvergreen.git browser staff : egUser.hasPermHere() Signed-off-by: Bill Erickson --- 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; }]);