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
refactoring and name fixes
Jonas Jabarid568b5c783b9
diff --git a/app/contracts/projects/base_contract.rb b/app/contracts/projects/base_contract.rbindex 4b64a68872e..49e55622adc 100644--- a/app/contracts/projects/base_contract.rb+++ b/app/contracts/projects/base_contract.rb@@ -50,8 +50,8 @@ module Projectsvalidate_templated_set_by_adminend- attribute :touched_custom_field_section_id- # `touched_custom_field_section_id` used in Projects::ActsAsCustomizablePatches in order to+ attribute :limit_custom_fields_validation_to_section_id+ # `limit_custom_fields_validation_to_section_id` used in Projects::ActsAsCustomizablePatches in order to# only validate custom fields of the touched sectionvalidate :validate_user_allowed_to_managediff --git a/app/models/projects/acts_as_customizable_patches.rb b/app/models/projects/acts_as_customizable_patches.rbindex 81963e4bb15..6e0fb7a015c 100644--- a/app/models/projects/acts_as_customizable_patches.rb+++ b/app/models/projects/acts_as_customizable_patches.rb@@ -29,7 +29,10 @@module Projects::ActsAsCustomizablePatchesextend ActiveSupport::Concern- attr_accessor :touched_custom_field_section_id+ attr_accessor :limit_custom_fields_validation_to_section_id++ # attr_accessor :limit_custom_fields_validation_to_field_id+ # not needed for now, but might be relevant if we want to have edit dialogs just for one custom fieldincluded dodef active_custom_field_ids_of_project@@ -47,6 +50,11 @@ module Projects::ActsAsCustomizablePatches.where(id: active_custom_field_ids_of_project)end+ def available_project_custom_fields_grouped_by_section+ sorted_available_custom_fields+ .group_by(&:custom_field_section_id)+ end+def available_custom_fields_by_section(section)available_custom_fields.where(custom_field_section_id: section.id)@@ -75,22 +83,22 @@ module Projects::ActsAsCustomizablePatchesdef validate_custom_values# overrides acts_as_customizable- # validate custom values only of the touched section+ # validate custom values only of a specified section# instead of validating ALL custom values like done in acts_as_customizableset_default_values! if new_record?custom_field_values- .select { |custom_value| of_touched_custom_field_section?(custom_value) }+ .select { |custom_value| of_specified_custom_field_section?(custom_value) }.reject(&:marked_for_destruction?).select(&:invalid?).each { |custom_value| add_custom_value_errors! custom_value }end- def of_touched_custom_field_section?(custom_value)- if touched_custom_field_section_id.present?- custom_field_section_ids[custom_value.custom_field_id] == touched_custom_field_section_id+ def of_specified_custom_field_section?(custom_value)+ if limit_custom_fields_validation_to_section_id.present?+ custom_field_section_ids[custom_value.custom_field_id] == limit_custom_fields_validation_to_section_idelse- true # validate all custom values if no specific section was marked as touched via `update_custom_field_values_of_section`+ true # validate all custom values if no specific section was specifiedendendenddiff --git a/frontend/src/app/features/overview/overview.component.ts b/frontend/src/app/features/overview/overview.component.tsindex d0de3b2f2b8..fcfdbe3ecdc 100644--- a/frontend/src/app/features/overview/overview.component.ts+++ b/frontend/src/app/features/overview/overview.component.ts@@ -18,11 +18,11 @@ export class OverviewComponent extends GridPageComponent {}protected turboFrameSidebarSrc():string {- return `${this.pathHelper.staticBase}/projects/${this.currentProject.identifier!}/attributes_sidebar`;+ return `${this.pathHelper.staticBase}/projects/${this.currentProject.identifier!}/project_custom_fields_sidebar`;}protected turboFrameSidebarId():string {- return "project-attributes-sidebar";+ return "project-custom-fields-sidebar";}protected gridScopePath():string {diff --git a/modules/overviews/app/components/project_custom_fields/sections/edit_dialog_component.html.erb b/modules/overviews/app/components/project_custom_fields/sections/edit_dialog_component.html.erbindex c183a723f97..42078c509cc 100644--- a/modules/overviews/app/components/project_custom_fields/sections/edit_dialog_component.html.erb+++ b/modules/overviews/app/components/project_custom_fields/sections/edit_dialog_component.html.erb@@ -1,11 +1,11 @@<%=- content_tag("turbo-frame", id: "edit-project-attributes-dialog-#{@project_custom_field_section.id}-frame") do+ content_tag("turbo-frame", id: "edit-project-custom-fields-dialog-#{@project_custom_field_section.id}-frame") docomponent_wrapper(data: { qa_selector: 'async-dialog-content' }) doprimer_form_with(model: @project,method: :put,- url: project_update_attributes_path(project_id: @project.id, section_id: @project_custom_field_section.id),+ url: update_project_custom_values_path(project_id: @project.id, section_id: @project_custom_field_section.id),) do |f|component_collection do |collection|collection.with_component(Primer::Alpha::Dialog::Body.new(my: 3, style: "max-height: 500px;")) do@@ -15,7 +15,7 @@component_collection do |footer_collection|footer_collection.with_component(Primer::ButtonComponent.new(data: {- 'close-dialog-id': "edit-project-attributes-dialog-#{@project_custom_field_section.id}"+ 'close-dialog-id': "edit-project-custom-fields-dialog-#{@project_custom_field_section.id}"})) dot("button_cancel")diff --git a/modules/overviews/app/components/project_custom_fields/sections/show_component.html.erb b/modules/overviews/app/components/project_custom_fields/sections/show_component.html.erbindex 3a573264c34..0d114a622a6 100644--- a/modules/overviews/app/components/project_custom_fields/sections/show_component.html.erb+++ b/modules/overviews/app/components/project_custom_fields/sections/show_component.html.erb@@ -11,8 +11,8 @@heading.with_column dorender(OpTurbo::OpPrimer::AsyncDialogComponent.new(- id: "edit-project-attributes-dialog-#{@project_custom_field_section.id}",- src: project_attribute_section_dialog_path(project_id: @project.id, section_id: @project_custom_field_section.id),+ id: "edit-project-custom-fields-dialog-#{@project_custom_field_section.id}",+ src: project_custom_field_section_dialog_path(project_id: @project.id, section_id: @project_custom_field_section.id),size: :medium_portrait,title: @project_custom_field_section.name,button_icon: :pencil,diff --git a/modules/overviews/app/components/project_custom_fields/sidebar_component.html.erb b/modules/overviews/app/components/project_custom_fields/sidebar_component.html.erbindex ebbe0447486..dabcd20a885 100644--- a/modules/overviews/app/components/project_custom_fields/sidebar_component.html.erb+++ b/modules/overviews/app/components/project_custom_fields/sidebar_component.html.erb@@ -1,9 +1,9 @@<%=- content_tag("turbo-frame", id: "project-attributes-sidebar") do+ content_tag("turbo-frame", id: "project-custom-fields-sidebar") docomponent_wrapper do- if @active_project_custom_fields_grouped_by_section.any?- flex_layout(data: { qa_selector: "project-attributes-sidebar-async-content" }) do |sections_container|- @active_project_custom_fields_grouped_by_section.each do |project_custom_field_section_id, project_custom_fields|+ if available_project_custom_fields_grouped_by_section.any?+ flex_layout(data: { qa_selector: "project-custom-fields-sidebar-async-content" }) do |sections_container|+ available_project_custom_fields_grouped_by_section.each do |project_custom_field_section_id, project_custom_fields|sections_container.with_row(mb: 3) dorender(ProjectCustomFields::Sections::ShowComponent.new(project: @project,diff --git a/modules/overviews/app/components/project_custom_fields/sidebar_component.rb b/modules/overviews/app/components/project_custom_fields/sidebar_component.rbindex 207f065c038..2b6731ca762 100644--- a/modules/overviews/app/components/project_custom_fields/sidebar_component.rb+++ b/modules/overviews/app/components/project_custom_fields/sidebar_component.rb@@ -32,18 +32,21 @@ module ProjectCustomFieldsinclude OpPrimer::ComponentHelpersinclude OpTurbo::Streamable- def initialize(project:, project_custom_field_sections:, active_project_custom_fields_grouped_by_section:)+ def initialize(project:, eager_loaded_project_custom_field_sections:)super@project = project- @project_custom_field_sections = project_custom_field_sections- @active_project_custom_fields_grouped_by_section = active_project_custom_fields_grouped_by_section+ @eager_loaded_project_custom_field_sections = eager_loaded_project_custom_field_sectionsendprivatedef get_eager_loaded_project_custom_field_section(project_custom_field_section_id)- @project_custom_field_sections.find { |pcfs| pcfs.id == project_custom_field_section_id }+ @eager_loaded_project_custom_field_sections.find { |pcfs| pcfs.id == project_custom_field_section_id }+ end++ def available_project_custom_fields_grouped_by_section+ @available_project_custom_fields_grouped_by_section ||= @project.available_project_custom_fields_grouped_by_sectionendendenddiff --git a/modules/overviews/app/controllers/overviews/overviews_controller.rb b/modules/overviews/app/controllers/overviews/overviews_controller.rbindex e4261ac4072..03f2327f92f 100644--- a/modules/overviews/app/controllers/overviews/overviews_controller.rb+++ b/modules/overviews/app/controllers/overviews/overviews_controller.rb@@ -5,34 +5,31 @@ module ::Overviewsbefore_action :authorizebefore_action :jump_to_project_menu_itembefore_action :check_project_attributes_feature_enabled,- only: %i[attributes_sidebar attribute_section_dialog update_attributes]+ only: %i[project_custom_fields_sidebar project_custom_field_section_dialog update_project_custom_values]menu_item :overview- def attributes_sidebar+ def project_custom_fields_sidebarrender(ProjectCustomFields::SidebarComponent.new(project: @project,- project_custom_field_sections: ProjectCustomFieldSection.all,- active_project_custom_fields_grouped_by_section:+ eager_loaded_project_custom_field_sections:),layout: false)end- def attribute_section_dialog- @section = find_project_custom_field_section-+ def project_custom_field_section_dialogrender(ProjectCustomFields::Sections::EditDialogComponent.new(project: @project,- project_custom_field_section: @section+ project_custom_field_section: find_project_custom_field_section),layout: false)end- def update_attributes+ def update_project_custom_valuessection = find_project_custom_field_sectionservice_call = ::Projects::UpdateService@@ -42,7 +39,7 @@ module ::Overviews).call(permitted_params.project.merge(- touched_custom_field_section_id: section.id+ limit_custom_fields_validation_to_section_id: section.id))@@ -68,24 +65,6 @@ module ::Overviewsrender_404 unless OpenProject::FeatureDecisions.project_attributes_active?end- def active_project_custom_fields_grouped_by_section- # TODO: move to service/model- active_custom_field_ids_of_project = ProjectCustomFieldProjectMapping- .where(project_id: @project.id)- .pluck(:custom_field_id)-- ProjectCustomField- .includes(:project_custom_field_section)- .where(id: active_custom_field_ids_of_project)- .sort_by { |pcf| pcf.project_custom_field_section.position }- .group_by(&:custom_field_section_id)- end-- def active_project_custom_fields_of_section(section_id)- active_project_custom_fields_grouped_by_section[section_id]- .sort_by(&:position_in_custom_field_section)- end-def find_project_custom_field_sectionProjectCustomFieldSection.find(params[:section_id])end@@ -103,10 +82,13 @@ module ::Overviewsupdate_via_turbo_stream(component: ProjectCustomFields::SidebarComponent.new(project: @project,- project_custom_field_sections: ProjectCustomFieldSection.all,- active_project_custom_fields_grouped_by_section:+ eager_loaded_project_custom_field_sections:))end++ def eager_loaded_project_custom_field_sections+ ProjectCustomFieldSection.all.to_a+ endendenddiff --git a/modules/overviews/config/routes.rb b/modules/overviews/config/routes.rbindex fb1db6b3c34..45d0829e881 100644--- a/modules/overviews/config/routes.rb+++ b/modules/overviews/config/routes.rb@@ -1,11 +1,11 @@OpenProject::Application.routes.draw doconstraints(project_id: Regexp.new("(?!(#{Project::RESERVED_IDENTIFIERS.join('|')})$)(\\w|-)+")) doget 'projects/:project_id', to: "overviews/overviews#show", as: :project_overview, format: :html- get 'projects/:project_id/attributes_sidebar', to: "overviews/overviews#attributes_sidebar", as: :project_attributes_sidebar,- format: :html- get 'projects/:project_id/attribute_section_dialog/:section_id', to: "overviews/overviews#attribute_section_dialog",- as: :project_attribute_section_dialog, format: :html- put 'projects/:project_id/attributes/:section_id', to: "overviews/overviews#update_attributes", as: :project_update_attributes,- format: :html+ get 'projects/:project_id/project_custom_fields_sidebar', to: "overviews/overviews#project_custom_fields_sidebar", as: :project_custom_fields_sidebar,+ format: :html+ get 'projects/:project_id/project_custom_field_section_dialog/:section_id', to: "overviews/overviews#project_custom_field_section_dialog",+ as: :project_custom_field_section_dialog, format: :html+ put 'projects/:project_id/update_project_custom_values/:section_id', to: "overviews/overviews#update_project_custom_values", as: :update_project_custom_values,+ format: :htmlendenddiff --git a/modules/overviews/lib/overviews/engine.rb b/modules/overviews/lib/overviews/engine.rbindex 5213afab5ad..c738f08b13a 100644--- a/modules/overviews/lib/overviews/engine.rb+++ b/modules/overviews/lib/overviews/engine.rb@@ -48,14 +48,14 @@ module Overviews.controller_actions.push('overviews/overviews/show',- 'overviews/overviews/attributes_sidebar'+ 'overviews/overviews/project_custom_fields_sidebar')OpenProject::AccessControl.permission(:edit_project).controller_actions.push(- 'overviews/overviews/attribute_section_dialog',- 'overviews/overviews/update_attributes'+ 'overviews/overviews/project_custom_field_section_dialog',+ 'overviews/overviews/update_project_custom_values')OpenProject::AccessControl.permission(:view_work_packages)diff --git a/spec/features/projects/project_custom_fields/overview_page/sidebar_spec.rb b/spec/features/projects/project_custom_fields/overview_page/sidebar_spec.rbindex 03c0b5667e0..eed3c401f36 100644--- a/spec/features/projects/project_custom_fields/overview_page/sidebar_spec.rb+++ b/spec/features/projects/project_custom_fields/overview_page/sidebar_spec.rb@@ -28,12 +28,11 @@require 'spec_helper'require_relative 'shared_context'-require_relative 'overview_page'RSpec.describe 'Show project custom fields on project overview page', :js, :with_cuprite doinclude_context 'with seeded projects, members and project custom fields'- let(:overview_page) { OverviewPage.new(project) }+ let(:overview_page) { Pages::Projects::Show.new(project) }before dologin_as admin@@ -44,7 +43,7 @@ RSpec.describe 'Show project custom fields on project overview page', :js, :withoverview_page.visit_pagewithin '.op-grid-page' do- expect(page).to have_no_css('#project-attributes-sidebar')+ expect(page).to have_no_css('#project-custom-fields-sidebar')endendend@@ -54,7 +53,7 @@ RSpec.describe 'Show project custom fields on project overview page', :js, :withoverview_page.visit_pagewithin '.op-grid-page' do- expect(page).to have_css('#project-attributes-sidebar')+ expect(page).to have_css('#project-custom-fields-sidebar')endenddiff --git a/spec/permissions/manage_project_custom_values.rb b/spec/permissions/manage_project_custom_values_spec.rbsimilarity index 79%rename from spec/permissions/manage_project_custom_values.rbrename to spec/permissions/manage_project_custom_values_spec.rbindex c045bb47617..3791db3cfe9 100644--- a/spec/permissions/manage_project_custom_values.rb+++ b/spec/permissions/manage_project_custom_values_spec.rb@@ -34,12 +34,12 @@ RSpec.describe Overviews::OverviewsController, 'manage_project_custom_values perinclude PermissionSpecs# render sidebar on project overview page with view_project permission- # TODO: prevents calling overviews/overviews#attributes_sidebar when not having the permission view_project (FAILED - 1)- check_permission_required_for('overviews/overviews#attributes_sidebar', :view_project)+ # TODO: prevents calling overviews/overviews#project_custom_fields_sidebar when not having the permission view_project (FAILED - 1)+ check_permission_required_for('overviews/overviews#project_custom_fields_sidebar', :view_project)# render dialog with inputs for editing project attributes with edit_project permission- check_permission_required_for('overviews/overviews#attribute_section_dialog', :edit_project)+ check_permission_required_for('overviews/overviews#project_custom_field_section_dialog', :edit_project)# update project attributes with edit_project permission, deeper permission check via contract in place- check_permission_required_for('overviews/overviews#update_attributes', :edit_project)+ check_permission_required_for('overviews/overviews#update_project_custom_values', :edit_project)enddiff --git a/spec/support/components/projects/project_custom_fields/edit_dialog.rb b/spec/support/components/projects/project_custom_fields/edit_dialog.rbindex a731896bd6a..26fb876e4a2 100644--- a/spec/support/components/projects/project_custom_fields/edit_dialog.rb+++ b/spec/support/components/projects/project_custom_fields/edit_dialog.rb@@ -46,7 +46,7 @@ module Componentsenddef dialog_css_selector- "modal-dialog#edit-project-attributes-dialog-#{@project_custom_field_section.id}"+ "modal-dialog#edit-project-custom-fields-dialog-#{@project_custom_field_section.id}"enddef async_content_container_css_selectordiff --git a/spec/support/pages/projects/show.rb b/spec/support/pages/projects/show.rbindex a2c3cac9b14..be5c23304d1 100644--- a/spec/support/pages/projects/show.rb+++ b/spec/support/pages/projects/show.rb@@ -56,8 +56,8 @@ module Pagesenddef within_async_loaded_sidebar(&)- within '#project-attributes-sidebar' do- expect(page).to have_css("[data-qa-selector='project-attributes-sidebar-async-content']")+ within '#project-custom-fields-sidebar' do+ expect(page).to have_css("[data-qa-selector='project-custom-fields-sidebar-async-content']")yieldendend