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.
This commit is contained in:
Bob Van Landuyt 2018-04-05 18:42:57 +02:00
parent bdd7600de7
commit 6114c40fca
2 changed files with 21 additions and 16 deletions

View file

@ -1,4 +1,6 @@
class ProjectPolicy < BasePolicy class ProjectPolicy < BasePolicy
extend ClassMethods
READONLY_FEATURES_WHEN_ARCHIVED = %i[ READONLY_FEATURES_WHEN_ARCHIVED = %i[
issue issue
list list
@ -20,22 +22,6 @@ class ProjectPolicy < BasePolicy
cluster cluster
].freeze ].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" desc "User is a project owner"
condition :owner do condition :owner do
(project.owner.present? && project.owner == @user) || (project.owner.present? && project.owner == @user) ||

View file

@ -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