tensult/role-acl

View on GitHub

Showing 54 of 54 total issues

Similar blocks of code found in 3 locations. Consider refactoring.
Open

export class NotCondition implements IConditionFunction {

    evaluate(args?: any, context?: any): boolean | Promise<boolean> {
        if (!args) {
            return true;
Severity: Major
Found in src/conditions/NotCondition.ts and 2 other locations - About 1 day to fix
src/conditions/AndCondition.ts on lines 11..36
src/conditions/OrCondition.ts on lines 12..37

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 219.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 3 locations. Consider refactoring.
Open

export class OrCondition implements IConditionFunction {

    evaluate(args?: any, context?: any): boolean | Promise<boolean> {
        if (!args) {
            return true;
Severity: Major
Found in src/conditions/OrCondition.ts and 2 other locations - About 1 day to fix
src/conditions/AndCondition.ts on lines 11..36
src/conditions/NotCondition.ts on lines 13..39

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 219.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 3 locations. Consider refactoring.
Open

export class AndCondition implements IConditionFunction {

     evaluate(args?: any, context?: any):boolean | Promise<boolean> {
        if (!args) {
            return true;
Severity: Major
Found in src/conditions/AndCondition.ts and 2 other locations - About 1 day to fix
src/conditions/NotCondition.ts on lines 13..39
src/conditions/OrCondition.ts on lines 12..37

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 219.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

                return roles.filter((role) => {
                    return grants[role] && grants[role].grants;
                }).map((role) => {
                    return grants[role].grants;
                }).reduce((allGrants, roleGrants) => {
        Severity: Major
        Found in src/utils/common.ts and 1 other location - About 2 hrs to fix
        src/utils/common.ts on lines 282..288

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 92.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

                return roles.filter((role) => {
                    return grants[role] && grants[role].grants;
                }).map((role) => {
                    return grants[role].grants;
                }).reduce((allGrants, roleGrants) => {
        Severity: Major
        Found in src/utils/common.ts and 1 other location - About 2 hrs to fix
        src/utils/common.ts on lines 260..266

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 92.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        AccessControl.isAllowed = function (account, user, resource, action, context) {
            const acl = new AccessControl(account.acl);
            const permission = acl.permission({
                resource,
                action,
        Severity: Major
        Found in app.js and 1 other location - About 2 hrs to fix
        app.js on lines 15..24

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 87.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        AccessControl.getAllowedAttributes = function (account, user, resource, action, context) {
            const acl = new AccessControl(account.acl);
            const permission = acl.permission({
                resource,
                action,
        Severity: Major
        Found in app.js and 1 other location - About 2 hrs to fix
        app.js on lines 4..13

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 87.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        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

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

                return (await this.filterGrantsAllowing(matchingGrants, query))
                    .map((grant) => {
                        return ArrayUtil.toStringArray(grant.attributes);
                    }).reduce(Notation.Glob.union, []);
        Severity: Major
        Found in src/utils/common.ts and 2 other locations - About 1 hr to fix
        src/utils/common.ts on lines 296..299
        src/utils/common.ts on lines 322..325

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 61.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

                return (await this.filterGrantsAllowing(matchingGrants, query))
                    .map((grant) => {
                        return ArrayUtil.toStringArray(grant.resource);
                    }).reduce(Notation.Glob.union, []);
        Severity: Major
        Found in src/utils/common.ts and 2 other locations - About 1 hr to fix
        src/utils/common.ts on lines 322..325
        src/utils/common.ts on lines 360..363

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 61.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

                return (await this.filterGrantsAllowing(matchingGrants, query))
                    .map((grant) => {
                        return ArrayUtil.toStringArray(grant.action);
                    }).reduce(Notation.Glob.union, []);
        Severity: Major
        Found in src/utils/common.ts and 2 other locations - About 1 hr to fix
        src/utils/common.ts on lines 296..299
        src/utils/common.ts on lines 360..363

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 61.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        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

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

                  return (this.filterGrantsAllowingSync(matchingGrants, query))
                      .map((grant) => {
                          return ArrayUtil.toStringArray(grant.resource);
                      }).reduce(Notation.Glob.union, []);
          Severity: Major
          Found in src/utils/common.ts and 2 other locations - About 1 hr to fix
          src/utils/common.ts on lines 336..339
          src/utils/common.ts on lines 373..376

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 59.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

                  return (this.filterGrantsAllowingSync(matchingGrants, query))
                      .map((grant) => {
                          return ArrayUtil.toStringArray(grant.attributes);
                      }).reduce(Notation.Glob.union, []);
          Severity: Major
          Found in src/utils/common.ts and 2 other locations - About 1 hr to fix
          src/utils/common.ts on lines 307..310
          src/utils/common.ts on lines 336..339

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 59.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Severity
          Category
          Status
          Source
          Language