Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Conversation

loban
Copy link

@loban loban commented Oct 10, 2019

  • When checking for granted resources, actions, or attributes, the current code
    executes all conditions for all grants, and then filters the passed ones
    by action and/or resource in the query.
  • This is inefficient, especially if the condition checks are expensive, e.g.
    if they make database calls.
  • I've optimized it by first filtering out grants based on the action and
    resource in the query, and then running the condition checks on the remaining.

- When checking for granted resources, actions, or attributes, the current code
  executes all conditions for all grants, and then filters the passed ones
  by action and/or resource in the query.
- This is inefficient, especially if the condition checks are expensive, e.g.
  if they make database calls.
- I've optimized it by first filtering out grants based on the action and
  resource in the query, and then running the condition checks on the remaining.
&& this.anyMatch(query.action, grant.action);
});

return (await this.filterGrantsAllowing(matchingGrants, query))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is a false positive. Please manually review.


const matchingGrants = (await this.getUnionGrantsOfRoles(grants, query));

return (await this.filterGrantsAllowing(matchingGrants, query))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is a false positive. Please manually review.

}).map((grant) => {
});

return (await this.filterGrantsAllowing(matchingGrants, query))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is a false positive. Please manually review.

}).reduce(Notation.Glob.union, []);
}

public static async filterGrantsAllowing(grants: IAccessInfo[], query: IQueryInfo): Promise<IAccessInfo[]> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit of code is just the latter part of getUnionGrantsOfRoles(...) that has been refactored into it's own function.

@codeclimate
Copy link

codeclimate bot commented Oct 10, 2019

Code Climate has analyzed commit f0ca088 and detected 4 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1
Duplication 3

The test coverage on the diff in this pull request is 100.0% (80% is the threshold).

This pull request will bring the total coverage in the repository to 90.3% (0.0% change).

View more on Code Climate.

@koladilip koladilip merged commit 0eee374 into tensult:develop Oct 10, 2019
@koladilip
Copy link
Contributor

Thanks @loban, release this as https://www.npmjs.com/package/role-acl/v/4.1.2

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants