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 |
---|---|---|
.. | ||
README.md | Loading commit data... | |
branches_finder.rb | Loading commit data... | |
contributed_projects_finder.rb | Loading commit data... | |
group_projects_finder.rb | Loading commit data... | |
groups_finder.rb | Loading commit data... | |
issuable_finder.rb | Loading commit data... | |
issues_finder.rb | Loading commit data... | |
joined_groups_finder.rb | Loading commit data... | |
merge_requests_finder.rb | Loading commit data... | |
milestones_finder.rb | Loading commit data... | |
move_to_project_finder.rb | Loading commit data... | |
notes_finder.rb | Loading commit data... | |
personal_projects_finder.rb | Loading commit data... | |
pipelines_finder.rb | Loading commit data... | |
projects_finder.rb | Loading commit data... | |
snippets_finder.rb | Loading commit data... | |
tags_finder.rb | Loading commit data... | |
todos_finder.rb | Loading commit data... | |
trending_projects_finder.rb | Loading commit data... | |
union_finder.rb | Loading commit data... |