New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cr-acl

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cr-acl - npm Package Compare versions

Comparing version 0.5.2 to 0.5.3

112

cr-acl.js

@@ -5,4 +5,4 @@ angular.module('cr.acl', [])

'roles': {
'ROLE_USER': ['ROLE_USER'],
'ROLE_GUEST': ['ROLE_GUEST']
'ROLE_GUEST': [],
'ROLE_USER': ['ROLE_GUEST']
}

@@ -15,28 +15,2 @@ })

/**
* Your role is granted for this route?
* @param string identityRole
* @param array sstateRolesGranted
* @return bool
*/
self.isGranted = function (identityRole, stateRolesGranted) {
var granted = false;
if ((identityRole in self.roles) === false) {
throw 'This role[' + identityRole + '] not exist into InheritanceRoles declaration';
}
if (stateRolesGranted.indexOf(identityRole) !== -1) {
granted = true;
}
for (var ii in self.roles[identityRole]) {
if (stateRolesGranted.indexOf(self.roles[identityRole][ii]) !== -1) {
granted = true;
}
}
return granted;
};
this.$get = ['$q', '$rootScope', '$injector', function ($q, $rootScope, $injector) {

@@ -47,7 +21,7 @@ var crAcl = {};

* Configure roles tree
* @param arrat roles
* @param {array} roles
*/
crAcl.setInheritanceRoles = function (roles) {
angular.forEach(roles, function (inheritance, roleName) {
if (roleName == 'ROLE_USER' && roleName == 'ROLE_GUEST') {
if (roleName === 'ROLE_USER' && roleName === 'ROLE_GUEST') {
throw roleName + ' is a reserved world because is a father of ROLE, you can not override it';

@@ -68,3 +42,3 @@ }

* Set Role
* @param string role
* @param {string} role
*/

@@ -77,3 +51,2 @@ crAcl.setRole = function (role) {

* Get all Roles
* @param array
*/

@@ -95,2 +68,32 @@ crAcl.getRoles = function () {

/**
* Your role is granted for this route?
* @param {string} identityRole
* @param {array} stateRolesGranted
* @return bool
*/
crAcl.isGranted = function (identityRole, stateRolesGranted) {
var isRoleGranted = function (theRole, grantedRoles) {
// Check if current role is one of the directly allowed roles
if (grantedRoles.indexOf(theRole) !== -1) {
return true;
}
// Recursively check inherited roles
for (var i in self.roles[theRole]) {
if (isRoleGranted(self.roles[theRole][i], grantedRoles)) {
return true;
}
}
return false;
};
if ((identityRole in self.roles) === false) {
throw 'This role[' + identityRole + '] not exist into InheritanceRoles declaration';
}
return isRoleGranted(identityRole, stateRolesGranted);
};
var afterChangeStart = function (event, toState, toParams, fromState, fromParams) {

@@ -104,4 +107,3 @@ if (!toState.data || !toState.data.is_granted) {

var is_allowed = (toState.data.is_granted !== undefined) ? toState.data.is_granted : ['ROLE_GUEST'];
var isGranted = self.isGranted(crAcl.getRole(), is_allowed);
return isGranted;
return crAcl.isGranted(crAcl.getRole(), is_allowed);
};

@@ -115,3 +117,3 @@

event.preventDefault();
if (self.redirect != toState.name) {
if (self.redirect !== toState.name) {
$state.go(self.redirect);

@@ -129,3 +131,3 @@ }

event.preventDefault();
if (self.redirect != toState.name) {
if (self.redirect !== toState.name) {
$location.path(self.redirect);

@@ -144,13 +146,8 @@ }

restrict: 'A',
replace: false,
transclude: 'element',
transclude: true,
terminal: true,
link: function (scope, elem, attr, ctrl, $transclude) {
var content = false;
$transclude(function (clone, newScope) {
childScope = newScope;
$transclude(function (clone) {
clone[clone.length++] = document.createComment(' end crGranted: ' + attr.crGranted + ' ');
block = {
clone: clone
};
content = clone;

@@ -161,10 +158,7 @@ });

return acl.getRole();
}, function (newV, oldV) {
}, function () {
if (shouldBeShown()) {
$animate.enter(content, elem.parent(), elem);
} else {
if (content) {
content.remove();
}
} else if (content) {
content.remove();
}

@@ -174,20 +168,6 @@ });

var shouldBeShown = function () {
var allowedRoles = attr.crGranted.split(',');
var roles = acl.getRoles();
var currentRole = acl.getRole();
if (allowedRoles.indexOf(currentRole) != -1) {
return true;
} else {
var granted = false;
angular.forEach(allowedRoles, function (role) {
if (angular.isDefined(roles[currentRole])) {
var inheritedRoles = roles[currentRole];
if (inheritedRoles.indexOf(role) > -1) {
granted = true;
}
}
});
var allowedRoles = attr.crGranted.split(','),
currentRole = acl.getRole();
return granted;
}
return acl.isGranted(currentRole, allowedRoles);
};

@@ -194,0 +174,0 @@ }

{
"name": "cr-acl",
"version": "0.5.2",
"version": "0.5.3",
"dependencies": {

@@ -5,0 +5,0 @@ "angular": "^1.5",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc