-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ability): changes signature of rulesToQuery to be similar to…
… permittedFieldsOf This protects user from mistakes like passing rules of different subjects/actions into rulesToQuery. Also refactores toMongoQuery to have similar signature but a bit different, action goes as the last argument, so we can specify default action to be `read` (as in majority of cases this is what users will want) Relates to #18
- Loading branch information
Showing
6 changed files
with
73 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { rulesToQuery } from '@casl/ability/extra'; | ||
|
||
function ruleToMongoQuery(rule) { | ||
function convertToMongoQuery(rule) { | ||
return rule.inverted ? { $nor: [rule.conditions] } : rule.conditions; | ||
} | ||
|
||
export function toMongoQuery(rules) { | ||
return rulesToQuery(rules, ruleToMongoQuery); | ||
export function toMongoQuery(ability, subject, action = 'read') { | ||
return rulesToQuery(ability, action, subject, convertToMongoQuery); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters