Open
Conversation
If global “deny” or “allow” defined but not passed, and there isn’t any activity validator followed, just go to notAuthorized.
Owner
|
thanks for splitting this in to a separate pull request! can you explain the scenario again? i want to make sure i completely understand the purpose of this change |
Contributor
Author
|
We don't need to define all activity validators especially when there are too many activities with the same logic. We can use global deny or allow, but if they are not passed, we can just return notAuthorized if no individual validator defined. config.activities(function (activities) {
activities.allow(function (identity, activity, cb) {
// permissions may be loaded from database by identity.user
var permissions = ['users.add', 'users.read', 'users.edit', 'users.destroy'];
cb(null, permissions.indexOf(activity) !== -1);
});
// individual validator example
activities.can("users.edit", function (identity, params, cb) {
cb(null, identity.user.id === params.user_id);
});
/*
// If global "allow" is not passed, I don't want to define all validators like this,
// but now it throws ActivityNotFoundException.
activities.can("users.add", function (identity, params, cb) {
cb(null, false);
});
activities.can("users.read", function (identity, params, cb) {
cb(null, false);
});
activities.can("users.destroy", function (identity, params, cb) {
cb(null, false);
});
*/
}); |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If global “deny” or “allow” defined but not passed, and there isn’t any
activity validator followed, just go to notAuthorized.