Add declarative_policy_class to Declarative Policy
What does this MR do?
This adds the ability to specify a Declarative Policy class for a given Class.
The current behaviour of finding a policy for a Class is to append Policy
to the class name. (https://gitlab.com/gitlab-org/gitlab/blob/master/lib/declarative_policy.rb#L77)
Although this encourages convention over configuration, it is restrictive. There are times when this behaviour would force unnecessary namespacing inside the app/policies
directory, or force a moving of files so that they fit the existing app/policies
directory structure.
For example if you needed to create a policy for a file in lib/gitlab
, you would need to either move the file, or create a app/policies/gitlab
directory in order for the automatic class finding to work.
Under this proposed change you could do the following:
class Gitlab::SomeClass
def self.declarative_policy_class
'SomeClassPolicy' # Or any other Policy class
end
end
Since we already allow you to delegate the subject of a policy, it seems ok to merge this in.