Merge branch 'refactor/add-policies' into 'master'
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
Showing
... | @@ -97,9 +97,6 @@ gem 'fog-rackspace', '~> 0.1.1' | ... | @@ -97,9 +97,6 @@ gem 'fog-rackspace', '~> 0.1.1' |
# for aws storage | # for aws storage | ||
gem 'unf', '~> 0.1.4' | gem 'unf', '~> 0.1.4' | ||
# Authorization | |||
gem 'six', '~> 0.2.0' | |||
# Seed data | # Seed data | ||
gem 'seed-fu', '~> 2.3.5' | gem 'seed-fu', '~> 2.3.5' | ||
... | ... |
This diff is collapsed.
Click to expand it.
app/policies/base_policy.rb
0 → 100644
app/policies/ci/build_policy.rb
0 → 100644
app/policies/ci/runner_policy.rb
0 → 100644
app/policies/commit_status_policy.rb
0 → 100644
app/policies/deployment_policy.rb
0 → 100644
app/policies/environment_policy.rb
0 → 100644
app/policies/external_issue_policy.rb
0 → 100644
app/policies/global_policy.rb
0 → 100644
app/policies/group_member_policy.rb
0 → 100644
app/policies/group_policy.rb
0 → 100644
app/policies/issuable_policy.rb
0 → 100644
app/policies/issue_policy.rb
0 → 100644
app/policies/merge_request_policy.rb
0 → 100644
app/policies/namespace_policy.rb
0 → 100644
app/policies/note_policy.rb
0 → 100644
app/policies/personal_snippet_policy.rb
0 → 100644
app/policies/project_member_policy.rb
0 → 100644
app/policies/project_policy.rb
0 → 100644
app/policies/project_snippet_policy.rb
0 → 100644
app/policies/user_policy.rb
0 → 100644
spec/models/project_security_spec.rb
deleted
100644 → 0
spec/policies/project_policy_spec.rb
0 → 100644
Please
register
or
sign in
to comment