From: Bill Erickson Date: Sun, 27 Oct 2013 14:04:09 +0000 (-0400) Subject: web staff : added egUser.hasPermAt() X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9d8ade4a89a2d91867d171fc55f40ba60c412209;p=evergreen%2Fequinox.git web staff : added egUser.hasPermAt() 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 ea7aae8ce1..61db10a191 100644 --- a/Open-ILS/web/js/ui/default/staff/services/user.js +++ b/Open-ILS/web/js/ui/default/staff/services/user.js @@ -10,8 +10,8 @@ angular.module('egUserMod', ['egCoreMod']) .factory('egUser', -['$q', '$timeout', 'egNet', 'egAuth', 'egUserCache', -function($q, $timeout, egNet, egAuth, egUserCache) { +['$q', '$timeout', 'egNet', 'egAuth', 'egUserCache', 'egOrg', +function($q, $timeout, egNet, egAuth, egUserCache, egOrg) { var service = {}; service.get = function(userId) { @@ -42,6 +42,42 @@ function($q, $timeout, egNet, egAuth, egUserCache) { return deferred.promise; }; + /* + * Returns the full list of org unit objects at which the currently + * logged in user has the selected permissions. + * @permList - list or string. If a list, the response object is a + * hash of perm => orgList maps. If a string, the response is only + * the final org list. + */ + service.hasPermAt = function(permList) { + var deferred = $q.defer(); + var isArray = true; + if (!angular.isArray(permList)) { + isArray = false; + permList = [permList]; + } + // as called, this method will return the top-most org unit of the + // sub-tree at which this user has the selected permission. + // From there, flesh the descendant orgs locally. + egNet.request( + 'open-ils.actor', + 'open-ils.actor.user.has_work_perm_at.batch', + egAuth.token(), permList + ).then(function(resp) { + var answer = {}; + angular.forEach(permList, function(perm) { + var all = []; + angular.forEach(resp[perm], function(oneOrg) { + all = all.concat(egOrg.descendants(oneOrg)); + }); + answer[perm] = all; + }); + if (!isArray) answer = answer[permList[0]]; + deferred.resolve(answer); + }); + return deferred.promise; + }; + return service; }]);