src/index.js
function getRuleType(resource, role, privilege) {
        resource = typeof resource === 'undefined' ? null : resource;
        role = typeof role === 'undefined' ? null : role;
        privilege = typeof privilege === 'undefined' ? null : privilege;


        // get the rules for the $resource and $role
        var rules = getRules(resource, role), rule;
        if (rules === null) {
            return null;
        }

        // follow $privilege
        if (privilege === null) {
            if (rules.allPrivileges !== undefined) {
                rule = rules.allPrivileges;
            } else {
                return null;
            }
        } else if (rules.byPrivilegeId === undefined || rules.byPrivilegeId[privilege] === undefined) {
            return null;
        } else {
            rule = rules.byPrivilegeId[privilege];
        }

        // check assertion first
        var assertionValue = null;
        if (rule.assert !== null) {
            var assertion = rule.assert;
            assertionValue = assertion.call(
                self,
                _isAllowedRole === self.USER_IDENTITY_ROLE && self.getUserIdentity() !== null ? self.getUserIdentity() : role,
                _isAllowedResource !== null ? _isAllowedResource : resource,
                privilege
            );
        }

        if (rule.assert === null || assertionValue === true) {
            return rule.type;
        } else if (null !== resource || null !== role || null !== privilege) {
            return null;
        } else if (self.TYPE_ALLOW === rule.type) {
            return self.TYPE_DENY;
        }

        return self.TYPE_ALLOW;
    }
function getRuleType(resource, role, privilege) {
        resource = typeof resource === 'undefined' ? null : resource;
        role = typeof role === 'undefined' ? null : role;
        privilege = typeof privilege === 'undefined' ? null : privilege;


        // get the rules for the $resource and $role
        var rules = getRules(resource, role), rule;
        if (rules === null) {
            return null;
        }

        // follow $privilege
        if (privilege === null) {
            if (rules.allPrivileges !== undefined) {
                rule = rules.allPrivileges;
            } else {
                return null;
            }
        } else if (rules.byPrivilegeId === undefined || rules.byPrivilegeId[privilege] === undefined) {
            return null;
        } else {
            rule = rules.byPrivilegeId[privilege];
        }

        // check assertion first
        var assertionValue = null;
        if (rule.assert !== null) {
            var assertion = rule.assert;
            assertionValue = assertion.call(
                self,
                _isAllowedRole === self.USER_IDENTITY_ROLE && self.getUserIdentity() !== null ? self.getUserIdentity() : role,
                _isAllowedResource !== null ? _isAllowedResource : resource,
                privilege
            );
        }

        if (rule.assert === null || assertionValue === true) {
            return rule.type;
        } else if (null !== resource || null !== role || null !== privilege) {
            return null;
        } else if (self.TYPE_ALLOW === rule.type) {
            return self.TYPE_DENY;
        }

        return self.TYPE_ALLOW;
    }
function getRuleType ( resource , role , privilege ) { resource = typeof resource === 'undefined' ? null : resource ; role = typeof role === 'undefined' ? null : role ; privilege = typeof privilege === 'undefined' ? null : privilege ; // get the rules for the $resource and $role var rules = getRules ( resource , role ) , rule ; if ( rules === null ) { return null ; } // follow $privilege if ( privilege === null ) { if ( rules . allPrivileges !== undefined ) { rule = rules . allPrivileges ; } else { return null ; } } else if ( rules . byPrivilegeId === undefined || rules . byPrivilegeId [ privilege ] === undefined ) { return null ; } else { rule = rules . byPrivilegeId [ privilege ] ; } // check assertion first var assertionValue = null ; if ( rule . assert !== null ) { var assertion = rule . assert ; assertionValue = assertion . call ( self , _isAllowedRole === self . USER_IDENTITY_ROLE && self . getUserIdentity ( ) !== null ? self . getUserIdentity ( ) : role , _isAllowedResource !== null ? _isAllowedResource : resource , privilege ) ; } if ( rule . assert === null || assertionValue === true ) { return rule . type ; } else if ( null !== resource || null !== role || null !== privilege ) { return null ; } else if ( self . TYPE_ALLOW === rule . type ) { return self . TYPE_DENY ; } return self . TYPE_ALLOW ; }
Returns the rule type associated with the specified Resource, Role, and privilege
combination.

If a rule does not exist or its attached assertion fails, which means that
the rule is not applicable, then this method returns null. Otherwise, the
rule type applies and is returned as either TYPE_ALLOW or TYPE_DENY.

If $resource or $role is null, then this means that the rule must apply to
all Resources or Roles, respectively.

If $privilege is null, then the rule must apply to all privileges.

If all three parameters are null, then the default ACL rule type is returned,
based on whether its assertion method passes.

@param  {null|string} [resource=null]
@param  {null|string} [role=null]
@param  {null|string} [privilege=null]
@return {(string|null)}
Returns the rule type associated with the specified Resource Role and privilege combination .