Commit 4074283d authored by Douwe Maan's avatar Douwe Maan Committed by Bob Van Landuyt

Block EE-specific write abilities when project is archived

parent 036af7d1
class ProjectPolicy < BasePolicy class ProjectPolicy < BasePolicy
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
prepend EE::ProjectPolicy prepend EE::ProjectPolicy
READONLY_FEATURES_WHEN_ARCHIVED = %i[ READONLY_FEATURES_WHEN_ARCHIVED = %i[
...@@ -22,22 +38,6 @@ class ProjectPolicy < BasePolicy ...@@ -22,22 +38,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) ||
......
...@@ -2,6 +2,12 @@ module EE ...@@ -2,6 +2,12 @@ module EE
module ProjectPolicy module ProjectPolicy
extend ActiveSupport::Concern extend ActiveSupport::Concern
READONLY_FEATURES_WHEN_ARCHIVED = %i[
board
issue_link
approvers
].freeze
prepended do prepended do
with_scope :subject with_scope :subject
condition(:service_desk_enabled) { @subject.service_desk_enabled? } condition(:service_desk_enabled) { @subject.service_desk_enabled? }
...@@ -125,6 +131,12 @@ module EE ...@@ -125,6 +131,12 @@ module EE
prevent :master_access prevent :master_access
prevent :owner_access prevent :owner_access
end end
rule { archived }.policy do
READONLY_FEATURES_WHEN_ARCHIVED.each do |feature|
prevent(*::ProjectPolicy.create_update_admin_destroy(feature))
end
end
end end
end end
end end
...@@ -140,7 +140,7 @@ describe ProjectPolicy do ...@@ -140,7 +140,7 @@ describe ProjectPolicy do
let(:feature_write_abilities) do let(:feature_write_abilities) do
described_class::READONLY_FEATURES_WHEN_ARCHIVED.flat_map do |feature| described_class::READONLY_FEATURES_WHEN_ARCHIVED.flat_map do |feature|
described_class.create_update_admin_destroy(feature) described_class.create_update_admin_destroy(feature)
end end + additional_reporter_permissions + additional_master_permissions
end end
let(:other_write_abilities) do let(:other_write_abilities) do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment