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

actually disable comments with restricted visibility with project setting is disabled

Bruno Pagno7ad332d86cfd
diff --git a/app/components/work_packages/activities_tab/journals/new_component.rb b/app/components/work_packages/activities_tab/journals/new_component.rb
index f84262eb508..4b691638f75 100644
--- a/app/components/work_packages/activities_tab/journals/new_component.rb
+++ b/app/components/work_packages/activities_tab/journals/new_component.rb
@@ -60,6 +60,7 @@ module WorkPackages
def adding_restricted_comment_allowed?
OpenProject::FeatureDecisions.comments_with_restricted_visibility_active? &&
+ work_package.project.enabled_comments_with_restricted_visibility &&
User.current.allowed_in_project?(:add_comments_with_restricted_visibility, work_package.project)
end
diff --git a/app/models/work_package/journalized.rb b/app/models/work_package/journalized.rb
index 0ff0d06be3f..2bfd855df77 100644
--- a/app/models/work_package/journalized.rb
+++ b/app/models/work_package/journalized.rb
@@ -33,6 +33,7 @@ module WorkPackage::Journalized
acts_as_journalized journals_association_extension: proc {
def restricted_visible
if OpenProject::FeatureDecisions.comments_with_restricted_visibility_active? &&
+ proxy_association.owner.project.enabled_comments_with_restricted_visibility &&
User.current.allowed_in_project?(:view_comments_with_restricted_visibility, proxy_association.owner.project)
all
else
diff --git a/spec/features/activities/work_package/restricted_visibility_comments_spec.rb b/spec/features/activities/work_package/restricted_visibility_comments_spec.rb
index 1b9fbecfc41..e23cf28c98b 100644
--- a/spec/features/activities/work_package/restricted_visibility_comments_spec.rb
+++ b/spec/features/activities/work_package/restricted_visibility_comments_spec.rb
@@ -52,17 +52,40 @@ RSpec.describe "Work package comments with restricted visibility",
context "with an admin user" do
current_user { admin }
- before do
- wp_page.visit!
- wp_page.wait_for_activity_tab
+ context "when the feature is enabled for the project" do
+ before do
+ project.enabled_comments_with_restricted_visibility = true
+ project.save!
+
+ wp_page.visit!
+ wp_page.wait_for_activity_tab
+ end
+
+ it "allows adding a comment with restricted visibility" do
+ activity_tab.expect_input_field
+
+ activity_tab.add_comment(text: "First (restricted) comment by admin", restricted: true)
+
+ activity_tab.expect_journal_notes(text: "First (restricted) comment by admin")
+ end
end
- it "allows adding a comment with restricted visibility" do
- activity_tab.expect_input_field
+ context "when the feature is not enabled for the project" do
+ before do
+ project.enabled_comments_with_restricted_visibility = false
+ project.save!
- activity_tab.add_comment(text: "First (restricted) comment by admin", restricted: true)
+ wp_page.visit!
+ wp_page.wait_for_activity_tab
+ end
- activity_tab.expect_journal_notes(text: "First (restricted) comment by admin")
+ it "allows adding a comment with restricted visibility" do
+ activity_tab.expect_input_field
+
+ activity_tab.type_comment("This comment cannot be restricted")
+
+ expect(page).not_to have_test_selector("op-work-package-journal-restricted-comment-checkbox")
+ end
end
end
diff --git a/spec/models/work_package/work_package_acts_as_journalized_spec.rb b/spec/models/work_package/work_package_acts_as_journalized_spec.rb
index 9a211518c20..1ba39f407cc 100644
--- a/spec/models/work_package/work_package_acts_as_journalized_spec.rb
+++ b/spec/models/work_package/work_package_acts_as_journalized_spec.rb
@@ -903,28 +903,51 @@ RSpec.describe WorkPackage do
end
context "when comments_with_restricted_visibility is enabled", with_flag: { comments_with_restricted_visibility: true } do
- context "when the user cannot see restricted journals" do
+ context "and setting is enabled for the project" do
before do
- mock_permissions_for(user) do |mock|
- mock.allow_in_work_package :view_work_packages, work_package:
+ work_package.project.enabled_comments_with_restricted_visibility = true
+ work_package.project.save!
+ end
+
+ context "when the user cannot see restricted journals" do
+ before do
+ mock_permissions_for(user) do |mock|
+ mock.allow_in_work_package :view_work_packages, work_package:
+ end
+ end
+
+ it "does not return the restricted journal" do
+ expect(journals.map(&:id)).not_to include(restricted_note.id)
+ expect(journals.map(&:id)).to include(unrestricted_note.id)
end
end
- it "does not return the restricted journal" do
- expect(journals.map(&:id)).not_to include(restricted_note.id)
- expect(journals.map(&:id)).to include(unrestricted_note.id)
+ context "when the user can see restricted journals" do
+ before do
+ mock_permissions_for(user) do |mock|
+ mock.allow_in_project(:view_comments_with_restricted_visibility, project: work_package.project)
+ end
+ end
+
+ it "returns all journals" do
+ expect(journals.map(&:id)).to include(restricted_note.id, unrestricted_note.id)
+ end
end
end
- context "when the user can see restricted journals" do
+ context "and setting is disabled for the project" do
before do
+ work_package.project.enabled_comments_with_restricted_visibility = false
+ work_package.project.save!
+
mock_permissions_for(user) do |mock|
mock.allow_in_project(:view_comments_with_restricted_visibility, project: work_package.project)
end
end
- it "returns all journals" do
- expect(journals.map(&:id)).to include(restricted_note.id, unrestricted_note.id)
+ it "does not return the restricted journal" do
+ expect(journals.map(&:id)).not_to include(restricted_note.id)
+ expect(journals.map(&:id)).to include(unrestricted_note.id)
end
end
end