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
On new CF page, show enterprise banner only for hierarchy type
Christophe Bliardf1ca6765f08b
diff --git a/app/views/custom_fields/new.html.erb b/app/views/custom_fields/new.html.erbindex 1fd6d04aa3e..aac6a2f74dc 100644--- a/app/views/custom_fields/new.html.erb+++ b/app/views/custom_fields/new.html.erb@@ -46,8 +46,7 @@ See COPYRIGHT and LICENSE files for more details.<% content_controller "admin--custom-fields",dynamic: true,"admin--custom-fields-format-config-value": OpenProject::CustomFieldFormatDependent.stimulus_config,- "admin--custom-fields-enterprise-edition-value": !EnterpriseToken.allows_to?(:custom_field_hierarchies) || EnterpriseToken.trialling?(:custom_field_hierarchies),- "admin--custom-fields-hierarchy-enabled-value": EnterpriseToken.allows_to?(:custom_field_hierarchies) || EnterpriseToken.trialling?(:custom_field_hierarchies) %>+ "admin--custom-fields-hierarchy-enabled-value": EnterpriseToken.allows_to?(:custom_field_hierarchies) %><%= labelled_tabular_form_for @custom_field, as: :custom_field,url: custom_fields_path,diff --git a/frontend/src/stimulus/controllers/dynamic/admin/custom-fields.controller.ts b/frontend/src/stimulus/controllers/dynamic/admin/custom-fields.controller.tsindex 325e12db1d6..06b8ac05944 100644--- a/frontend/src/stimulus/controllers/dynamic/admin/custom-fields.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/admin/custom-fields.controller.ts@@ -55,12 +55,10 @@ export default class CustomFieldsController extends Controller {static values = {formatConfig: Array,- enterpriseEdition: Boolean,hierarchyEnabled: Boolean,};declare readonly formatConfigValue:[string, string, string[]][];- declare readonly enterpriseEditionValue:boolean;declare readonly hierarchyEnabledValue:boolean;declare readonly formatTarget:HTMLInputElement;@@ -258,10 +256,7 @@ export default class CustomFieldsController extends Controller {}this.formatConfigValue.forEach(([targetsName, operator, formats]) => {- let active = operator === 'only' ? formats.includes(format) : !formats.includes(format);- if (targetsName === 'enterpriseBanner') {- active = this.enterpriseEditionValue;- }+ const active = operator === 'only' ? formats.includes(format) : !formats.includes(format);const targets = this[`${targetsName}Targets` as keyof typeof this] as HTMLElement[];if (targets) {diff --git a/spec/features/custom_fields/custom_fields_spec.rb b/spec/features/custom_fields/custom_fields_spec.rbindex b33ce403253..14b99d7473d 100644--- a/spec/features/custom_fields/custom_fields_spec.rb+++ b/spec/features/custom_fields/custom_fields_spec.rb@@ -80,6 +80,7 @@ RSpec.describe "custom fields", :js dolabel_possible_values = I18n.t("activerecord.attributes.custom_field.possible_values").upcase # Possible values, capitalized on UIlabel_default_value = I18n.t("activerecord.attributes.custom_field.default_value") # Default valuelabel_is_required = I18n.t("activerecord.attributes.custom_field.is_required") # Required+ label_ee_banner_hierarchy = I18n.t("ee.upsell.custom_field_hierarchies.description") # Hierarchy Enterprise banner# Spent time SFs don't show "Searchable". Not tested here.# Project CFs don't show "For all projects" and "Used as a filter". Not tested here.# Content right to left is not shown for Project CFs Long text. Strange. Not tested.@@ -101,7 +102,7 @@ RSpec.describe "custom fields", :js dolabel_min_length, label_max_length, label_regexp, label_default_value, label_is_required)expect_page_not_to_have_texts(- label_multi_value, label_allow_non_open_versions, label_possible_values+ label_multi_value, label_allow_non_open_versions, label_possible_values, label_ee_banner_hierarchy)select "Long text", from: "custom_field_field_format"@@ -109,7 +110,7 @@ RSpec.describe "custom fields", :js dolabel_min_length, label_max_length, label_regexp, label_default_value, label_is_required)expect_page_not_to_have_texts(- label_multi_value, label_allow_non_open_versions, label_possible_values+ label_multi_value, label_allow_non_open_versions, label_possible_values, label_ee_banner_hierarchy)# Both Integer and Float have min/max_len and regex as well which seems strange.@@ -118,7 +119,7 @@ RSpec.describe "custom fields", :js dolabel_min_length, label_max_length, label_regexp, label_default_value, label_is_required)expect_page_not_to_have_texts(- label_multi_value, label_allow_non_open_versions, label_possible_values+ label_multi_value, label_allow_non_open_versions, label_possible_values, label_ee_banner_hierarchy)select "Float", from: "custom_field_field_format"@@ -126,7 +127,7 @@ RSpec.describe "custom fields", :js dolabel_min_length, label_max_length, label_regexp, label_default_value, label_is_required)expect_page_not_to_have_texts(- label_multi_value, label_allow_non_open_versions, label_possible_values+ label_multi_value, label_allow_non_open_versions, label_possible_values, label_ee_banner_hierarchy)select "List", from: "custom_field_field_format"@@ -134,14 +135,16 @@ RSpec.describe "custom fields", :js dolabel_multi_value, label_possible_values, label_is_required)expect_page_not_to_have_texts(- label_min_length, label_max_length, label_regexp, label_allow_non_open_versions, label_default_value+ label_min_length, label_max_length, label_regexp, label_allow_non_open_versions,+ label_default_value, label_ee_banner_hierarchy)select "Date", from: "custom_field_field_format"expect_page_to_have_texts(label_is_required)expect_page_not_to_have_texts(label_min_length, label_max_length, label_regexp, label_multi_value,- label_allow_non_open_versions, label_possible_values, label_default_value+ label_allow_non_open_versions, label_possible_values, label_default_value,+ label_ee_banner_hierarchy)select "Boolean", from: "custom_field_field_format"@@ -150,7 +153,7 @@ RSpec.describe "custom fields", :js do)expect_page_not_to_have_texts(label_min_length, label_max_length, label_regexp, label_multi_value,- label_allow_non_open_versions, label_possible_values+ label_allow_non_open_versions, label_possible_values, label_ee_banner_hierarchy)select "User", from: "custom_field_field_format"@@ -159,7 +162,7 @@ RSpec.describe "custom fields", :js do)expect_page_not_to_have_texts(label_min_length, label_max_length, label_regexp, label_allow_non_open_versions,- label_possible_values, label_default_value+ label_possible_values, label_default_value, label_ee_banner_hierarchy)select "Version", from: "custom_field_field_format"@@ -168,8 +171,20 @@ RSpec.describe "custom fields", :js do)expect_page_not_to_have_texts(label_min_length, label_max_length, label_regexp,- label_possible_values, label_default_value+ label_possible_values, label_default_value, label_ee_banner_hierarchy)++ if hierarchy_type_available+ select "Hierarchy", from: "custom_field_field_format"+ expect_page_to_have_texts(+ label_multi_value, label_is_required, label_ee_banner_hierarchy+ )+ expect_page_not_to_have_texts(+ label_min_length, label_max_length, label_regexp, label_allow_non_open_versions,+ label_possible_values, label_default_value+ )+ expect(page).to have_button("Save", disabled: true)+ endendit "shows the correct breadcrumbs" do@@ -186,14 +201,53 @@ RSpec.describe "custom fields", :js doenddescribe "work packages" do+ let(:hierarchy_type_available) { true }+it_behaves_like "creating a new custom field", "Work packages"++ context "for hierarchy type" do+ before do+ cf_page.visit_tab "Work packages"++ click_on "Create a new custom field"+ wait_for_reload+ cf_page.set_name "Ignored"++ select "Hierarchy", from: "custom_field_field_format"+ end++ context "with an active enterprise token with custom_field_hierarchies feature", with_ee: [:custom_field_hierarchies] do+ it "does not show the enterprise upsell banner and can save" do+ expect(page).to have_no_text(I18n.t("ee.upsell.custom_field_hierarchies.description"))+ expect(page).to have_button("Save", disabled: false)+ end+ end++ context "with an active enterprise token without custom_field_hierarchies feature", with_ee: [:another_feature] do+ it "shows the enterprise upsell banner and cannot save" do+ expect(page).to have_text(I18n.t("ee.upsell.custom_field_hierarchies.description"))+ expect(page).to have_button("Save", disabled: true)+ end+ end++ context "with a trial enterprise token", :with_ee_trial, with_ee: [:custom_field_hierarchies] do+ it "shows the enterprise upsell banner and can save" do+ expect(page).to have_text(I18n.t("ee.upsell.custom_field_hierarchies.description"))+ expect(page).to have_button("Save", disabled: false)+ end+ end+ endenddescribe "time entries" do+ let(:hierarchy_type_available) { false }+it_behaves_like "creating a new custom field", "Spent time"enddescribe "versions" do+ let(:hierarchy_type_available) { false }+it_behaves_like "creating a new custom field", "Versions"end@@ -255,7 +309,7 @@ RSpec.describe "custom fields", :js docheck("custom_field_multi_value")check("custom_field_custom_options_attributes_0_default_value")check("custom_field_custom_options_attributes_2_default_value")- within all(".custom-option-row").first do+ within first(".custom-option-row") doclick_on "Move to bottom"endclick_on "Save"diff --git a/spec/support/shared/with_ee.rb b/spec/support/shared/with_ee.rbindex 6787551dfa4..4c2689238f0 100644--- a/spec/support/shared/with_ee.rb+++ b/spec/support/shared/with_ee.rb@@ -47,7 +47,7 @@ endRSpec.configure do |config|config.before do |example|allowed = ee_actions(example)- if allowed.present?+ if allowed.present? || example.metadata[:with_ee_trial]allowed = aggregate_parent_array(example, allowed.to_set)token_double = instance_double(EnterpriseToken)@@ -65,7 +65,7 @@ RSpec.configure do |config|.to receive_messages(token_object: token_object_double,available_features: allowed.to_a,expired?: false,- trial?: false,+ trial?: !!example.metadata[:with_ee_trial],restrictions: {})endend