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

Allow passing a proc to authorize #291

Open
brendon opened this issue Feb 18, 2025 · 6 comments · May be fixed by #293
Open

Allow passing a proc to authorize #291

brendon opened this issue Feb 18, 2025 · 6 comments · May be fixed by #293

Comments

@brendon
Copy link
Contributor

brendon commented Feb 18, 2025

I'm flirting with ActiveSupport::CurrentAttributes and have to currently add a bridging method to pass current_user into ActionPolicy:

authorize :user, through: :current_user

def current_user
  Current.user
end

Would you be open to allowing a proc?

authorize :user, through: -> { Current.user }

Of course I could just skip all that and use Current.user all over the policies. I'm not 100% sure how I feel about that yet.

Apart from the usual hate for Current is there any reason not to go this way? It would definitely make testing less isolated.

@pboling
Copy link
Contributor

pboling commented Feb 18, 2025

I think accepting a Proc makes sense because it can be molded to fit just about any need.

@brendon
Copy link
Contributor Author

brendon commented Feb 18, 2025

Sounds good, would you like me to do a PR?

@pboling
Copy link
Contributor

pboling commented Feb 18, 2025

I'm not a maintainer, just a fellow contributor, but of course I'd love to see it. :)

@brendon
Copy link
Contributor Author

brendon commented Feb 18, 2025

Oh lol :D Yea I'll wait to see what @palkan thinks :)

@palkan
Copy link
Owner

palkan commented Feb 26, 2025

Sounds good to me! Will be happy to review and merge a PR :)

@brendon brendon linked a pull request Feb 26, 2025 that will close this issue
3 tasks
@brendon
Copy link
Contributor Author

brendon commented Feb 26, 2025

PR is up :)

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 a pull request may close this issue.

3 participants