-
-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: optional authorization context #95
Feat: optional authorization context #95
Conversation
@@ -49,11 +49,15 @@ def initialize(*args, **params) | |||
@authorization_context = {} | |||
|
|||
self.class.authorization_targets.each do |id, opts| | |||
raise AuthorizationContextMissing, id unless params.key?(id) | |||
if opts[:optional] == true | |||
val = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it clear the value if it's passed? Can we add a test with OptionalRoleTestPolicy.new(role: some_role)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. My bad.
Already fixed 👌🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And let's also update the documentation: https://github.com/palkan/action_policy/blob/master/docs/authorization_context.md
It's already there https://github.com/palkan/action_policy/pull/95/files#diff-0a246b3b403e2dba66a4867a91b6d2e7R22 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thanks!
What is the purpose of this pull request?
As suggested in #89 (comment)
it allows making authorization context optional
What changes did you make? (overview)
Don't raise
AuthorizationContextMissing
fromActionPolicy::Policy::Authorization
if authorization target was defined with hasoptional: true
PR checklist: