Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[33750] Ensure default statuses can not be set read only

Oliver Günther4bb47cd93553
diff --git a/app/models/status.rb b/app/models/status.rb
index 91921bf92c0..3bf8075e840 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -47,6 +47,8 @@ class Status < ApplicationRecord
validates_inclusion_of :default_done_ratio, in: 0..100, allow_nil: true
+ validate :default_status_must_not_be_readonly
+
after_save :unmark_old_default_value, if: :is_default?
def unmark_old_default_value
@@ -108,6 +110,12 @@ class Status < ApplicationRecord
raise "Can't delete status" if WorkPackage.where(status_id: id).exists?
end
+ def default_status_must_not_be_readonly
+ if is_readonly? && is_default?
+ errors.add(:is_readonly, :readonly_default_exlusive)
+ end
+ end
+
# Deletes associated workflows
def delete_workflows
Workflow
diff --git a/config/locales/en.yml b/config/locales/en.yml
index f88e8fa770a..5f559c46f97 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -747,6 +747,8 @@ en:
unassignable: "cannot be assigned to a project."
version:
undeletable_work_packages_attached: "The version cannot be deleted as it has work packages attached to it."
+ status:
+ readonly_default_exlusive: "can not be activated for statuses that are marked default."
template:
body: "Please check the following fields:"
header:
diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb
index a0e67063ec3..33902972326 100644
--- a/spec/models/status_spec.rb
+++ b/spec/models/status_spec.rb
@@ -39,6 +39,12 @@ describe Status, type: :model do
expect(Status.default).to eq(status)
expect(Status.where_default.pluck(:id)).to eq([status.id])
end
+
+ it 'can not be set read only (Regression #33750)', with_ee: %i[readonly_work_packages] do
+ status.is_readonly = true
+ expect(status.save).to eq false
+ expect(status.errors[:is_readonly]).to include(I18n.t("activerecord.errors.models.status.readonly_default_exlusive"))
+ end
end
end