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

[#64153] Journals index atom export can expose internal comments

Kabiru Mwenja7b6f16fc074b
diff --git a/app/models/query.rb b/app/models/query.rb
index 4049933269b..a2ff72285c2 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -390,9 +390,11 @@ class Query < ApplicationRecord
# Returns the journals
# Valid options are :order, :offset, :limit
- def work_package_journals(options = {})
+ # NOTE: Internal comments are NEVER included "FOR NOW". This is a stop gap measure before we
+ # evaluate whether we want to maintain the journals atom export or not.
+ def work_package_journals(options = {}) # rubocop:disable Metrics/AbcSize
Journal.includes(:user)
- .where(journable_type: WorkPackage.to_s)
+ .where(journable_type: WorkPackage.to_s, restricted: false)
.joins("INNER JOIN work_packages ON work_packages.id = journals.journable_id")
.joins("INNER JOIN projects ON work_packages.project_id = projects.id")
.joins("INNER JOIN users AS authors ON work_packages.author_id = authors.id")
diff --git a/spec/models/query_spec.rb b/spec/models/query_spec.rb
index d71d7250c1e..a6ed3ed5221 100644
--- a/spec/models/query_spec.rb
+++ b/spec/models/query_spec.rb
@@ -593,7 +593,6 @@ RSpec.describe Query,
context "with filters" do
before do
-
allow(Status)
.to receive_messages(all: [valid_status], exists?: true)
@@ -927,4 +926,25 @@ RSpec.describe Query,
end
end
end
+
+ describe "#work_package_journals" do
+ let(:work_package) { create(:work_package, project:, author: project_member) }
+ let(:user) { create(:user, member_with_permissions: { work_package => %i[view_work_packages] }) }
+
+ before do
+ allow(User).to receive(:current).and_return(user)
+
+ work_package.add_journal(user:, notes: "This is a public note", internal: false)
+ work_package.save(validate: false)
+ work_package.add_journal(user:, notes: "This is an internal note", internal: true)
+ work_package.save(validate: false)
+ end
+
+ it "excludes internal comments", :aggregate_failures do
+ expect(work_package.journals.pluck(:restricted)).to contain_exactly(false, false, true)
+ expect(query.work_package_journals.count).to eq(2)
+ internal_journals = work_package.journals.where(restricted: true)
+ expect(query.work_package_journals).not_to include(internal_journals)
+ end
+ end
end