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
[#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.rbindex 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 WorkPackageTypesclass UpdateSubjectPatternContract < BaseContractattribute :patterns+ validate :enterprise_editionvalidate :validate_subject_generation_patternprivate+ 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_patternblueprint = model.patterns.subject&.blueprintreturn 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.rbindex 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: :componentendcontext "when enterprise edition is not activated", with_ee: %i[] do- it "shows the enterprise banner" do+ it "shows the large enterprise banner" dorender_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")endcontext "and when the subject is already automatically generated" dolet(:type) { create(:type, patterns: { subject: { blueprint: "Hello world", enabled: true } }) }- it "shows the enterprise banner" do+ it "shows the inline enterprise banner" dorender_component- expect(page).to have_enterprise_banner(:professional)+ expect(page).to have_enterprise_banner(:professional, class: "op-enterprise-banner_medium")endit "enables mode selectors", :aggregate_failures dorender_component- expect(page.find("input[type=radio][value=generated]")).not_to be_disabled+ expect(page.find("input[type=radio][value=generated]")).to be_disabledexpect(page.find("input[type=radio][value=manual]")).not_to be_disabledendenddiff --git a/spec/contracts/work_package_types/update_subject_pattern_contract_spec.rb b/spec/contracts/work_package_types/update_subject_pattern_contract_spec.rbindex 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] dolet(:model) { create(:type, :with_subject_pattern) }let(:user) { create(:admin) }@@ -44,12 +44,28 @@ module WorkPackageTypesexpect(contract.validate).to be_falseyend- it "adds and error to the contract" do+ it "adds an error to the contract" docontract.validateexpect(contract.errors.details).to eq(base: [{ error: :error_unauthorized }])endend+ 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" dolet(: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.rbindex 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] dolet(:user) { create(:admin) }let(:model) { create(:type, :with_subject_pattern) }let(:params) { Hash.new }