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:
parent
bdd7600de7
commit
6114c40fca
2 changed files with 21 additions and 16 deletions
|
@ -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) ||
|
||||||
|
|
19
app/policies/project_policy/class_methods.rb
Normal file
19
app/policies/project_policy/class_methods.rb
Normal 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
|
Loading…
Reference in a new issue