From 6114c40fca764602addc911bc58bc05c42e03747 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Thu, 5 Apr 2018 18:42:57 +0200 Subject: [PATCH] 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. --- app/policies/project_policy.rb | 18 ++---------------- app/policies/project_policy/class_methods.rb | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 app/policies/project_policy/class_methods.rb 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