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;
}]);