Last active
March 30, 2026 19:04
-
-
Save glaszig/1e5118eaab4f633ff0c2e17ef706345d to your computer and use it in GitHub Desktop.
ruby authorization policies in 40 lines of code in spirit of rails-native authentication
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
| # app/policies/appointment_policy.rb | |
| class AppointmentPolicy | |
| class Scope | |
| def resolve scope | |
| if Current.user.admin? | |
| scope | |
| else | |
| scope.mine | |
| end | |
| end | |
| end | |
| def edit? appointment | |
| return false if appointment.participant_approved? | |
| return true if Current.user.admin? | |
| appointment.user == Current.user && !appointment.review | |
| end | |
| def destroy? appointment | |
| !appointment.participant_approved? | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment