Skip to content
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

Merged
merged 3 commits into from
Nov 25, 2019

Conversation

somenugget
Copy link
Contributor

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 from ActionPolicy::Policy::Authorization if authorization target was defined with has optional: true

PR checklist:

  • Tests included
  • Documentation updated
  • Changelog entry added

@somenugget somenugget changed the title feat: optional authorization context Feat: optional authorization context Nov 23, 2019
@@ -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
Copy link
Owner

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)?

Copy link
Contributor Author

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 👌🏻

CHANGELOG.md Show resolved Hide resolved
Copy link
Owner

@palkan palkan left a comment

Choose a reason for hiding this comment

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

@somenugget
Copy link
Contributor Author

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

Copy link
Owner

@palkan palkan left a comment

Choose a reason for hiding this comment

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

👍 Thanks!

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

Successfully merging this pull request may close these issues.

2 participants