Make the /groups
route behave as expected
The route is supposed to redirect the Groups#index request based on whether or not a user was logged in. If they are, we redirect them to their groups dashboard; if they're not, we redirect them to the public Explore page. But due to overly aggressive `before_action`s that weren't excluding the `index` action, the request always resulted in a 404, whether a user was logged in or not. Closes #12660
This commit is contained in:
parent
5409fc49bd
commit
a7c4d0da8c
2 changed files with 28 additions and 4 deletions
|
@ -2,17 +2,18 @@ class GroupsController < Groups::ApplicationController
|
|||
include IssuesAction
|
||||
include MergeRequestsAction
|
||||
|
||||
skip_before_action :authenticate_user!, only: [:show, :issues, :merge_requests]
|
||||
respond_to :html
|
||||
before_action :group, except: [:new, :create]
|
||||
|
||||
skip_before_action :authenticate_user!, only: [:index, :show, :issues, :merge_requests]
|
||||
before_action :group, except: [:index, :new, :create]
|
||||
|
||||
# Authorize
|
||||
before_action :authorize_read_group!, except: [:show, :new, :create, :autocomplete]
|
||||
before_action :authorize_read_group!, except: [:index, :show, :new, :create, :autocomplete]
|
||||
before_action :authorize_admin_group!, only: [:edit, :update, :destroy, :projects]
|
||||
before_action :authorize_create_group!, only: [:new, :create]
|
||||
|
||||
# Load group projects
|
||||
before_action :load_projects, except: [:new, :create, :projects, :edit, :update, :autocomplete]
|
||||
before_action :load_projects, except: [:index, :new, :create, :projects, :edit, :update, :autocomplete]
|
||||
before_action :event_filter, only: :show
|
||||
|
||||
layout :determine_layout
|
||||
|
|
23
spec/controllers/groups_controller_spec.rb
Normal file
23
spec/controllers/groups_controller_spec.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe GroupsController do
|
||||
describe 'GET index' do
|
||||
context 'as a user' do
|
||||
it 'redirects to Groups Dashboard' do
|
||||
sign_in(create(:user))
|
||||
|
||||
get :index
|
||||
|
||||
expect(response).to redirect_to(dashboard_groups_path)
|
||||
end
|
||||
end
|
||||
|
||||
context 'as a guest' do
|
||||
it 'redirects to Explore Groups' do
|
||||
get :index
|
||||
|
||||
expect(response).to redirect_to(explore_groups_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue