Skip to content

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

Make custom field section routes "resource"-ful

Alexander Brandon Colesb4d14c7f3052
diff --git a/modules/overviews/app/components/overviews/project_custom_fields/edit_component.html.erb b/modules/overviews/app/components/overviews/project_custom_fields/edit_component.html.erb
index ca92dca0eb0..02e55bd3b48 100644
--- a/modules/overviews/app/components/overviews/project_custom_fields/edit_component.html.erb
+++ b/modules/overviews/app/components/overviews/project_custom_fields/edit_component.html.erb
@@ -6,7 +6,7 @@
model: @project,
method: :put,
data: { turbo: true, turbo_stream: true, "test-selector": "async-dialog-content" },
- url: project_update_custom_values_path(project_id: @project.id, section_id: @project_custom_field_section.id)
+ url: project_custom_field_section_path(project_id: @project.id, id: @project_custom_field_section.id)
) do |f|
render(
Projects::CustomFields::Form.new(
diff --git a/modules/overviews/app/components/overviews/project_custom_fields/show_component.html.erb b/modules/overviews/app/components/overviews/project_custom_fields/show_component.html.erb
index 7fa043fd75c..ff69af2db93 100644
--- a/modules/overviews/app/components/overviews/project_custom_fields/show_component.html.erb
+++ b/modules/overviews/app/components/overviews/project_custom_fields/show_component.html.erb
@@ -12,7 +12,7 @@
section.with_action_icon(
icon: :pencil,
tag: :a,
- href: project_custom_field_section_dialog_path(project_id: @project.id, section_id: @project_custom_field_section.id),
+ href: show_dialog_project_custom_field_section_path(project_id: @project.id, id: @project_custom_field_section.id),
data: {
controller: "async-dialog"
},
diff --git a/modules/overviews/app/controllers/overviews/overviews_controller.rb b/modules/overviews/app/controllers/overviews/overviews_controller.rb
index a87eb8023c9..4830f752964 100644
--- a/modules/overviews/app/controllers/overviews/overviews_controller.rb
+++ b/modules/overviews/app/controllers/overviews/overviews_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# -- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -28,8 +30,6 @@
module ::Overviews
class OverviewsController < ::Grids::BaseInProjectController
- include OpTurbo::ComponentStream
-
before_action :jump_to_project_menu_item
menu_item :overview
@@ -38,38 +38,6 @@ module ::Overviews
render :project_custom_fields_sidebar, layout: false
end
- def project_custom_field_section_dialog
- respond_with_dialog(
- Overviews::ProjectCustomFields::EditDialogComponent.new(
- project: @project,
- project_custom_field_section: find_project_custom_field_section
- )
- )
- end
-
- def project_update_custom_values
- section = find_project_custom_field_section
- service_call = ::Projects::UpdateService
- .new(
- user: current_user,
- model: @project,
- contract_options: { project_attributes_only: true }
- )
- .call(
- permitted_params.project.merge(
- _limit_custom_fields_validation_to_section_id: section.id
- )
- )
-
- if service_call.success?
- update_sidebar_component
- else
- handle_errors(service_call.result, section)
- end
-
- respond_to_with_turbo_streams(status: service_call.success? ? :ok : :unprocessable_entity)
- end
-
def project_life_cycle_sidebar
render :project_life_cycle_sidebar, layout: false
end
@@ -80,26 +48,5 @@ module ::Overviews
redirect_to_project_menu_item(@project, params[:jump]) && return
end
end
-
- private
-
- def find_project_custom_field_section
- ProjectCustomFieldSection.find(params[:section_id])
- end
-
- def handle_errors(project_with_errors, section)
- update_via_turbo_stream(
- component: Overviews::ProjectCustomFields::EditComponent.new(
- project: project_with_errors,
- project_custom_field_section: section
- )
- )
- end
-
- def update_sidebar_component
- update_via_turbo_stream(
- component: Overviews::ProjectCustomFields::SidePanelComponent.new(project: @project)
- )
- end
end
end
diff --git a/modules/overviews/app/controllers/overviews/project_custom_field_sections_controller.rb b/modules/overviews/app/controllers/overviews/project_custom_field_sections_controller.rb
new file mode 100644
index 00000000000..d8f7aa9f42c
--- /dev/null
+++ b/modules/overviews/app/controllers/overviews/project_custom_field_sections_controller.rb
@@ -0,0 +1,89 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+class Overviews::ProjectCustomFieldSectionsController < ApplicationController
+ include OpTurbo::ComponentStream
+
+ before_action :find_project_by_project_id
+ before_action :find_project_custom_field_section
+ before_action :authorize
+
+ def show_dialog
+ respond_with_dialog(
+ Overviews::ProjectCustomFields::EditDialogComponent.new(
+ project: @project,
+ project_custom_field_section: @section
+ )
+ )
+ end
+
+ def update
+ service_call = ::Projects::UpdateService
+ .new(
+ user: current_user,
+ model: @project,
+ contract_options: { project_attributes_only: true }
+ )
+ .call(
+ permitted_params.project.merge(
+ _limit_custom_fields_validation_to_section_id: @section.id
+ )
+ )
+
+ if service_call.success?
+ update_sidebar_component
+ else
+ handle_errors(service_call.result, @section)
+ end
+
+ respond_to_with_turbo_streams(status: service_call.success? ? :ok : :unprocessable_entity)
+ end
+
+ private
+
+ def find_project_custom_field_section
+ @section = ProjectCustomFieldSection.find(params[:id])
+ end
+
+ def handle_errors(project_with_errors, section)
+ update_via_turbo_stream(
+ component: Overviews::ProjectCustomFields::EditComponent.new(
+ project: project_with_errors,
+ project_custom_field_section: section
+ )
+ )
+ end
+
+ def update_sidebar_component
+ update_via_turbo_stream(
+ component: Overviews::ProjectCustomFields::SidePanelComponent.new(project: @project)
+ )
+ end
+end
diff --git a/modules/overviews/config/routes.rb b/modules/overviews/config/routes.rb
index 14daac3ea17..a519839a7e8 100644
--- a/modules/overviews/config/routes.rb
+++ b/modules/overviews/config/routes.rb
@@ -9,10 +9,10 @@ Rails.application.routes.draw do
controller :overviews do
get "project_custom_fields_sidebar" => :project_custom_fields_sidebar, as: :custom_fields_sidebar
get "project_life_cycle_sidebar" => :project_life_cycle_sidebar, as: :life_cycle_sidebar
+ end
- get "project_custom_field_section_dialog/:section_id" => :project_custom_field_section_dialog,
- as: :custom_field_section_dialog
- put "project_update_custom_values/:section_id" => :project_update_custom_values, as: :update_custom_values
+ resources :project_custom_field_sections, only: [:update], as: :custom_field_sections do
+ get :show_dialog, on: :member
end
namespace :widgets do
@@ -23,8 +23,6 @@ Rails.application.routes.draw do
end
resources :project_phases, controller: "overviews/project_phases", only: %i[edit update] do
- member do
- put :preview
- end
+ put :preview, on: :member
end
end
diff --git a/modules/overviews/lib/overviews/engine.rb b/modules/overviews/lib/overviews/engine.rb
index 3e32f611fa3..6d40231fc56 100644
--- a/modules/overviews/lib/overviews/engine.rb
+++ b/modules/overviews/lib/overviews/engine.rb
@@ -66,8 +66,8 @@ module Overviews
OpenProject::AccessControl.permission(:edit_project_attributes)
.controller_actions
.push(
- "overviews/overviews/project_custom_field_section_dialog",
- "overviews/overviews/project_update_custom_values"
+ "overviews/project_custom_field_sections/show_dialog",
+ "overviews/project_custom_field_sections/update"
)
OpenProject::AccessControl.permission(:view_project_phases)
diff --git a/modules/overviews/spec/routing/overviews_routing_spec.rb b/modules/overviews/spec/routing/overviews_routing_spec.rb
index f8f659f15fa..d8173ba35d5 100644
--- a/modules/overviews/spec/routing/overviews_routing_spec.rb
+++ b/modules/overviews/spec/routing/overviews_routing_spec.rb
@@ -46,26 +46,6 @@ RSpec.describe Overviews::OverviewsController do
)
end
- it do
- expect(get("/projects/my-project/project_custom_field_section_dialog/33"))
- .to route_to(
- controller: "overviews/overviews",
- action: "project_custom_field_section_dialog",
- project_id: "my-project",
- section_id: "33"
- )
- end
-
- it do
- expect(put("/projects/my-project/project_update_custom_values/44"))
- .to route_to(
- controller: "overviews/overviews",
- action: "project_update_custom_values",
- project_id: "my-project",
- section_id: "44"
- )
- end
-
it do
expect(get("/projects/my-project/project_life_cycle_sidebar"))
.to route_to(
@@ -91,26 +71,6 @@ RSpec.describe Overviews::OverviewsController do
)
end
- it do
- expect(get(project_custom_field_section_dialog_path("my-project", 33)))
- .to route_to(
- controller: "overviews/overviews",
- action: "project_custom_field_section_dialog",
- project_id: "my-project",
- section_id: "33"
- )
- end
-
- it do
- expect(put(project_update_custom_values_path("my-project", 44)))
- .to route_to(
- controller: "overviews/overviews",
- action: "project_update_custom_values",
- project_id: "my-project",
- section_id: "44"
- )
- end
-
it do
expect(get(project_life_cycle_sidebar_path("my-project")))
.to route_to(
diff --git a/modules/overviews/spec/routing/project_custom_field_sections_routing_spec.rb b/modules/overviews/spec/routing/project_custom_field_sections_routing_spec.rb
new file mode 100644
index 00000000000..55841705d69
--- /dev/null
+++ b/modules/overviews/spec/routing/project_custom_field_sections_routing_spec.rb
@@ -0,0 +1,105 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require "rails_helper"
+
+RSpec.describe Overviews::ProjectCustomFieldSectionsController do
+ describe "routing" do
+ describe "#show" do
+ it do
+ expect(get("/projects/my-project/project_custom_field_sections/33/show_dialog"))
+ .to route_to(
+ controller: "overviews/project_custom_field_sections",
+ action: "show_dialog",
+ project_id: "my-project",
+ id: "33"
+ )
+ end
+ end
+
+ describe "PUT/PATCH #update" do
+ it do
+ expect(put("/projects/my-project/project_custom_field_sections/44"))
+ .to route_to(
+ controller: "overviews/project_custom_field_sections",
+ action: "update",
+ project_id: "my-project",
+ id: "44"
+ )
+ end
+
+ it do
+ expect(patch("/projects/my-project/project_custom_field_sections/44"))
+ .to route_to(
+ controller: "overviews/project_custom_field_sections",
+ action: "update",
+ project_id: "my-project",
+ id: "44"
+ )
+ end
+ end
+ end
+
+ describe "named routing" do
+ describe "GET #show" do
+ it do
+ expect(get(show_dialog_project_custom_field_section_path("my-project", 33)))
+ .to route_to(
+ controller: "overviews/project_custom_field_sections",
+ action: "show_dialog",
+ project_id: "my-project",
+ id: "33"
+ )
+ end
+ end
+
+ describe "PUT/PATCH #update" do
+ it do
+ expect(put(project_custom_field_section_path("my-project", 44)))
+ .to route_to(
+ controller: "overviews/project_custom_field_sections",
+ action: "update",
+ project_id: "my-project",
+ id: "44"
+ )
+ end
+
+ it do
+ expect(patch("/projects/my-project/project_custom_field_sections/44"))
+ .to route_to(
+ controller: "overviews/project_custom_field_sections",
+ action: "update",
+ project_id: "my-project",
+ id: "44"
+ )
+ end
+ end
+ end
+end
diff --git a/spec/permissions/edit_project_attributes_spec.rb b/spec/permissions/edit_project_attributes_spec.rb
index cd1cc024291..4cce6c06b5a 100644
--- a/spec/permissions/edit_project_attributes_spec.rb
+++ b/spec/permissions/edit_project_attributes_spec.rb
@@ -31,13 +31,13 @@
require "spec_helper"
require "support/permission_specs"
-RSpec.describe Overviews::OverviewsController, "edit_project_attributes permission", # rubocop:disable RSpec/EmptyExampleGroup,RSpec/SpecFilePathFormat
+RSpec.describe Overviews::ProjectCustomFieldSectionsController, "edit_project_attributes permission", # rubocop:disable RSpec/EmptyExampleGroup,RSpec/SpecFilePathFormat
type: :controller do
include PermissionSpecs
# render dialog with inputs for editing project attributes with edit_project permission
- check_permission_required_for("overviews/overviews#project_custom_field_section_dialog", :edit_project_attributes)
+ check_permission_required_for("overviews/project_custom_field_sections#show_dialog", :edit_project_attributes)
# update project attributes with edit_project permission, deeper permission check via contract in place
- check_permission_required_for("overviews/overviews#project_update_custom_values", :edit_project_attributes)
+ check_permission_required_for("overviews/project_custom_field_sections#update", :edit_project_attributes)
end