tensult/role-acl

View on GitHub

Showing 23 of 54 total issues

File common.ts has 451 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import Notation from 'notation';
import Matcher from 'matcher';
import { ArrayUtil } from './array';
import { ConditionUtil } from '../conditions';
import { AccessControlError, IQueryInfo, IAccessInfo, ICondition } from '../core';
Severity: Minor
Found in src/utils/common.ts - About 6 hrs to fix

    CommonUtil has 43 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class CommonUtil {
    
        public static isStringOrArray(value: any): boolean {
            return typeof value === 'string' || ArrayUtil.isFilledStringArray(value);
        }
    Severity: Minor
    Found in src/utils/common.ts - About 5 hrs to fix

      AccessControl has 31 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class AccessControl {
        /**
         *  @private
         */
        private _grants: any;
      Severity: Minor
      Found in src/AccessControl.ts - About 3 hrs to fix

        Function getFlatRolesSync has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

            public static getFlatRolesSync(grants: any, roles: string | string[], context?: any, skipConditions?: boolean): string[] {
                roles = ArrayUtil.toStringArray(roles);
                if (!roles) throw new AccessControlError(`Invalid role(s): ${JSON.stringify(roles)}`);
                let arr: string[] = roles.slice();
                for (let roleName of roles) {
        Severity: Minor
        Found in src/utils/common.ts - About 2 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function getFlatRoles has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

            public static async getFlatRoles(grants: any, roles: string | string[], context?: any, skipConditions?: boolean): Promise<string[]> {
                roles = ArrayUtil.toStringArray(roles);
                if (!roles) throw new AccessControlError(`Invalid role(s): ${JSON.stringify(roles)}`);
                let arr: string[] = roles.slice();
                for (let roleName of roles) {
        Severity: Minor
        Found in src/utils/common.ts - About 2 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function evaluate has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

          public static evaluate(
            condition: ICondition,
            context: any
          ): boolean | Promise<boolean> {
            if (!condition) {
        Severity: Minor
        Found in src/conditions/util.ts - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function filterGrantsAllowingSync has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            public static filterGrantsAllowingSync(grants: IAccessInfo[], query: IQueryInfo): IAccessInfo[] {
                if (query.skipConditions) {
                    return grants;
                } else {
                    const matchingGrants = [];
        Severity: Minor
        Found in src/utils/common.ts - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function evaluate has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          public static evaluate(
            condition: ICondition,
            context: any
          ): boolean | Promise<boolean> {
            if (!condition) {
        Severity: Minor
        Found in src/conditions/util.ts - About 1 hr to fix

          Function validateCondition has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

            public static validateCondition(condition) {
              if (!condition) {
                return;
              }
          
          
          Severity: Minor
          Found in src/conditions/util.ts - About 55 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Avoid deeply nested control flow statements.
          Open

                                  if (typeof (conditionResult) !== 'boolean') {
                                      throw new AccessControlError(`Expected the condition function should return boolean, but returning ${conditionResult}`);
                                  } else if (conditionResult === true) {
                                      rolesMetCondition.push(extendedRoleName);
                                  }
          Severity: Major
          Found in src/utils/common.ts - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if (await ConditionUtil.evaluate(roleItem.$extend[extendedRoleName].condition,
                                        context)) {
                                        rolesMetCondition.push(extendedRoleName);
                                    }
            Severity: Major
            Found in src/utils/common.ts - About 45 mins to fix

              Function isAllowed has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              AccessControl.isAllowed = function (account, user, resource, action, context) {
              Severity: Minor
              Found in app.js - About 35 mins to fix

                Function getAllowedAttributes has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                AccessControl.getAllowedAttributes = function (account, user, resource, action, context) {
                Severity: Minor
                Found in app.js - About 35 mins to fix

                  Function normalizeQueryInfo has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public static normalizeQueryInfo(query: IQueryInfo): IQueryInfo {
                          // clone the object
                          const newQuery: IQueryInfo = this.clone(query);
                          // validate and normalize role(s)
                          newQuery.role = ArrayUtil.toStringArray(newQuery.role);
                  Severity: Minor
                  Found in src/utils/common.ts - About 35 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Function filterGrantsAllowing has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public static async filterGrantsAllowing(grants: IAccessInfo[], query: IQueryInfo): Promise<IAccessInfo[]> {
                          if (query.skipConditions) {
                              return grants;
                          } else {
                              const matchingGrants = [];
                  Severity: Minor
                  Found in src/utils/common.ts - About 35 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Avoid too many return statements within this function.
                  Open

                            return ConditionUtil._customConditionFunctions[condition.Fn](context, condition.args);
                  Severity: Major
                  Found in src/conditions/util.ts - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                        return false;
                    Severity: Major
                    Found in src/conditions/util.ts - About 30 mins to fix

                      Function evaluate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                          evaluate(args?: any, context?: any): boolean | Promise<boolean> {
                              if (!args) {
                                  return true;
                              }
                      
                      
                      Severity: Minor
                      Found in src/conditions/OrCondition.ts - About 25 mins to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Function evaluate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                          evaluate(args?: any, context?: any): boolean | Promise<boolean> {
                              if (!args) {
                                  return true;
                              }
                      
                      
                      Severity: Minor
                      Found in src/conditions/NotCondition.ts - About 25 mins to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Function areExtendingRolesAllowingSync has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public static areExtendingRolesAllowingSync(roleExtensionObject: any, allowingRoles: any, query: IQueryInfo): boolean {
                              if (!roleExtensionObject) {
                                  return false;
                              }
                              let result = false;
                      Severity: Minor
                      Found in src/utils/common.ts - About 25 mins to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Severity
                      Category
                      Status
                      Source
                      Language