From bdbaefd970365e91f231edacd4512dba3154ff15 Mon Sep 17 00:00:00 2001 From: Aaron Contreras Date: Fri, 28 Jul 2023 11:26:28 -0500 Subject: [PATCH] Refactor `/boards(/*state)` into separate `index` and `show` actions Since we're now routing with Rails and not Angular, we don't need a catch-all `/boards*` route. We can properly route between requesting a collection and an individual board resource. --- .../controllers/boards/boards_controller.rb | 12 ++++---- .../app/views/boards/boards/show.html.erb | 30 +++++++++++++++++++ modules/boards/config/routes.rb | 9 ++---- .../boards/lib/open_project/boards/engine.rb | 2 +- .../spec/routing/boards_routing_spec.rb | 18 +++++++---- 5 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 modules/boards/app/views/boards/boards/show.html.erb diff --git a/modules/boards/app/controllers/boards/boards_controller.rb b/modules/boards/app/controllers/boards/boards_controller.rb index dd94e23198e..bc689c38b92 100644 --- a/modules/boards/app/controllers/boards/boards_controller.rb +++ b/modules/boards/app/controllers/boards/boards_controller.rb @@ -3,7 +3,7 @@ module ::Boards before_action :find_optional_project before_action :build_board_grid, only: %i[new] - with_options only: [:index] do + with_options only: %i[index show] do # The boards permission alone does not suffice # to view work packages before_action :authorize @@ -33,6 +33,10 @@ module ::Boards :boards end + def show + render layout: 'angular/angular' + end + def new; end def create @@ -42,7 +46,7 @@ module ::Boards if service_result.success? flash[:notice] = I18n.t(:notice_successful_create) - redirect_to board_grid_path + redirect_to project_work_package_board_path(@project, @board_grid) else @errors = service_result.errors render action: :new @@ -92,9 +96,5 @@ module ::Boards def board_grid_params params.require(:boards_grid).permit(%i[name attribute]) end - - def board_grid_path - "/projects/#{@project.identifier}/boards/#{@board_grid.id}" - end end end diff --git a/modules/boards/app/views/boards/boards/show.html.erb b/modules/boards/app/views/boards/boards/show.html.erb new file mode 100644 index 00000000000..3655423d098 --- /dev/null +++ b/modules/boards/app/views/boards/boards/show.html.erb @@ -0,0 +1,30 @@ +<%#-- copyright +OpenProject is an open source project management software. +Copyright (C) 2012-2023 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. + +++#%> + +<% html_title(t('boards.label_boards')) -%> diff --git a/modules/boards/config/routes.rb b/modules/boards/config/routes.rb index 90c46cb5ee1..649cf0c6e72 100644 --- a/modules/boards/config/routes.rb +++ b/modules/boards/config/routes.rb @@ -3,23 +3,18 @@ OpenProject::Application.routes.draw do resources :boards, controller: 'boards/boards', - only: %i[new create], + only: %i[index show new create], as: :work_package_boards - scope '', as: :work_package_boards do - get '/boards(/*state)', to: 'boards/boards#index' - end - scope 'projects/:project_id', as: 'project' do resources :boards, controller: 'boards/boards', - only: %i[new], + only: %i[index new show], as: :work_package_boards # Adding the `create` action into the above `resources` macro would # result in a name collision between it and `get /boards(/*state)` # as it would result in both being named `project_work_package_boards` post '/boards', to: 'boards/boards#create' - get '/boards(/*state)', to: 'boards/boards#index', as: :work_package_boards end end diff --git a/modules/boards/lib/open_project/boards/engine.rb b/modules/boards/lib/open_project/boards/engine.rb index acc9cdf88d8..9e8a19d14f4 100644 --- a/modules/boards/lib/open_project/boards/engine.rb +++ b/modules/boards/lib/open_project/boards/engine.rb @@ -29,7 +29,7 @@ module OpenProject::Boards name: 'OpenProject Boards' do project_module :board_view, dependencies: :work_package_tracking, order: 80 do permission :show_board_views, - { 'boards/boards': %i[index overview] }, + { 'boards/boards': %i[index show overview] }, dependencies: :view_work_packages, contract_actions: { boards: %i[read] } permission :manage_board_views, diff --git a/modules/boards/spec/routing/boards_routing_spec.rb b/modules/boards/spec/routing/boards_routing_spec.rb index 06f991d1885..f4954bbbcf0 100644 --- a/modules/boards/spec/routing/boards_routing_spec.rb +++ b/modules/boards/spec/routing/boards_routing_spec.rb @@ -31,8 +31,8 @@ require 'spec_helper' RSpec.describe 'Boards routing' do it do expect(subject) - .to route(:get, '/projects/foobar/boards/state') - .to(controller: 'boards/boards', action: 'index', project_id: 'foobar', state: 'state') + .to route(:get, '/boards/all') + .to(controller: 'boards/boards', action: 'overview') end it do @@ -43,14 +43,14 @@ RSpec.describe 'Boards routing' do it do expect(subject) - .to route(:get, '/boards/state') - .to(controller: 'boards/boards', action: 'index', state: 'state') + .to route(:get, '/boards/1') + .to(controller: 'boards/boards', action: 'show', id: 1) end it do expect(subject) - .to route(:get, '/projects/foobar/boards/new') - .to(controller: 'boards/boards', action: 'new', project_id: 'foobar') + .to route(:get, '/projects/foobar/boards/1') + .to(controller: 'boards/boards', action: 'show', project_id: 'foobar', id: 1) end it do @@ -59,6 +59,12 @@ RSpec.describe 'Boards routing' do .to(controller: 'boards/boards', action: 'new') end + it do + expect(subject) + .to route(:get, '/projects/foobar/boards/new') + .to(controller: 'boards/boards', action: 'new', project_id: 'foobar') + end + it do expect(subject) .to route(:post, '/projects/foobar/boards')