Merge branch 'rs-admin-user-case-insensitive' into 'master'

Admin section finds users case-insensitively

Closes #55877

See merge request gitlab-org/gitlab-ce!25176
This commit is contained in:
Douwe Maan 2019-02-15 17:10:29 +00:00
commit fffce276f1
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) }