FIX: don't ever fetch staged accounts in unseen mentions

This commit is contained in:
Régis Hanol 2015-11-27 18:16:50 +01:00
parent 5e93140f85
commit 76692235ae
2 changed files with 36 additions and 5 deletions

View File

@ -201,12 +201,15 @@ class UsersController < ApplicationController
end
def is_local_username
users = params[:usernames]
users = [params[:username]] if users.blank?
users.each(&:downcase!)
usernames = params[:usernames]
usernames = [params[:username]] if usernames.blank?
usernames.each(&:downcase!)
result = User.where(username_lower: users).pluck(:username_lower)
render json: {valid: result}
result = User.where(staged: false)
.where(username_lower: usernames)
.pluck(:username_lower)
render json: { valid: result }
end
def render_available_true

View File

@ -1539,4 +1539,32 @@ describe UsersController do
end
describe ".is_local_username" do
let(:user) { Fabricate(:user) }
it "finds the user" do
xhr :get, :is_local_username, username: user.username
expect(response).to be_success
json = JSON.parse(response.body)
expect(json["valid"][0]).to eq(user.username)
end
it "supports multiples usernames" do
xhr :get, :is_local_username, usernames: [user.username, "system"]
expect(response).to be_success
json = JSON.parse(response.body)
expect(json["valid"].size).to eq(2)
end
it "never includes staged accounts" do
staged = Fabricate(:user, staged: true)
xhr :get, :is_local_username, usernames: [staged.username]
expect(response).to be_success
json = JSON.parse(response.body)
expect(json["valid"].size).to eq(0)
end
end
end