Commit 8af6d0d0 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'fix-group-boards-redirect' into 'master'

Redirect to group boards with params from old path

Closes #3922

See merge request gitlab-org/gitlab-ee!3267
parents d7941abb 181cf350
---
title: Redirect to existing group boards using old URL if there is no subgroup called
'boards'
merge_request:
author:
type: fixed
......@@ -89,7 +89,14 @@ constraints(GroupUrlConstrainer.new) do
end
## EE-specific
get :boards, to: redirect('/groups/%{group_id}/-/boards')
legacy_ee_group_boards_redirect = redirect do |params, request|
path = "/groups/#{params[:group_id]}/-/boards"
path << "/#{params[:extra_params]}" if params[:extra_params].present?
path << "?#{request.query_string}" if request.query_string.present?
path
end
get 'boards(/*extra_params)', as: :legacy_ee_group_boards_redirect, to: legacy_ee_group_boards_redirect
end
scope(path: '*id',
......
......@@ -68,21 +68,27 @@ describe Gitlab::PathRegex do
message
end
let(:all_routes) do
let(:all_non_legacy_routes) do
route_set = Rails.application.routes
routes_collection = route_set.routes
routes_array = routes_collection.routes
non_deprecated_redirect_routes = routes_array.reject do |route|
non_legacy_routes = routes_array.reject do |route|
route.name.to_s =~ /legacy_(\w*)_redirect/
end
non_deprecated_redirect_routes = non_legacy_routes.reject do |route|
app = route.app
# `app.app` is either another app, or `self`. We want to find the final app.
app = app.app while app.try(:app) && app.app != app
app.is_a?(ActionDispatch::Routing::PathRedirect) && app.block.include?('/-/')
end
non_deprecated_redirect_routes.map { |route| route.path.spec.to_s }
end
let(:routes_without_format) { all_routes.map { |path| without_format(path) } }
let(:routes_without_format) { all_non_legacy_routes.map { |path| without_format(path) } }
# Routes not starting with `/:` or `/*`
# all routes not starting with a param
......
require 'spec_helper'
describe 'Deprecated boards paths' do
it 'redirects to boards page' do
group = create :group, name: 'gitlabhq'
let!(:group) { create(:group, name: 'gitlabhq') }
get('/groups/gitlabhq/boards')
context 'when no group called boards exists' do
it 'redirects to boards page' do
get('/groups/gitlabhq/boards')
expect(response).to redirect_to(group_boards_path(group))
expect(response).to redirect_to(group_boards_path(group))
end
it 'redirects to the boards page with additional params' do
get('/groups/gitlabhq/boards/1?foo=bar')
expect(response).to redirect_to(group_board_path(group, 1, foo: 'bar'))
end
end
context 'when a group called boards exists', :nested_groups do
before do
create(:group, name: 'boards', parent: group)
end
it 'does not redirect to the main boards page' do
get('/groups/gitlabhq/boards')
expect(response).to have_gitlab_http_status(200)
end
it 'does not redirect to the boards page with additional params' do
get('/groups/gitlabhq/boards/issues')
expect(response).to have_gitlab_http_status(200)
end
it 'redirects to the boards page with additional params if there is no matching route on the subgroup' do
get('/groups/gitlabhq/boards/1?foo=bar')
expect(response).to redirect_to(group_board_path(group, 1, foo: 'bar'))
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment