gitlab-org--gitlab-foss/app
Robert Speicher e71cd7a300 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
2016-08-31 20:53:40 +00:00
..
assets Merge branch 'fix-todo-pagination' into 'master' 2016-08-31 20:26:12 +00:00
controllers Merge branch 'refactor/add-policies' into 'master' 2016-08-31 20:53:40 +00:00
finders Merge branch 'refactor/add-policies' into 'master' 2016-08-31 20:53:40 +00:00
helpers Merge branch 'tag-name-filter' into 'master' 2016-08-31 19:58:20 +00:00
mailers remove Ability.abilities 2016-08-30 11:35:06 -07:00
models Merge branch 'refactor/add-policies' into 'master' 2016-08-31 20:53:40 +00:00
policies newline before default return 2016-08-30 15:55:37 -07:00
services Merge branch 'refactor/add-policies' into 'master' 2016-08-31 20:53:40 +00:00
uploaders
validators
views Merge branch 'fix-todo-pagination' into 'master' 2016-08-31 20:26:12 +00:00
workers