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
[#53722] Only allow pcf to be created when there is at least one section
Tobias Dillmann2ef58e38ad35
diff --git a/app/components/settings/project_custom_fields/header_component.html.erb b/app/components/settings/project_custom_fields/header_component.html.erbindex cd7fd782258..66f06124012 100644--- a/app/components/settings/project_custom_fields/header_component.html.erb+++ b/app/components/settings/project_custom_fields/header_component.html.erb@@ -28,17 +28,19 @@content_arguments: { data: { controller: "async-dialog" } })- menu.with_sub_menu_item(label: t("settings.project_attributes.label_new_attribute")) do |sub_menu|- OpenProject::CustomFieldFormat.available_for_class_name("Project")- .sort_by(&:name)- .map do |format|- sub_menu.with_item(- label: helpers.label_for_custom_field_format(format.name),- tag: :a,- href: new_admin_settings_project_custom_field_path(field_format: format.name),- content_arguments: { data: { turbo: "false",- test_selector: "new-project-custom-field-button" } }- )+ if allow_custom_field_creation?+ menu.with_sub_menu_item(label: t("settings.project_attributes.label_new_attribute")) do |sub_menu|+ OpenProject::CustomFieldFormat.available_for_class_name("Project")+ .sort_by(&:name)+ .map do |format|+ sub_menu.with_item(+ label: helpers.label_for_custom_field_format(format.name),+ tag: :a,+ href: new_admin_settings_project_custom_field_path(field_format: format.name),+ content_arguments: { data: { turbo: "false",+ test_selector: "new-project-custom-field-button" } }+ )+ endendendenddiff --git a/app/components/settings/project_custom_fields/header_component.rb b/app/components/settings/project_custom_fields/header_component.rbindex 317c6fa5555..b46b6e36220 100644--- a/app/components/settings/project_custom_fields/header_component.rb+++ b/app/components/settings/project_custom_fields/header_component.rb@@ -34,11 +34,21 @@ module Settingsinclude OpTurbo::Streamableinclude CustomFieldsHelper+ def initialize(allow_custom_field_creation:)+ super++ @allow_custom_field_creation = allow_custom_field_creation+ end+def breadcrumbs_items[{ href: admin_index_path, text: t("label_administration") },{ href: admin_settings_project_custom_fields_path, text: t("label_project_plural") },t("settings.project_attributes.heading")]end++ def allow_custom_field_creation?+ @allow_custom_field_creation+ endendendenddiff --git a/app/controllers/admin/settings/project_custom_field_sections_controller.rb b/app/controllers/admin/settings/project_custom_field_sections_controller.rbindex 35646229f79..5865f99dbf3 100644--- a/app/controllers/admin/settings/project_custom_field_sections_controller.rb+++ b/app/controllers/admin/settings/project_custom_field_sections_controller.rb@@ -40,7 +40,7 @@ module Admin::Settings)if call.success?- update_header_via_turbo_stream # required to closed the dialog+ update_header_via_turbo_stream(allow_custom_field_creation: allow_custom_field_creation?)update_sections_via_turbo_stream(project_custom_field_sections: ProjectCustomFieldSection.all)elseupdate_section_dialog_body_form_via_turbo_stream(project_custom_field_section: call.result)@@ -67,6 +67,7 @@ module Admin::Settingscall = ::ProjectCustomFieldSections::DeleteService.new(user: current_user, model: @project_custom_field_section).callif call.success?+ update_header_via_turbo_stream(allow_custom_field_creation: allow_custom_field_creation?)update_sections_via_turbo_stream(project_custom_field_sections: ProjectCustomFieldSection.all)else# TODO: show error message@@ -95,6 +96,7 @@ module Admin::Settings)if call.success?+ update_header_via_turbo_stream(allow_custom_field_creation: allow_custom_field_creation?)update_sections_via_turbo_stream(project_custom_field_sections: ProjectCustomFieldSection.all)else# TODO: show error message@@ -112,6 +114,10 @@ module Admin::Settings@project_custom_field_section = ProjectCustomFieldSection.find(params[:id])end+ def allow_custom_field_creation?+ ProjectCustomFieldSection.any?+ end+def project_custom_field_section_paramsparams.require(:project_custom_field_section).permit(:name)enddiff --git a/app/controllers/admin/settings/project_custom_fields_controller.rb b/app/controllers/admin/settings/project_custom_fields_controller.rbindex a3e2330eb93..a841c4110b7 100644--- a/app/controllers/admin/settings/project_custom_fields_controller.rb+++ b/app/controllers/admin/settings/project_custom_fields_controller.rb@@ -48,6 +48,8 @@ module Admin::Settings# rubocop:enable Rails/LexicallyScopedActionFilterdef index+ @allow_custom_field_creation = @project_custom_field_sections.any?+respond_to :htmlenddiff --git a/app/controllers/concerns/admin/settings/project_custom_fields/component_streams.rb b/app/controllers/concerns/admin/settings/project_custom_fields/component_streams.rbindex b36b9b49c9e..37950b649e0 100644--- a/app/controllers/concerns/admin/settings/project_custom_fields/component_streams.rb+++ b/app/controllers/concerns/admin/settings/project_custom_fields/component_streams.rb@@ -33,9 +33,11 @@ module Adminextend ActiveSupport::Concernincluded do- def update_header_via_turbo_stream+ def update_header_via_turbo_stream(allow_custom_field_creation:)update_via_turbo_stream(- component: ::Settings::ProjectCustomFields::HeaderComponent.new+ component: ::Settings::ProjectCustomFields::HeaderComponent.new(+ allow_custom_field_creation:+ ))enddiff --git a/app/views/admin/settings/project_custom_fields/index.html.erb b/app/views/admin/settings/project_custom_fields/index.html.erbindex e8e72ebd3b5..526cf875437 100644--- a/app/views/admin/settings/project_custom_fields/index.html.erb+++ b/app/views/admin/settings/project_custom_fields/index.html.erb@@ -29,7 +29,7 @@ See COPYRIGHT and LICENSE files for more details.<% html_title t(:label_administration), t("settings.project_attributes.heading") %><div data-turbo="true">- <%= render(Settings::ProjectCustomFields::HeaderComponent.new) %>+ <%= render(Settings::ProjectCustomFields::HeaderComponent.new(allow_custom_field_creation: @allow_custom_field_creation)) %><%= render(Settings::ProjectCustomFieldSections::IndexComponent.new(project_custom_field_sections: @project_custom_field_sections