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

bug/64324 Enhance internal comments feature plan access (#19057)

Kabiru Mwenjae66502e8df44
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 3f69e07141a..a0e796f92d5 100644
--- a/app/components/work_packages/activities_tab/journals/new_component.rb
+++ b/app/components/work_packages/activities_tab/journals/new_component.rb
@@ -60,7 +60,8 @@ module WorkPackages
end
def adding_internal_comment_allowed?
- work_package.project.enabled_internal_comments &&
+ EnterpriseToken.allows_to?(:internal_comments) &&
+ work_package.project.enabled_internal_comments &&
User.current.allowed_in_project?(:add_internal_comments, work_package.project)
end
diff --git a/app/contracts/work_packages/create_note_contract.rb b/app/contracts/work_packages/create_note_contract.rb
index 2cc990e6054..f4c9db290a2 100644
--- a/app/contracts/work_packages/create_note_contract.rb
+++ b/app/contracts/work_packages/create_note_contract.rb
@@ -40,6 +40,11 @@ module WorkPackages
attribute :journal_internal do
next unless model.journal_internal
+ unless EnterpriseToken.allows_to?(:internal_comments)
+ plan_name = I18n.t("ee.upsell.plan_name", plan: OpenProject::Token.lowest_plan_for(:internal_comments)&.capitalize)
+ errors.add(:journal_internal, :enterprise_plan_required, plan_name:)
+ end
+
unless allowed_in_project?(:add_internal_comments)
errors.add(:journal_internal, :error_unauthorized)
end
diff --git a/spec/contracts/work_packages/create_note_contract_spec.rb b/spec/contracts/work_packages/create_note_contract_spec.rb
index c3d00949bf2..6f4f952114a 100644
--- a/spec/contracts/work_packages/create_note_contract_spec.rb
+++ b/spec/contracts/work_packages/create_note_contract_spec.rb
@@ -82,7 +82,7 @@ RSpec.describe WorkPackages::CreateNoteContract do
end
end
- describe "journal_internal" do
+ describe "journal_internal", with_ee: [:internal_comments] do
before do
# Setting the journal_notes to not trigger a :blank error
work_package.journal_notes = "blubs"
@@ -94,6 +94,15 @@ RSpec.describe WorkPackages::CreateNoteContract do
end
it_behaves_like "contract is valid"
+
+ context "and the enterprise token does not allow internal comments", with_ee: [] do
+ it "invalidates the contract, and shows the least required enterprise plan" do
+ expect(contract.validate).to be(false)
+
+ expect(contract.errors.full_messages)
+ .to eq(["Internal Journal requires at least the Professional enterprise plan."])
+ end
+ end
end
context "and journal_internal is false" do
diff --git a/spec/features/activities/work_package/internal_comments_spec.rb b/spec/features/activities/work_package/internal_comments_spec.rb
index ef47263009b..ee887f732dc 100644
--- a/spec/features/activities/work_package/internal_comments_spec.rb
+++ b/spec/features/activities/work_package/internal_comments_spec.rb
@@ -31,7 +31,8 @@
require "spec_helper"
RSpec.describe "Work package internal comments",
- :js do
+ :js,
+ with_ee: [:internal_comments] do
include InternalCommentsHelpers
shared_let(:project) { create(:project, enabled_internal_comments: true) }
@@ -52,6 +53,14 @@ RSpec.describe "Work package internal comments",
context "with an admin user" do
current_user { admin }
+ shared_examples "internal comments are disabled" do
+ it "does not allow adding an internal comment" do
+ activity_tab.expect_input_field
+
+ activity_tab.type_comment("This comment cannot be internal")
+ end
+ end
+
context "when the feature is enabled for the project" do
before do
wp_page.visit!
@@ -76,13 +85,19 @@ RSpec.describe "Work package internal comments",
wp_page.wait_for_activity_tab
end
- it "does not allow adding an internal comment" do
- activity_tab.expect_input_field
+ it_behaves_like "internal comments are disabled"
+ end
- activity_tab.type_comment("This comment cannot be internal")
+ context "when the enterprise plan does not allow internal comments", with_ee: [] do
+ before do
+ project.enabled_internal_comments = true
+ project.save!
- expect(page).not_to have_test_selector("op-work-package-journal-internal-comment-checkbox")
+ wp_page.visit!
+ wp_page.wait_for_activity_tab
end
+
+ it_behaves_like "internal comments are disabled"
end
end
@@ -193,7 +208,7 @@ RSpec.describe "Work package internal comments",
end
end
- describe "inline banner" do
+ describe "inline banner", with_ee: [] do
current_user { project_admin }
before do