BigW Consortium Gitlab
Refactor ability.rb into Policies ## What does this MR do? Factors out `ability.rb` into a new abstraction - the "policy" (stored in `app/policies`). A policy is a class named `#{class_name}Policy` (looked up automatically as needed) that implements `rules` as follows: ``` ruby class ThingPolicy < BasePolicy def rules @user # this is a user to determine abilities for, optionally nil in the anonymous case @subject # this is the subject of the ability, guaranteed to be an instance of `Thing` can! :some_ability # grant the :some_ability permission cannot! :some_ability # ensure that :some_ability is not allowed. this overrides any `can!` that is called before or after delegate! @subject.other_thing # merge the abilities (can!) and prohibitions (cannot!) from `@subject.other_thing` can? :some_ability # test whether, so far, :some_ability is allowed end def anonymous_rules # optional. if not implemented `rules` is called where `@user` is nil. otherwise this method is called when `@user` is nil. end end ``` See merge request !5796
Name |
Last commit
|
Last update |
---|---|---|
.. | ||
admin | Loading commit data... | |
ci | Loading commit data... | |
concerns | Loading commit data... | |
dashboard | Loading commit data... | |
explore | Loading commit data... | |
groups | Loading commit data... | |
import | Loading commit data... | |
oauth | Loading commit data... | |
profiles | Loading commit data... | |
projects | Loading commit data... | |
sherlock | Loading commit data... | |
abuse_reports_controller.rb | Loading commit data... | |
application_controller.rb | Loading commit data... | |
autocomplete_controller.rb | Loading commit data... | |
confirmations_controller.rb | Loading commit data... | |
dashboard_controller.rb | Loading commit data... | |
emojis_controller.rb | Loading commit data... | |
groups_controller.rb | Loading commit data... | |
health_check_controller.rb | Loading commit data... | |
help_controller.rb | Loading commit data... | |
invites_controller.rb | Loading commit data... | |
jwt_controller.rb | Loading commit data... | |
koding_controller.rb | Loading commit data... | |
namespaces_controller.rb | Loading commit data... | |
notification_settings_controller.rb | Loading commit data... | |
omniauth_callbacks_controller.rb | Loading commit data... | |
passwords_controller.rb | Loading commit data... | |
profiles_controller.rb | Loading commit data... | |
projects_controller.rb | Loading commit data... | |
registrations_controller.rb | Loading commit data... | |
root_controller.rb | Loading commit data... | |
search_controller.rb | Loading commit data... | |
sent_notifications_controller.rb | Loading commit data... | |
sessions_controller.rb | Loading commit data... | |
snippets_controller.rb | Loading commit data... | |
uploads_controller.rb | Loading commit data... | |
users_controller.rb | Loading commit data... |