@casl/ability
Advanced tools
+19
-2
@@ -6,2 +6,19 @@ # Change Log | ||
| <a name="2.0.2"></a> | ||
| # [2.0.2](https://github.com/stalniy/casl/compare/@casl/ability@2.0.0...@casl/ability@2.0.2) (2018-04-03) | ||
| ### Features | ||
| * **ability:** allows to pass subjects as comma separated items ([7612425](https://github.com/stalniy/casl/commit/7612425)) | ||
| * **builder:** allows to pass async function in `AbilityBuilder.define` ([def07c7](https://github.com/stalniy/casl/commit/def07c7)) | ||
| ### Performance | ||
| * **ability:** improves performance of `permittedFieldsOf` helper function ([7612425](https://github.com/stalniy/casl/commit/7612425)) | ||
| ### Bug Fixes | ||
| * **builder:** returns RuleBuilder from AbilityBuilder#cannot ([def07c7](https://github.com/stalniy/casl/commit/def07c7)) | ||
| <a name="2.0.0"></a> | ||
@@ -46,4 +63,4 @@ # [2.0.0](https://github.com/stalniy/casl/compare/v1.1.0...@casl/ability@2.0.0) (2018-03-23) | ||
| const ability = AbilityBuilder.define((can, cannot) => { | ||
| can('read', 'all') | ||
| cannot('read', 'Post') | ||
| can('read', 'all') | ||
| cannot('read', 'Post') | ||
| }) | ||
@@ -50,0 +67,0 @@ |
@@ -33,7 +33,8 @@ function rulesToQuery(ability, action, subject, convert) { | ||
| const fieldsFrom = options.fieldsFrom || getRuleFields; | ||
| const uniqueFields = ability.possibleRulesFor(action, subject).reduce((fields, rule) => { | ||
| const uniqueFields = ability.possibleRulesFor(action, subject).slice(0).reverse().filter(rule => rule.matches(subject)).reduce((fields, rule) => { | ||
| const names = fieldsFrom(rule); | ||
| if (names && !rule.inverted) { | ||
| names.forEach(fields.add, fields); | ||
| if (names) { | ||
| const toggle = rule.inverted ? 'delete' : 'add'; | ||
| names.forEach(fields[toggle], fields); | ||
| } | ||
@@ -44,5 +45,5 @@ | ||
| return Array.from(uniqueFields).filter(field => ability.can(action, subject, field)); | ||
| return Array.from(uniqueFields); | ||
| } | ||
| export { rulesToQuery, permittedFieldsOf }; |
@@ -114,3 +114,3 @@ import sift from 'sift'; | ||
| const action = actions[j]; | ||
| const subjects = Array.isArray(rule.subject) ? rule.subject : [rule.subject]; | ||
| const subjects = Array.isArray(rule.subject) ? rule.subject : rule.subject.split(','); | ||
@@ -228,5 +228,6 @@ for (let k = 0; k < subjects.length; k++) { | ||
| const builder = new this(); | ||
| define(builder.can.bind(builder), builder.cannot.bind(builder)); | ||
| const result = define(builder.can.bind(builder), builder.cannot.bind(builder)); | ||
| const buildAbility = () => new Ability(builder.rules, options); | ||
| return new Ability(builder.rules, options); | ||
| return result && typeof result.then === 'function' ? result.then(buildAbility) : buildAbility(); | ||
| } | ||
@@ -276,3 +277,3 @@ | ||
| return builder.rule; | ||
| return builder; | ||
| } | ||
@@ -279,0 +280,0 @@ } |
@@ -43,7 +43,10 @@ (function (global, factory) { | ||
| var fieldsFrom = options.fieldsFrom || getRuleFields; | ||
| var uniqueFields = ability.possibleRulesFor(action, subject).reduce(function (fields, rule) { | ||
| var uniqueFields = ability.possibleRulesFor(action, subject).slice(0).reverse().filter(function (rule) { | ||
| return rule.matches(subject); | ||
| }).reduce(function (fields, rule) { | ||
| var names = fieldsFrom(rule); | ||
| if (names && !rule.inverted) { | ||
| names.forEach(fields.add, fields); | ||
| if (names) { | ||
| var toggle = rule.inverted ? 'delete' : 'add'; | ||
| names.forEach(fields[toggle], fields); | ||
| } | ||
@@ -54,5 +57,3 @@ | ||
| return Array.from(uniqueFields).filter(function (field) { | ||
| return ability.can(action, subject, field); | ||
| }); | ||
| return Array.from(uniqueFields); | ||
| } | ||
@@ -59,0 +60,0 @@ |
@@ -177,3 +177,3 @@ (function (global, factory) { | ||
| var action = actions[j]; | ||
| var subjects = Array.isArray(rule.subject) ? rule.subject : [rule.subject]; | ||
| var subjects = Array.isArray(rule.subject) ? rule.subject : rule.subject.split(','); | ||
@@ -313,5 +313,8 @@ for (var k = 0; k < subjects.length; k++) { | ||
| var builder = new this(); | ||
| define(builder.can.bind(builder), builder.cannot.bind(builder)); | ||
| var result = define(builder.can.bind(builder), builder.cannot.bind(builder)); | ||
| var buildAbility = function buildAbility() { | ||
| return new Ability(builder.rules, options); | ||
| }; | ||
| return new Ability(builder.rules, options); | ||
| return result && typeof result.then === 'function' ? result.then(buildAbility) : buildAbility(); | ||
| } | ||
@@ -368,3 +371,3 @@ }, { | ||
| return builder.rule; | ||
| return builder; | ||
| } | ||
@@ -371,0 +374,0 @@ }]); |
+7
-6
@@ -37,7 +37,10 @@ function rulesToQuery(ability, action, subject, convert) { | ||
| var fieldsFrom = options.fieldsFrom || getRuleFields; | ||
| var uniqueFields = ability.possibleRulesFor(action, subject).reduce(function (fields, rule) { | ||
| var uniqueFields = ability.possibleRulesFor(action, subject).slice(0).reverse().filter(function (rule) { | ||
| return rule.matches(subject); | ||
| }).reduce(function (fields, rule) { | ||
| var names = fieldsFrom(rule); | ||
| if (names && !rule.inverted) { | ||
| names.forEach(fields.add, fields); | ||
| if (names) { | ||
| var toggle = rule.inverted ? 'delete' : 'add'; | ||
| names.forEach(fields[toggle], fields); | ||
| } | ||
@@ -48,7 +51,5 @@ | ||
| return Array.from(uniqueFields).filter(function (field) { | ||
| return ability.can(action, subject, field); | ||
| }); | ||
| return Array.from(uniqueFields); | ||
| } | ||
| export { rulesToQuery, permittedFieldsOf }; |
+7
-4
@@ -171,3 +171,3 @@ import sift from 'sift'; | ||
| var action = actions[j]; | ||
| var subjects = Array.isArray(rule.subject) ? rule.subject : [rule.subject]; | ||
| var subjects = Array.isArray(rule.subject) ? rule.subject : rule.subject.split(','); | ||
@@ -307,5 +307,8 @@ for (var k = 0; k < subjects.length; k++) { | ||
| var builder = new this(); | ||
| define(builder.can.bind(builder), builder.cannot.bind(builder)); | ||
| var result = define(builder.can.bind(builder), builder.cannot.bind(builder)); | ||
| var buildAbility = function buildAbility() { | ||
| return new Ability(builder.rules, options); | ||
| }; | ||
| return new Ability(builder.rules, options); | ||
| return result && typeof result.then === 'function' ? result.then(buildAbility) : buildAbility(); | ||
| } | ||
@@ -362,3 +365,3 @@ }, { | ||
| return builder.rule; | ||
| return builder; | ||
| } | ||
@@ -365,0 +368,0 @@ }]); |
+1
-1
| { | ||
| "name": "@casl/ability", | ||
| "version": "2.0.1", | ||
| "version": "2.0.2", | ||
| "description": "CASL is an isomorphic authorization JavaScript library which restricts what resources a given user is allowed to access", | ||
@@ -5,0 +5,0 @@ "main": "dist/umd/index.js", |
49729
2.73%1017
0.99%