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

[#63873] addeed enterprise validation to contract

Eric Schubertd55a5ff29991
diff --git a/app/contracts/work_package_types/update_subject_pattern_contract.rb b/app/contracts/work_package_types/update_subject_pattern_contract.rb
index 00d7a6a6fb5..4d913591fba 100644
--- a/app/contracts/work_package_types/update_subject_pattern_contract.rb
+++ b/app/contracts/work_package_types/update_subject_pattern_contract.rb
@@ -32,10 +32,18 @@ module WorkPackageTypes
class UpdateSubjectPatternContract < BaseContract
attribute :patterns
+ validate :enterprise_edition
validate :validate_subject_generation_pattern
private
+ def enterprise_edition
+ action = :work_package_subject_generation
+ if model.patterns.subject&.enabled && !EnterpriseToken.allows_to?(action)
+ errors.add(:patterns, :error_enterprise_only, action: action.to_s.titleize)
+ end
+ end
+
def validate_subject_generation_pattern
blueprint = model.patterns.subject&.blueprint
return if blueprint.nil?
diff --git a/spec/components/work_package_types/subject_configuration_component_spec.rb b/spec/components/work_package_types/subject_configuration_component_spec.rb
index 56578de9c21..5e57b510b26 100644
--- a/spec/components/work_package_types/subject_configuration_component_spec.rb
+++ b/spec/components/work_package_types/subject_configuration_component_spec.rb
@@ -104,32 +104,25 @@ RSpec.describe WorkPackageTypes::SubjectConfigurationComponent, type: :component
end
context "when enterprise edition is not activated", with_ee: %i[] do
- it "shows the enterprise banner" do
+ it "shows the large enterprise banner" do
render_component
- expect(page).to have_enterprise_banner(:professional)
- end
-
- it "disables only automatic mode selector", :aggregate_failures do
- render_component
-
- expect(page.find("input[type=radio][value=generated]")).to be_disabled
- expect(page.find("input[type=radio][value=manual]")).not_to be_disabled
+ expect(page).to have_enterprise_banner(:professional, class: "op-enterprise-banner_large")
end
context "and when the subject is already automatically generated" do
let(:type) { create(:type, patterns: { subject: { blueprint: "Hello world", enabled: true } }) }
- it "shows the enterprise banner" do
+ it "shows the inline enterprise banner" do
render_component
- expect(page).to have_enterprise_banner(:professional)
+ expect(page).to have_enterprise_banner(:professional, class: "op-enterprise-banner_medium")
end
it "enables mode selectors", :aggregate_failures do
render_component
- expect(page.find("input[type=radio][value=generated]")).not_to be_disabled
+ expect(page.find("input[type=radio][value=generated]")).to be_disabled
expect(page.find("input[type=radio][value=manual]")).not_to be_disabled
end
end
diff --git a/spec/contracts/work_package_types/update_subject_pattern_contract_spec.rb b/spec/contracts/work_package_types/update_subject_pattern_contract_spec.rb
index 9da14e37127..37b5bc9ef6f 100644
--- a/spec/contracts/work_package_types/update_subject_pattern_contract_spec.rb
+++ b/spec/contracts/work_package_types/update_subject_pattern_contract_spec.rb
@@ -31,7 +31,7 @@
require "spec_helper"
module WorkPackageTypes
- RSpec.describe UpdateSubjectPatternContract do
+ RSpec.describe UpdateSubjectPatternContract, with_ee: [:work_package_subject_generation] do
let(:model) { create(:type, :with_subject_pattern) }
let(:user) { create(:admin) }
@@ -44,12 +44,28 @@ module WorkPackageTypes
expect(contract.validate).to be_falsey
end
- it "adds and error to the contract" do
+ it "adds an error to the contract" do
contract.validate
expect(contract.errors.details).to eq(base: [{ error: :error_unauthorized }])
end
end
+ context "if there is no enterprise token that allows subject configuration", with_ee: [] do
+ it "adds an error to the contract" do
+ contract.validate
+ expect(contract.errors.details)
+ .to eq(patterns: [{ action: "Work Package Subject Generation", error: :error_enterprise_only }])
+ end
+
+ context "with manual subject configuration" do
+ let(:model) { create(:type) }
+
+ it "succeeds" do
+ expect(contract.validate).to be_truthy
+ end
+ end
+ end
+
describe "subject_pattern validation" do
let(:valid_pattern) { { subject: { blueprint: "{{author}}", enabled: true } } }
let(:invalid_pattern) { { subject: { blueprint: "{{vader_s_rubber_duck}}", enabled: true } } }
diff --git a/spec/services/work_package_types/set_attributes_service_spec.rb b/spec/services/work_package_types/set_attributes_service_spec.rb
index aa764e2934d..28cc56da6ff 100644
--- a/spec/services/work_package_types/set_attributes_service_spec.rb
+++ b/spec/services/work_package_types/set_attributes_service_spec.rb
@@ -31,7 +31,7 @@
require "spec_helper"
module WorkPackageTypes
- RSpec.describe SetAttributesService do
+ RSpec.describe SetAttributesService, with_ee: [:work_package_subject_generation] do
let(:user) { create(:admin) }
let(:model) { create(:type, :with_subject_pattern) }
let(:params) { Hash.new }