mirror of
https://github.com/discourse/discourse.git
synced 2026-08-26 21:27:16 -05:00
SiteSetting to hide regular names from users
This commit is contained in:
@@ -893,6 +893,30 @@ describe UsersController do
|
||||
json["users"].map { |u| u["username"] }.should include(user.username)
|
||||
end
|
||||
|
||||
context "when `enable_names` is true" do
|
||||
before do
|
||||
SiteSetting.stubs(:enable_names?).returns(true)
|
||||
end
|
||||
|
||||
it "returns names" do
|
||||
xhr :post, :search_users, term: user.name
|
||||
json = JSON.parse(response.body)
|
||||
json["users"].map { |u| u["name"] }.should include(user.name)
|
||||
end
|
||||
end
|
||||
|
||||
context "when `enable_names` is false" do
|
||||
before do
|
||||
SiteSetting.stubs(:enable_names?).returns(false)
|
||||
end
|
||||
|
||||
it "returns names" do
|
||||
xhr :post, :search_users, term: user.name
|
||||
json = JSON.parse(response.body)
|
||||
json["users"].map { |u| u["name"] }.should_not include(user.name)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'send_activation_email' do
|
||||
|
||||
@@ -21,53 +21,68 @@ describe UserSearch do
|
||||
Fabricate :post, user: user6, topic: topic
|
||||
end
|
||||
|
||||
def search_for(*args)
|
||||
UserSearch.new(*args).search
|
||||
end
|
||||
|
||||
# this is a seriously expensive integration test, re-creating this entire test db is too expensive
|
||||
# reuse
|
||||
it "operates correctly" do
|
||||
# normal search
|
||||
results = UserSearch.search user1.name.split(" ").first
|
||||
results = search_for(user1.name.split(" ").first)
|
||||
results.size.should == 1
|
||||
results.first.should == user1
|
||||
|
||||
# lower case
|
||||
results = UserSearch.search user1.name.split(" ").first.downcase
|
||||
results = search_for(user1.name.split(" ").first.downcase)
|
||||
results.size.should == 1
|
||||
results.first.should == user1
|
||||
|
||||
# username
|
||||
results = UserSearch.search user4.username
|
||||
results = search_for(user4.username)
|
||||
results.size.should == 1
|
||||
results.first.should == user4
|
||||
|
||||
# case insensitive
|
||||
results = UserSearch.search user4.username.upcase
|
||||
results = search_for(user4.username.upcase)
|
||||
results.size.should == 1
|
||||
results.first.should == user4
|
||||
|
||||
# substrings
|
||||
results = UserSearch.search "mr"
|
||||
results = search_for("mr")
|
||||
results.size.should == 6
|
||||
|
||||
results = UserSearch.search "mrb"
|
||||
results = search_for("mrb")
|
||||
results.size.should == 3
|
||||
|
||||
|
||||
results = UserSearch.search "MR"
|
||||
results = search_for("MR")
|
||||
results.size.should == 6
|
||||
|
||||
results = UserSearch.search "MRB"
|
||||
results = search_for("MRB")
|
||||
results.size.should == 3
|
||||
|
||||
# topic priority
|
||||
results = UserSearch.search "mrb", topic.id
|
||||
results = search_for("mrb", topic.id)
|
||||
results.first.should == user1
|
||||
|
||||
|
||||
results = UserSearch.search "mrb", topic2.id
|
||||
results = search_for("mrb", topic2.id)
|
||||
results.first.should == user2
|
||||
|
||||
results = UserSearch.search "mrb", topic3.id
|
||||
results = search_for("mrb", topic3.id)
|
||||
results.first.should == user5
|
||||
|
||||
# When searching by name is enabled, it returns the record
|
||||
SiteSetting.stubs(:enable_names).returns(true)
|
||||
results = search_for("Tarantino")
|
||||
results.size.should == 1
|
||||
|
||||
# When searching by name is disabled, it will not return the record
|
||||
SiteSetting.stubs(:enable_names).returns(false)
|
||||
results = search_for("Tarantino")
|
||||
results.size.should == 0
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
require 'spec_helper'
|
||||
require_dependency 'post'
|
||||
require_dependency 'user'
|
||||
|
||||
describe BasicPostSerializer do
|
||||
|
||||
context "name" do
|
||||
let(:user) { Fabricate.build(:user) }
|
||||
let(:post) { Fabricate.build(:post, user: user) }
|
||||
let(:serializer) { BasicPostSerializer.new(post, scope: Guardian.new, root: false) }
|
||||
let(:json) { serializer.as_json }
|
||||
|
||||
it "returns the name it when `enable_names` is true" do
|
||||
SiteSetting.stubs(:enable_names?).returns(true)
|
||||
json[:name].should be_present
|
||||
end
|
||||
|
||||
it "doesn't return the name it when `enable_names` is false" do
|
||||
SiteSetting.stubs(:enable_names?).returns(false)
|
||||
json[:name].should be_blank
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -58,4 +58,21 @@ describe PostSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
context "display_username" do
|
||||
let(:user) { Fabricate.build(:user) }
|
||||
let(:post) { Fabricate.build(:post, user: user) }
|
||||
let(:serializer) { PostSerializer.new(post, scope: Guardian.new, root: false) }
|
||||
let(:json) { serializer.as_json }
|
||||
|
||||
it "returns the display_username it when `enable_names` is on" do
|
||||
SiteSetting.stubs(:enable_names).returns(true)
|
||||
json[:display_username].should be_present
|
||||
end
|
||||
|
||||
it "doesn't return the display_username it when `enable_names` is off" do
|
||||
SiteSetting.stubs(:enable_names).returns(false)
|
||||
json[:display_username].should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
require 'spec_helper'
|
||||
require_dependency 'user'
|
||||
|
||||
describe UserSerializer do
|
||||
|
||||
context "with a user" do
|
||||
let(:user) { Fabricate.build(:user) }
|
||||
let(:serializer) { UserSerializer.new(user, scope: Guardian.new, root: false) }
|
||||
let(:json) { serializer.as_json }
|
||||
|
||||
it "produces json" do
|
||||
json.should be_present
|
||||
end
|
||||
|
||||
context "with `enable_names` true" do
|
||||
before do
|
||||
SiteSetting.stubs(:enable_names?).returns(true)
|
||||
end
|
||||
|
||||
it "has a name" do
|
||||
json[:name].should == "Bruce Wayne"
|
||||
end
|
||||
end
|
||||
|
||||
context "with `enable_names` false" do
|
||||
before do
|
||||
SiteSetting.stubs(:enable_names?).returns(false)
|
||||
end
|
||||
|
||||
it "has a name" do
|
||||
puts json[:name]
|
||||
json[:name].should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user