diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-04-05 18:42:57 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-04-10 19:43:01 +0200 |
commit | 6114c40fca764602addc911bc58bc05c42e03747 (patch) | |
tree | 85d22c3ffba3d39383d95f6442ccfb20207124c1 /app/policies | |
parent | bdd7600de71c9490be4ba4ddc27999b490b7cf8a (diff) | |
download | gitlab-ce-6114c40fca764602addc911bc58bc05c42e03747.tar.gz |
Move `ProjectPolicy`-class methods into module
That way the ProjectPolicy class can be extended with this module
before we prepend the EE::ProjectPolicy. This makes the classmethods
available for rules defined in the EE::ProjectPolicy.
Diffstat (limited to 'app/policies')
-rw-r--r-- | app/policies/project_policy.rb | 18 | ||||
-rw-r--r-- | app/policies/project_policy/class_methods.rb | 19 |
2 files changed, 21 insertions, 16 deletions
diff --git a/app/policies/project_policy.rb b/app/policies/project_policy.rb index 91dd89a8de1..b4970b605ca 100644 --- a/app/policies/project_policy.rb +++ b/app/policies/project_policy.rb @@ -1,4 +1,6 @@ class ProjectPolicy < BasePolicy + extend ClassMethods + READONLY_FEATURES_WHEN_ARCHIVED = %i[ issue list @@ -20,22 +22,6 @@ class ProjectPolicy < BasePolicy cluster ].freeze - def self.create_read_update_admin_destroy(name) - [ - :"read_#{name}", - *create_update_admin_destroy(name) - ] - end - - def self.create_update_admin_destroy(name) - [ - :"create_#{name}", - :"update_#{name}", - :"admin_#{name}", - :"destroy_#{name}" - ] - end - desc "User is a project owner" condition :owner do (project.owner.present? && project.owner == @user) || diff --git a/app/policies/project_policy/class_methods.rb b/app/policies/project_policy/class_methods.rb new file mode 100644 index 00000000000..60e5aba00ba --- /dev/null +++ b/app/policies/project_policy/class_methods.rb @@ -0,0 +1,19 @@ +class ProjectPolicy + module ClassMethods + def create_read_update_admin_destroy(name) + [ + :"read_#{name}", + *create_update_admin_destroy(name) + ] + end + + def create_update_admin_destroy(name) + [ + :"create_#{name}", + :"update_#{name}", + :"admin_#{name}", + :"destroy_#{name}" + ] + end + end +end |