FIX: lowercase username for add/rem group members

This fix searches for users based on the downcased username so that if
you pass in usernames to add/remove from a group and you don't have the
casing just right it will still find the correct users.

I updated the tests to add a username that has a mix of upper and
lowercase letters to verify this functionality.
This commit is contained in:
Blake Erickson 2018-10-18 13:17:24 -06:00
parent 3973823a33
commit 93485facaf
2 changed files with 3 additions and 3 deletions

View File

@ -484,7 +484,7 @@ class GroupsController < ApplicationController
def users_from_params
if params[:usernames].present?
users = User.where(username: params[:usernames].split(","))
users = User.where(username_lower: params[:usernames].split(",").map(&:downcase))
raise Discourse::InvalidParameters.new(:usernames) if users.blank?
elsif params[:user_ids].present?
users = User.where(id: params[:user_ids].split(","))

View File

@ -856,7 +856,7 @@ describe GroupsController do
context "is able to add several members to a group" do
let(:user1) { Fabricate(:user) }
let(:user2) { Fabricate(:user) }
let(:user2) { Fabricate(:user, username: "UsEr2") }
it "adds by username" do
expect do
@ -1069,7 +1069,7 @@ describe GroupsController do
context '#remove_members' do
context "is able to remove several members from a group" do
let(:user1) { Fabricate(:user) }
let(:user2) { Fabricate(:user) }
let(:user2) { Fabricate(:user, username: "UsEr2") }
let(:group1) { Fabricate(:group, users: [user1, user2]) }
it "removes by username" do