Admin section finds users case-insensitively

Previously, if you entered a username in the URL manually to view a
specific user, the lookup was done case-sensitively, despite usernames
being case-insensitive, often resulting in a 404. We now use the same
`find_routable!` logic as the non-admin Users controller.
This commit is contained in:
Robert Speicher 2019-02-12 14:26:07 -08:00
parent a58e92fc1b
commit 12c70e636c
No known key found for this signature in database
GPG Key ID: 1D812769A7706642
3 changed files with 23 additions and 3 deletions

View File

@ -1,6 +1,8 @@
# frozen_string_literal: true
class Admin::UsersController < Admin::ApplicationController
include RoutableActions
before_action :user, except: [:index, :new, :create]
before_action :check_impersonation_availability, only: :impersonate
@ -177,11 +179,13 @@ class Admin::UsersController < Admin::ApplicationController
user == current_user
end
# rubocop: disable CodeReuse/ActiveRecord
def user
@user ||= User.find_by!(username: params[:id])
@user ||= find_routable!(User, params[:id])
end
def build_canonical_path(user)
url_for(safe_params.merge(id: user.to_param))
end
# rubocop: enable CodeReuse/ActiveRecord
def redirect_back_or_admin_user(options = {})
redirect_back_or_default(default: default_route, options: options)

View File

@ -0,0 +1,5 @@
---
title: Admin section finds users case-insensitively
merge_request:
author:
type: fixed

View File

@ -8,6 +8,17 @@ describe Admin::UsersController do
sign_in(admin)
end
describe 'GET :id' do
it 'finds a user case-insensitively' do
user = create(:user, username: 'CaseSensitive')
get :show, params: { id: user.username.downcase }
expect(response).to be_redirect
expect(response.location).to end_with(user.username)
end
end
describe 'DELETE #user with projects' do
let(:project) { create(:project, namespace: user.namespace) }
let!(:issue) { create(:issue, author: user) }