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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Enhance wp note contract to include feature flag
Kabiru Mwenja9bb1da4de34d
diff --git a/app/contracts/work_packages/create_note_contract.rb b/app/contracts/work_packages/create_note_contract.rbindex 9868261ba7c..21d8d7700cb 100644--- a/app/contracts/work_packages/create_note_contract.rb+++ b/app/contracts/work_packages/create_note_contract.rb@@ -34,10 +34,13 @@ module WorkPackagesattribute :journal_notes doerrors.add(:journal_notes, :error_unauthorized) unless can?(:comment)+ errors.add(:journal_notes, :blank) if model.journal_notes.blank?endattribute :journal_restricted do- errors.add(:journal_restricted, :invalid) if model.journal_notes.blank? && model.journal_restricted+ if model.journal_restricted && !OpenProject::FeatureDecisions.comments_with_restricted_visibility_active?+ errors.add(:journal_restricted, :feature_disabled)+ endendprivatediff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex 81d3cf9feef..1fd7a5d3aad 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -31,6 +31,7 @@ en:tenant: Directory (tenant) IDerrors:messages:+ feature_disabled: is not available.invalid_host_url: is not a valid URL.not_linked_to_project: is not linked to project.models:diff --git a/spec/contracts/work_packages/create_note_contract_spec.rb b/spec/contracts/work_packages/create_note_contract_spec.rbindex e880862f122..eeacb2dabb7 100644--- a/spec/contracts/work_packages/create_note_contract_spec.rb+++ b/spec/contracts/work_packages/create_note_contract_spec.rb@@ -86,24 +86,30 @@ RSpec.describe WorkPackages::CreateNoteContract doendcontext "with a blank note" do- context "and journal_restricted is true" do- before do- work_package.journal_notes = ""- work_package.journal_restricted = true+ before do+ work_package.journal_notes = ""+ work_package.journal_restricted = true- contract.validate+ contract.validate+ end++ context "and journal_restricted is true, and comments_with_restricted_visibility_active? is disabled",+ with_flag: { comments_with_restricted_visibility_active: false } do+ it "is invalid" do+ expect(contract.errors.full_messages).to eq(["Comment can't be blank.", "Restricted Journal is not available."])end+ end+ context "and journal_restricted is true, and comments_with_restricted_visibility_active? is enabled",+ with_flag: { comments_with_restricted_visibility_active: true } doit "is invalid" do- expect(contract.errors.symbols_for(:journal_restricted))- .to contain_exactly(:invalid)- expect(contract.errors.full_messages).to include("Restricted Journal is invalid.")+ expect(contract.errors.full_messages).to eq(["Comment can't be blank."])endendendcontext "with a note" do- context "and journal_restricted is true" do+ context "and journal_restricted is true", with_flag: { comments_with_restricted_visibility_active: true } dobefore dowork_package.journal_notes = "blubs"work_package.journal_restricted = true