-
Notifications
You must be signed in to change notification settings - Fork 212
/
angular-permission.min.js
12 lines (10 loc) · 9.02 KB
/
angular-permission.min.js
1
2
3
4
5
6
7
8
9
10
11
12
/**
* angular-permission
* Fully featured role and permission based access control for your angular applications
* @version v6.0.0 - 2018-01-20
* @link https://github.com/Narzerus/angular-permission
* @author Rafael Vidaurre <[email protected]> (http://www.rafaelvidaurre.com), Blazej Krysiak <[email protected]>
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
!function(a,angular,b){"use strict";function c(){"ngInject";var a="showElement",b="hideElement",c=!1;this.setDefaultOnAuthorizedMethod=function(b){a=b},this.setDefaultOnUnauthorizedMethod=function(a){b=a},this.suppressUndefinedPermissionWarning=function(a){c=a},this.$get=function(){return{defaultOnAuthorizedMethod:a,defaultOnUnauthorizedMethod:b,suppressUndefinedPermissionWarning:c}}}function d(a){"ngInject";function b(b){var c=a.defer(),d=0,e=angular.isArray(b)?[]:{};return angular.forEach(b,function(b,f){d++,a.when(b).then(function(a){c.resolve(a)}).catch(function(a){e[f]=a,--d||c.reject(a)})}),0===d&&c.reject(e),c.promise}return a.any=b,a}function e(){"ngInject";this.broadcastPermissionStartEvent=function(){throw new Error("Method broadcastPermissionStartEvent in PermTransitionEvents interface must be implemented")},this.broadcastPermissionAcceptedEvent=function(){throw new Error("Method broadcastPermissionAcceptedEvent in PermTransitionEvents interface must be implemented")},this.broadcastPermissionDeniedEvent=function(){throw new Error("Method broadcastPermissionDeniedEvent in PermTransitionEvents interface must be implemented")}}function f(a,b,c){"ngInject";function d(a,b){f(a,b),this.permissionName=a,this.validationFunction=g(b)}function e(b,c){return b?a.resolve(c):a.reject(c)}function f(a,b){if(!angular.isString(a))throw new TypeError('Parameter "permissionName" name must be String');if(!angular.isFunction(b)&&!angular.isArray(b))throw new TypeError('Parameter "validationFunction" must be Function or an injectable Function using explicit annotation')}function g(a){return angular.isArray(a.$inject||a)||(a=["permissionName","transitionProperties",a]),a}return d.prototype.validatePermission=function(){var a={permissionName:this.permissionName,transitionProperties:c},d=b.invoke(this.validationFunction,null,a);return angular.isFunction(d.then)||(d=e(d,this.permissionName)),d},d}function g(a,b,c,d){"ngInject";function e(a,b){g(a,b),this.roleName=a,this.validationFunction=h(b)}function f(b,c){return b?a.resolve(c):a.reject(c)}function g(a,b){if(!angular.isString(a))throw new TypeError('Parameter "roleName" name must be String');if(!angular.isArray(b)&&!angular.isFunction(b))throw new TypeError('Parameter "validationFunction" must be array or function')}function h(a){return angular.isArray(a)&&!angular.isFunction(a[a.length-1])?a=i(a):angular.isArray(a.$inject||a)||(a=["roleName","transitionProperties",a]),a}function i(b){return function(){var d=b.map(function(b){if(c.hasPermissionDefinition(b)){var d=c.getPermissionDefinition(b);return d.validatePermission()}return a.reject(b)});return a.all(d)}}return e.prototype.validateRole=function(){var a={roleName:this.roleName,transitionProperties:d},c=b.invoke(this.validationFunction,null,a);return angular.isFunction(c.then)||(c=f(c,this.roleName)),c},e}function h(a){"ngInject";function b(b,c){i[b]=new a(b,c)}function c(a,c){if(!angular.isArray(a))throw new TypeError('Parameter "permissionNames" name must be Array');angular.forEach(a,function(a){b(a,c)})}function d(a){delete i[a]}function e(a){return angular.isDefined(i[a])}function f(a){return i[a]}function g(){return i}function h(){i={}}var i={};this.definePermission=b,this.defineManyPermissions=c,this.removePermissionDefinition=d,this.hasPermissionDefinition=e,this.getPermissionDefinition=f,this.getStore=g,this.clearStore=h}function i(a){"ngInject";function b(b,c){i[b]=new a(b,c)}function c(a){if(!angular.isObject(a))throw new TypeError('Parameter "roleNames" name must be object');angular.forEach(a,function(a,c){b(c,a)})}function d(a){delete i[a]}function e(a){return angular.isDefined(i[a])}function f(a){return i[a]}function g(){return i}function h(){i={}}var i={};this.defineRole=b,this.defineManyRoles=c,this.getRoleDefinition=f,this.hasRoleDefinition=e,this.removeRoleDefinition=d,this.getStore=g,this.clearStore=h}function j(a,b,c,d){"ngInject";return{restrict:"A",bindToController:{sref:"=?permissionSref",only:"=?permissionOnly",except:"=?permissionExcept",onAuthorized:"&?permissionOnAuthorized",onUnauthorized:"&?permissionOnUnauthorized"},controllerAs:"permission",controller:["$scope","$element","$permission",function(e,f,g){function h(){return b.has("$state")&&k.sref}function i(){if(angular.isFunction(k.onAuthorized))k.onAuthorized()(f);else{var a=g.defaultOnAuthorizedMethod;d[a](f)}}function j(){if(angular.isFunction(k.onUnauthorized))k.onUnauthorized()(f);else{var a=g.defaultOnUnauthorizedMethod;d[a](f)}}var k=this;e.$watchGroup(["permission.only","permission.except","sref"],function(){try{if(h()){var d=b.get("PermStateAuthorization");d.authorizeByStateName(k.sref).then(function(){i()}).catch(function(){j()})}else{var e=b.get("PermAuthorization"),f=new c({only:k.only,except:k.except});e.authorizeByPermissionMap(f).then(function(){i()}).catch(function(){j()})}}catch(b){j(),a.error(b.message)}})}]}}function k(a){"ngInject";function b(b){var d=a.defer();return c(d,b),d.promise}function c(b,c){var e=c.resolvePropertyValidity(c.except);a.any(e).then(function(a){b.reject(a)}).catch(function(){d(b,c)})}function d(b,c){if(!c.only.length)return void b.resolve();var d=c.resolvePropertyValidity(c.only);a.any(d).then(function(a){b.resolve(a)}).catch(function(a){b.reject(a)})}this.authorizeByPermissionMap=b}function l(a,b,c,d,e,f,g){"ngInject";function h(a){a=a||{},this.only=j(a.only),this.except=j(a.except),this.redirectTo=k(a.redirectTo)}function i(b,d){return a.when(c.invoke(b,null,{rejectedPermission:d,transitionProperties:e})).then(function(b){return angular.isString(b)?{state:b}:angular.isObject(b)?b:a.reject()})}function j(a){return angular.isString(a)?[a]:angular.isArray(a)?a:angular.isFunction(a)?a.call(null,e):[]}function k(a){if(angular.isDefined(a)){if(p(a)||angular.isFunction(a))return q(a);if(angular.isObject(a))return m(a)?n(a):o(a);if(angular.isString(a))return l(a);throw new ReferenceError('Property "redirectTo" must be String, Function, Array or Object')}}function l(a){var b={};return b.default=function(){return{state:a}},b.default.$inject=["rejectedPermission","transitionProperties"],b}function m(a){return angular.isDefined(a.state)}function n(a){var b={};return b.default=function(){return a},b}function o(a){var b={};return angular.forEach(a,function(a,c){p(a)?b[c]=a:angular.isFunction(a)&&(b[c]=a,b[c].$inject=[]),angular.isObject(a)&&(b[c]=function(){return a},b[c].$inject=[]),angular.isString(a)&&(b[c]=function(){return{state:a}},b[c].$inject=[])}),b}function p(a){return angular.isArray(a)||angular.isFunction(a)&&angular.isArray(a.$inject)}function q(a){var b={};return b.default=a,angular.isDefined(a.$inject)||(b.default.$inject=["rejectedPermission","transitionProperties"]),b}return h.prototype.resolveRedirectState=function(b){if(!angular.isDefined(this.redirectTo))return a.reject();var c=this.redirectTo[b]||this.redirectTo.default;return i(c,b)},h.prototype.resolvePropertyValidity=function(c){return c.map(function(c){if(f.hasRoleDefinition(c)){var e=f.getRoleDefinition(c);return e.validateRole()}if(g.hasPermissionDefinition(c)){var h=g.getPermissionDefinition(c);return h.validatePermission()}return d.suppressUndefinedPermissionWarning||b.warn("Permission or role "+c+" was not defined."),a.reject(c)})},h}d.$inject=["$delegate"],f.$inject=["$q","$injector","PermTransitionProperties"],g.$inject=["$q","$injector","PermPermissionStore","PermTransitionProperties"],h.$inject=["PermPermission"],i.$inject=["PermRole"],j.$inject=["$log","$injector","PermPermissionMap","PermPermissionStrategies"],k.$inject=["$q"],l.$inject=["$q","$log","$injector","$permission","PermTransitionProperties","PermRoleStore","PermPermissionStore"];var m=angular.module("permission",[]);"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports=m.name),angular.module("permission").provider("$permission",c),angular.module("permission").decorator("$q",d);var n={enableElement:function(a){a.removeAttr("disabled")},disableElement:function(a){a.attr("disabled","disabled")},showElement:function(a){a.removeClass("ng-hide")},hideElement:function(a){a.addClass("ng-hide")}};angular.module("permission").value("PermPermissionStrategies",n).value("PermissionStrategies",n);var o={};angular.module("permission").value("PermTransitionProperties",o),angular.module("permission").service("PermTransitionEvents",e),angular.module("permission").factory("PermPermission",f),angular.module("permission").factory("PermRole",g),angular.module("permission").service("PermPermissionStore",h),angular.module("permission").service("PermRoleStore",i),angular.module("permission").directive("permission",j),angular.module("permission").service("PermAuthorization",k),angular.module("permission").factory("PermPermissionMap",l)}(window,window.angular);
//# sourceMappingURL=angular-permission.min.js.map