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
show enterprise banner for calculated value
Ivan Kuchin7973c77dd715
diff --git a/app/assets/videos/enterprise/calculated-values.mp4 b/app/assets/videos/enterprise/calculated-values.mp4new file mode 100644index 00000000000..01f765fd023Binary files /dev/null and b/app/assets/videos/enterprise/calculated-values.mp4 differdiff --git a/app/components/admin/custom_fields/calculated_values/details_component.html.erb b/app/components/admin/custom_fields/calculated_values/details_component.html.erbindex 6873ea2c605..6e434ae9cb3 100644--- a/app/components/admin/custom_fields/calculated_values/details_component.html.erb+++ b/app/components/admin/custom_fields/calculated_values/details_component.html.erb@@ -29,12 +29,14 @@ See COPYRIGHT and LICENSE files for more details.<%=component_wrapper do- settings_primer_form_with(- model:,- scope: :custom_field,- id: "custom_field_form",- url: form_url,- method: form_method- ) { |form| render CustomFields::CalculatedValues::DetailsForm.new(form) }+ with_enterprise_banner_guard(:calculated_values, variant: :large, video: "enterprise/calculated-values.mp4") do+ settings_primer_form_with(+ model:,+ scope: :custom_field,+ id: "custom_field_form",+ url: form_url,+ method: form_method+ ) { |form| render CustomFields::CalculatedValues::DetailsForm.new(form) }+ endend%>diff --git a/app/components/admin/custom_fields/calculated_values/details_component.rb b/app/components/admin/custom_fields/calculated_values/details_component.rbindex 74d88666d0f..f2c70c9bba5 100644--- a/app/components/admin/custom_fields/calculated_values/details_component.rb+++ b/app/components/admin/custom_fields/calculated_values/details_component.rb@@ -31,6 +31,7 @@module Admin::CustomFields::CalculatedValuesclass DetailsComponent < ApplicationComponentinclude ApplicationHelper+ include EnterpriseHelperinclude OpPrimer::ComponentHelpersinclude OpTurbo::Streamablediff --git a/app/components/settings/project_custom_field_sections/custom_field_row_component.rb b/app/components/settings/project_custom_field_sections/custom_field_row_component.rbindex 2ccd5c3870d..239dba9a6c9 100644--- a/app/components/settings/project_custom_field_sections/custom_field_row_component.rb+++ b/app/components/settings/project_custom_field_sections/custom_field_row_component.rb@@ -49,9 +49,17 @@ module Settingshref: edit_admin_settings_project_custom_field_path(@project_custom_field),data: { turbo: "false", test_selector: "project-custom-field-edit" }) do |item|item.with_leading_visual_icon(icon: :pencil)++ if show_enterprise_icon_for_edit_action?+ item.with_trailing_visual_icon(icon: :"op-enterprise-addons", classes: "upsell-colored")+ endendend+ def show_enterprise_icon_for_edit_action?+ @project_custom_field.field_format_calculated_value? && !EnterpriseToken.allows_to?(:calculated_values)+ end+def move_actions(menu)unless first?move_action_item(menu, :highest, t("label_agenda_item_move_to_top"),diff --git a/app/components/settings/project_custom_fields/edit_form_header_component.html.erb b/app/components/settings/project_custom_fields/edit_form_header_component.html.erbindex fc0ff62837f..a9eeafa8c8c 100644--- a/app/components/settings/project_custom_fields/edit_form_header_component.html.erb+++ b/app/components/settings/project_custom_fields/edit_form_header_component.html.erb@@ -29,7 +29,7 @@ See COPYRIGHT and LICENSE files for more details.<%=render(Primer::OpenProject::PageHeader.new) do |header|header.with_title { @custom_field.attribute_in_database("name") }- header.with_description { t("settings.project_attributes.edit.description") }+ header.with_description { t("settings.project_attributes.edit.description") } unless hide_description?header.with_breadcrumbs(breadcrumbs_items)helpers.render_tab_header_nav(header, tabs, test_selector: :project_attribute_detail_header)diff --git a/app/components/settings/project_custom_fields/edit_form_header_component.rb b/app/components/settings/project_custom_fields/edit_form_header_component.rbindex 4bddbab106f..159efb04cbc 100644--- a/app/components/settings/project_custom_fields/edit_form_header_component.rb+++ b/app/components/settings/project_custom_fields/edit_form_header_component.rb@@ -69,6 +69,10 @@ module Settings{ href: admin_settings_project_custom_fields_path, text: t("settings.project_attributes.heading") },@custom_field.attribute_in_database("name")]end++ def hide_description?+ @custom_field.field_format_calculated_value? && !EnterpriseToken.allows_to?(:calculated_values)+ endendendenddiff --git a/app/components/settings/project_custom_fields/header_component.html.erb b/app/components/settings/project_custom_fields/header_component.html.erbindex cf8ea3beb30..946d4e6c1c5 100644--- a/app/components/settings/project_custom_fields/header_component.html.erb+++ b/app/components/settings/project_custom_fields/header_component.html.erb@@ -45,7 +45,11 @@href: new_admin_settings_project_custom_field_path(field_format: format.name),content_arguments: { data: { turbo: "false",test_selector: "new-project-custom-field-button" } }- )+ ) do |item|+ if show_enterprise_icon?(format)+ item.with_trailing_visual_icon(icon: :"op-enterprise-addons", classes: "upsell-colored")+ end+ endendendenddiff --git a/app/components/settings/project_custom_fields/header_component.rb b/app/components/settings/project_custom_fields/header_component.rbindex e9f48896933..c0c605ac613 100644--- a/app/components/settings/project_custom_fields/header_component.rb+++ b/app/components/settings/project_custom_fields/header_component.rb@@ -51,6 +51,12 @@ module Settingsdef allow_custom_field_creation?@allow_custom_field_creationend++ def show_enterprise_icon?(custom_field_format)+ if custom_field_format.name == "calculated_value"+ !EnterpriseToken.allows_to?(:calculated_values)+ end+ endendendenddiff --git a/app/components/settings/project_custom_fields/new_form_header_component.html.erb b/app/components/settings/project_custom_fields/new_form_header_component.html.erbindex 85fe507eb96..01e7fc54296 100644--- a/app/components/settings/project_custom_fields/new_form_header_component.html.erb+++ b/app/components/settings/project_custom_fields/new_form_header_component.html.erb@@ -30,7 +30,7 @@ See COPYRIGHT and LICENSE files for more details.<%=render(Primer::OpenProject::PageHeader.new) do |header|header.with_title { t("settings.project_attributes.new.heading") }- header.with_description { t("settings.project_attributes.new.description") }+ header.with_description { t("settings.project_attributes.new.description") } unless hide_description?header.with_breadcrumbs(breadcrumb_items, selected_item_font_weight: :normal)end%>diff --git a/app/components/settings/project_custom_fields/new_form_header_component.rb b/app/components/settings/project_custom_fields/new_form_header_component.rbindex 04c3597d348..ef41034fb11 100644--- a/app/components/settings/project_custom_fields/new_form_header_component.rb+++ b/app/components/settings/project_custom_fields/new_form_header_component.rb@@ -40,6 +40,10 @@ module Settingst("settings.project_attributes.new.heading"))]end++ def hide_description?+ model.field_format_calculated_value? && !EnterpriseToken.allows_to?(:calculated_values)+ endendendenddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 0f7e33be58e..ca5dd1b589b 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -2300,6 +2300,7 @@ en:features:baseline_comparison: Baseline Comparisonsboard_view: Advanced Boards+ calculated_values: Calculated Valuesconditional_highlighting: Conditional Highlightinginternal_comments: Internal Commentscustom_actions: Custom Actions@@ -2373,6 +2374,8 @@ en:description: "Share work packages with users who are not members of the project."project_list_sharing:description: "Share project lists with individual users."+ calculated_values:+ description: "Calculated Values allow you to create a mathematical formula based attribute using numeric values and other project attributes and custom fields."define_custom_style:title: "Custom color theme and logo"more_info: "Note: the used logo will be publicly accessible."diff --git a/spec/features/admin/custom_fields/projects/calculated_value_spec.rb b/spec/features/admin/custom_fields/projects/calculated_value_spec.rbindex 11f83cde5d3..54f8c80b700 100644--- a/spec/features/admin/custom_fields/projects/calculated_value_spec.rb+++ b/spec/features/admin/custom_fields/projects/calculated_value_spec.rb@@ -67,106 +67,115 @@ RSpec.describe "Edit project custom field calculated value", :js, with_flag: { cendend- it "allows to change basic attributes and the section of the calculated value" do- expect(page).to have_css(".PageHeader-title", text: calculated_value.name)+ context "without calculated_values enterprise feature" do+ it do+ expect(page)+ .to have_enterprise_banner(:premium)+ .and have_no_field("custom_field_name")+ .and have_no_button("Save")+ end+ end- fill_in("custom_field_name", with: "Updated name", fill_options: { clear: :backspace })- select(section_for_select_fields.name, from: "custom_field_custom_field_section_id")- find_field(id: "custom_field_formula", type: :hidden).set("1 + 1")+ context "with calculated_values enterprise feature", with_ee: %i[calculated_values] do+ it "allows to change basic attributes and the section of the calculated value" do+ expect(page).to have_css(".PageHeader-title", text: calculated_value.name)- click_on "Save"+ fill_in("custom_field_name", with: "Updated name", fill_options: { clear: :backspace })+ select(section_for_select_fields.name, from: "custom_field_custom_field_section_id")+ find_field(id: "custom_field_formula", type: :hidden).set("1 + 1")- expect(page).to have_text("Successful update")+ click_on "Save"- expect(page).to have_css(".PageHeader-title", text: "Updated name")+ expect(page).to have_text("Successful update")- expect(calculated_value.reload.name).to eq("Updated name")- expect(calculated_value.reload.project_custom_field_section).to eq(section_for_select_fields)- expect(calculated_value.reload.formula_string).to eq("1 + 1")+ expect(page).to have_css(".PageHeader-title", text: "Updated name")- within ".PageHeader-breadcrumbs" do- expect(page).to have_link("Administration")- expect(page).to have_link("Projects")- expect(page).to have_link("Project attributes")- expect(page).to have_text("Updated name")+ expect(calculated_value.reload.name).to eq("Updated name")+ expect(calculated_value.reload.project_custom_field_section).to eq(section_for_select_fields)+ expect(calculated_value.reload.formula_string).to eq("1 + 1")++ within ".PageHeader-breadcrumbs" do+ expect(page).to have_link("Administration")+ expect(page).to have_link("Projects")+ expect(page).to have_link("Project attributes")+ expect(page).to have_text("Updated name")+ endend- end- it "prevents saving a calculated value with an empty name" do- original_name = calculated_value.name+ it "prevents saving a calculated value with an empty name" do+ original_name = calculated_value.name- fill_in("custom_field_name", with: "")- click_on "Save"+ fill_in("custom_field_name", with: "")+ click_on "Save"- expect(page).to have_text("Name can't be blank")+ expect(page).to have_text("Name can't be blank")- expect(page).to have_no_text("Successful update")+ expect(page).to have_no_text("Successful update")- expect(page).to have_css(".PageHeader-title", text: original_name)- expect(calculated_value.reload.name).to eq(original_name)- end+ expect(page).to have_css(".PageHeader-title", text: original_name)+ expect(calculated_value.reload.name).to eq(original_name)+ end- it "prevents saving a calculated value with an empty formula" do- original_formula = calculated_value.formula_string+ it "prevents saving a calculated value with an empty formula" do+ original_formula = calculated_value.formula_string- find_field(id: "custom_field_formula", type: :hidden).set("")- click_on "Save"+ find_field(id: "custom_field_formula", type: :hidden).set("")+ click_on "Save"- expect(page).to have_text("Formula can't be blank")- expect(page).to have_no_text("Successful update")+ expect(page).to have_text("Formula can't be blank")+ expect(page).to have_no_text("Successful update")- expect(calculated_value.reload.formula_string).to eq(original_formula)- end+ expect(calculated_value.reload.formula_string).to eq(original_formula)+ end- it "allows submitting formula by pressing Enter/Return" do- # ensure multiple spaces are handled without problems- formula = "2 + (1 +1)"+ it "allows submitting formula by pressing Enter/Return" do+ # ensure multiple spaces are handled without problems+ formula = "2 + (1 +1)"- pattern_input = find(:xpath, "//input[@id='custom_field_formula']/parent::div//div[@contenteditable='true']")+ pattern_input = find(:xpath, "//input[@id='custom_field_formula']/parent::div//div[@contenteditable='true']")- pattern_input.set("#{formula}\n")+ pattern_input.set("#{formula}\n")- expect(page).to have_text("Successful update")+ expect(page).to have_text("Successful update")- expect(calculated_value.reload.formula_string).to eq(formula)- end+ expect(calculated_value.reload.formula_string).to eq(formula)+ end- context "when editing the formula" do- using CustomFieldFormulaReferencing+ context "when editing the formula" do+ using CustomFieldFormulaReferencing- it "allows using the pattern input component" do- expect(page).to have_css(".PageHeader-title", text: calculated_value.name)+ it "allows using the pattern input component" do+ expect(page).to have_css(".PageHeader-title", text: calculated_value.name)- expect(page).to have_css("input#custom_field_formula[value='#{integer_project_custom_field} * 2']",- visible: :hidden)+ expect(page).to have_css("input#custom_field_formula[value='#{integer_project_custom_field} * 2']",+ visible: :hidden)- # Suggestions drop down is hidden- expect(page).to have_no_css(".op-pattern-input--suggestions-dropdown .ActionListItem")+ # Suggestions drop down is hidden+ expect(page).to have_no_css(".op-pattern-input--suggestions-dropdown .ActionListItem")- pattern_input = page.find(".op-pattern-input--text-field")- pattern_input.click- pattern_input.send_keys(" + ")- expect(page).to have_no_css(".op-pattern-input--suggestions-dropdown .ActionListItem")+ pattern_input = page.find(".op-pattern-input--text-field")+ pattern_input.click+ pattern_input.send_keys(" + ")+ expect(page).to have_no_css(".op-pattern-input--suggestions-dropdown .ActionListItem")- # Open suggestion list- pattern_input.send_keys("/")- within ".op-pattern-input--suggestions-dropdown" do- expect(page).to have_css(".ActionListItem", text: float_project_custom_field.name)- click_on(float_project_custom_field.name)- end+ # Open suggestion list+ pattern_input.send_keys("/")+ within ".op-pattern-input--suggestions-dropdown" do+ expect(page).to have_css(".ActionListItem", text: float_project_custom_field.name)+ click_on(float_project_custom_field.name)+ end- click_on("Save")- wait_for_network_idle+ click_on("Save")+ wait_for_network_idle- new_formula = calculated_value.reload.formula_string- expect(new_formula).to eq("#{integer_project_custom_field} * 2 + #{float_project_custom_field}")+ new_formula = calculated_value.reload.formula_string+ expect(new_formula).to eq("#{integer_project_custom_field} * 2 + #{float_project_custom_field}")+ endendendend- context "without the feature flag", with_flag: { calculated_value_project_attribute: false } do- let!(:calculated_value) { nil }-+ context "without the feature flag", with_ee: %i[calculated_values], with_flag: { calculated_value_project_attribute: false } doit "prevents saving a calculated value" doexpect dologin_as(admin)diff --git a/spec/features/admin/custom_fields/projects/create_in_section_spec.rb b/spec/features/admin/custom_fields/projects/create_in_section_spec.rbindex a004f75c9fe..6eaf3a77cfc 100644--- a/spec/features/admin/custom_fields/projects/create_in_section_spec.rb+++ b/spec/features/admin/custom_fields/projects/create_in_section_spec.rb@@ -49,78 +49,122 @@ RSpec.describe "Create project custom fields in sections", :js dobefore dologin_as(admin)cf_index_page.visit!-- cf_index_page.click_to_create_new_custom_field("Integer")end- it "shows a correct breadcrumb menu" do- within ".PageHeader-breadcrumbs" do- expect(page).to have_link("Administration")- expect(page).to have_link("Projects")- expect(page).to have_link("Project attributes")- expect(page).to have_text("Integer: New attribute")+ context "when trying to create Integer custom field" do+ before do+ cf_index_page.click_to_create_new_custom_field("Integer")end- end- it "allows to create a new project custom field with an associated section" do- # TODO: reuse specs for classic custom field form in order to test for other attribute settings- expect(page).to have_css(".PageHeader-title", text: "New attribute")+ it "shows a correct breadcrumb menu" do+ within ".PageHeader-breadcrumbs" do+ expect(page).to have_link("Administration")+ expect(page).to have_link("Projects")+ expect(page).to have_link("Project attributes")+ expect(page).to have_text("Integer: New attribute")+ end+ end- fill_in("custom_field_name", with: "New custom field")- select(section_for_select_fields.name, from: "custom_field_custom_field_section_id")- check "Admin-only"+ it "allows to create a new project custom field with an associated section" do+ # TODO: reuse specs for classic custom field form in order to test for other attribute settings+ expect(page).to have_css(".PageHeader-title", text: "New attribute")- click_on("Save")+ fill_in("custom_field_name", with: "New custom field")+ select(section_for_select_fields.name, from: "custom_field_custom_field_section_id")+ check "Admin-only"- # redirects to the overview page- # the tab parameter is set as the redirect originates from the former custom field controller but does not have an effect- expect(page).to have_current_path(admin_settings_project_custom_fields_path(tab: "ProjectCustomField"))+ click_on("Save")- expect(page).to have_text("New custom field")+ # redirects to the overview page+ # the tab parameter is set as the redirect originates from the former custom field controller but does not have an effect+ expect(page).to have_current_path(admin_settings_project_custom_fields_path(tab: "ProjectCustomField"))- latest_custom_field = ProjectCustomField.reorder(created_at: :asc).last+ expect(page).to have_text("New custom field")- expect(latest_custom_field.name).to eq("New custom field")- expect(latest_custom_field.admin_only).to be(true)- expect(latest_custom_field.project_custom_field_section).to eq(section_for_select_fields)- end+ latest_custom_field = ProjectCustomField.reorder(created_at: :asc).last- it "allows to create a new project custom field with a prefilled section via url param" do- visit new_admin_settings_project_custom_field_path(field_format: "int",- custom_field_section_id: section_for_multi_select_fields.id)+ expect(latest_custom_field.name).to eq("New custom field")+ expect(latest_custom_field.admin_only).to be(true)+ expect(latest_custom_field.project_custom_field_section).to eq(section_for_select_fields)+ end- fill_in("custom_field_name", with: "New custom field")+ it "allows to create a new project custom field with a prefilled section via url param" do+ visit new_admin_settings_project_custom_field_path(field_format: "int",+ custom_field_section_id: section_for_multi_select_fields.id)- click_on("Save")+ fill_in("custom_field_name", with: "New custom field")- # redirects to the overview page- # the tab parameter is set as the redirect originates from the former custom field controller but does not have an effect- expect(page).to have_current_path(admin_settings_project_custom_fields_path(tab: "ProjectCustomField"))+ click_on("Save")- latest_custom_field = ProjectCustomField.reorder(created_at: :asc).last+ # redirects to the overview page+ # the tab parameter is set as the redirect originates from the former custom field controller but does not have an effect+ expect(page).to have_current_path(admin_settings_project_custom_fields_path(tab: "ProjectCustomField"))- expect(latest_custom_field.name).to eq("New custom field")- expect(latest_custom_field.project_custom_field_section).to eq(section_for_multi_select_fields)- end+ latest_custom_field = ProjectCustomField.reorder(created_at: :asc).last- it "prevents creating a new project custom field with an empty name" do- click_on("Save")+ expect(latest_custom_field.name).to eq("New custom field")+ expect(latest_custom_field.project_custom_field_section).to eq(section_for_multi_select_fields)+ end++ it "prevents creating a new project custom field with an empty name" do+ click_on("Save")- expect(page).to have_field "custom_field_name", validation_message: /Please fill (in|out) this field./+ expect(page).to have_field "custom_field_name", validation_message: /Please fill (in|out) this field./++ # expect no redirect+ expect(page).to have_no_current_path(admin_settings_project_custom_fields_path(tab: "ProjectCustomField"))+ expect(page).to have_current_path(new_admin_settings_project_custom_field_path(field_format: "int"))+ end- # expect no redirect- expect(page).to have_no_current_path(admin_settings_project_custom_fields_path(tab: "ProjectCustomField"))- expect(page).to have_current_path(new_admin_settings_project_custom_field_path(field_format: "int"))+ context "without any existing sections" do+ before do+ ProjectCustomFieldSection.destroy_all+ cf_index_page.visit!+ end++ it "prevents creating a new project custom field" do+ cf_index_page.expect_no_add_project_attribute_submenu+ end+ endend- context "without any existing sections" do- before do- ProjectCustomFieldSection.destroy_all- cf_index_page.visit!+ context "when trying to create calculated value field" do+ context "without the feature flag", with_flag: { calculated_value_project_attribute: false } do+ it "prevents creation" do+ cf_index_page.expect_not_having_create_item "Calculated Value"+ endend- it "prevents creating a new project custom field" do- cf_index_page.expect_no_add_project_attribute_submenu+ context "with the feature flag", with_flag: { calculated_value_project_attribute: true } do+ before do+ cf_index_page.click_to_create_new_custom_field "Calculated Value"+ end++ context "without calculated_values enterprise feature" do+ it do+ expect(page)+ .to have_enterprise_banner(:premium)+ .and have_no_field("custom_field_name")+ .and have_no_button("Save")+ end+ end++ context "with calculated_values enterprise feature", with_ee: %i[calculated_values] do+ it "allows creation" do+ fill_in("custom_field_name", with: "New calculated value custom field")+ select(section_for_select_fields.name, from: "custom_field_custom_field_section_id")+ find_field(id: "custom_field_formula", type: :hidden).set("1 + 1")++ click_on("Save")++ # redirects to the overview page+ # the tab parameter is set as the redirect originates from the+ # former custom field controller but does not have an effect+ expect(page).to have_current_path(admin_settings_project_custom_fields_path(tab: "ProjectCustomField"))++ expect(page).to have_text("New calculated value custom field")+ end+ endendendenddiff --git a/spec/features/admin/custom_fields/projects/index_spec.rb b/spec/features/admin/custom_fields/projects/index_spec.rbindex dafcee06000..4badb0f0c33 100644--- a/spec/features/admin/custom_fields/projects/index_spec.rb+++ b/spec/features/admin/custom_fields/projects/index_spec.rb@@ -158,8 +158,14 @@ RSpec.describe "List project custom fields", :js dodescribe "managing project custom fields" docontext "with calculated value feature flag active", with_flag: { calculated_value_project_attribute: true } do- it "offers the type for creation" do- cf_index_page.expect_having_create_item(I18n.t("label_calculated_value"))+ it "offers the type for creation with enterprise icon" do+ cf_index_page.expect_having_create_item(I18n.t("label_calculated_value"), enterprise_icon: true)+ end++ context "with enterprise feature calculated_values", with_ee: %i[calculated_values] do+ it "offers the type for creation without enterprise icon" do+ cf_index_page.expect_having_create_item(I18n.t("label_calculated_value"), enterprise_icon: false)+ endendcontext "with fields of type calculated value" dodiff --git a/spec/support/pages/admin/settings/project_custom_fields/index.rb b/spec/support/pages/admin/settings/project_custom_fields/index.rbindex fca26abf44b..aafa65b4d01 100644--- a/spec/support/pages/admin/settings/project_custom_fields/index.rb+++ b/spec/support/pages/admin/settings/project_custom_fields/index.rb@@ -69,7 +69,7 @@ module Pagesclick_on typeend- def expect_having_create_item(type)+ def expect_having_create_item(type, enterprise_icon:)wait_for_network_idleclick_button "Add"@@ -77,6 +77,12 @@ module Pagesclick_button "Project attribute"expect(page).to have_link(type)++ if enterprise_icon+ expect(page.find(:link, type)).to have_css(".octicon-op-enterprise-addons.upsell-colored")+ else+ expect(page.find(:link, type)).to have_no_css(".octicon-op-enterprise-addons.upsell-colored")+ endenddef expect_not_having_create_item(type)