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
[#64144] Watcher email notification can expose an internal comment if it is the latest comment
Kabiru Mwenja52ea17f7d250
diff --git a/app/helpers/work_packages_helper.rb b/app/helpers/work_packages_helper.rbindex 84a103d7751..566592ac2be 100644--- a/app/helpers/work_packages_helper.rb+++ b/app/helpers/work_packages_helper.rb@@ -210,7 +210,7 @@ module WorkPackagesHelperenddef last_work_package_note(work_package)- note_journals = work_package.journals.select(&:notes?)+ note_journals = work_package.journals.internal_visible.select(&:notes?)return t(:text_no_notes) if note_journals.empty?note_journals.last.notesdiff --git a/spec/helpers/work_packages_helper_spec.rb b/spec/helpers/work_packages_helper_spec.rbindex 5aa1b857019..64a9b82d715 100644--- a/spec/helpers/work_packages_helper_spec.rb+++ b/spec/helpers/work_packages_helper_spec.rb@@ -191,4 +191,56 @@ RSpec.describe WorkPackagesHelper do])endend++ describe "#last_work_package_note" do+ let(:user) do+ create(:user,+ member_with_permissions: { project => permissions })+ end++ let(:project) { create(:project, enabled_internal_comments: true) }++ before do+ allow(User).to receive(:current).and_return(user)+ end++ context "with a work package that has notes" do+ let(:work_package) { create(:work_package, project:) }++ before do+ add_work_package_note(internal: false)+ add_work_package_note(internal: true)+ end++ context "and the user has no permission to see internal notes" do+ let(:permissions) { %i[view_work_packages] }++ it "returns the last unrestricted note" do+ expect(helper.last_work_package_note(work_package)).to eq("This is the last PUBLIC note")+ end+ end++ context "and the user has permissions to see internal notes" do+ let(:permissions) { %i[view_work_packages view_internal_comments] }++ it "returns the last unrestricted note" do+ expect(helper.last_work_package_note(work_package)).to eq("This is the last INTERNAL note")+ end+ end++ def add_work_package_note(internal: false)+ work_package.add_journal(user:, notes: "This is the last #{internal ? 'INTERNAL' : 'PUBLIC'} note", internal:)+ work_package.save(validate: false)+ end+ end++ context "with a work package that has no notes" do+ let(:work_package) { create(:work_package, project:) }+ let(:permissions) { %i[view_work_packages] }++ it "returns the no notes text" do+ expect(helper.last_work_package_note(work_package)).to eq(I18n.t(:text_no_notes))+ end+ end+ endend