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.
This commit is contained in:
Aaron Contreras
2023-07-28 11:26:28 -05:00
parent 625b145041
commit bdbaefd970
5 changed files with 51 additions and 20 deletions
@@ -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
@@ -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')) -%>
+2 -7
View File
@@ -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
@@ -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,
@@ -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')