Initial commit

This commit is contained in:
Isaac Parenteau committed 2018-07-07 20:43:51 -05:00
commit 880e39de2e
511 files changed
+38363

No files matched your search

@@ -0,0 +1,40 @@
angular.module('portal').factory('permissions', permissionFactory);
function permissionFactory($rootScope, $state, portalUtils, $q, cache, accountStores, Triggers) {
Triggers.listen([Triggers.PERMISSIONS_CHANGED], function(trigger, payload){
new accountStores.Account().refresh();
$rootScope.$broadcast('permissionsChanged');
});
var permissions = {
canView: function (attrs) {
var deferred = $q.defer();
//Nothing defined (always true)
if (angular.isDefined(attrs) === false) {
deferred.resolve(true);
} else {
var mCache = cache.request([new accountStores.Account()]).then(function () {
var validRole = verifyRole(mCache, attrs);
deferred.resolve(validRole);
});
}
return deferred.promise;
}
};
/**
* Check that the user is one of the passed in roles
* @param {type} attrs attributes to check against
* @returns {Boolean}
*/
function verifyRole(mCache, attrs) {
var show = true;
if (angular.isDefined(attrs.permission)) {
show = mCache.account.data.hasPermission(attrs.permission);
}
return show;
}
return permissions;
}