mirror of
https://github.com/discourse/discourse.git
synced 2025-03-21 04:55:46 +08:00
FIX: More fixes for Group#mentionable
and Group#messageable
feature.
This commit is contained in:
parent
91c5f928c2
commit
8140e54675
@ -21,6 +21,7 @@ export default TextField.extend({
|
|||||||
groups = [],
|
groups = [],
|
||||||
currentUser = this.currentUser,
|
currentUser = this.currentUser,
|
||||||
includeMentionableGroups = this.get('includeMentionableGroups') === 'true',
|
includeMentionableGroups = this.get('includeMentionableGroups') === 'true',
|
||||||
|
includeMessageableGroups = this.get('includeMessageableGroups') === 'true',
|
||||||
includeGroups = this.get('includeGroups') === 'true',
|
includeGroups = this.get('includeGroups') === 'true',
|
||||||
allowedUsers = this.get('allowedUsers') === 'true';
|
allowedUsers = this.get('allowedUsers') === 'true';
|
||||||
|
|
||||||
@ -52,6 +53,7 @@ export default TextField.extend({
|
|||||||
includeGroups,
|
includeGroups,
|
||||||
allowedUsers,
|
allowedUsers,
|
||||||
includeMentionableGroups,
|
includeMentionableGroups,
|
||||||
|
includeMessageableGroups,
|
||||||
group: self.get("group")
|
group: self.get("group")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ var cache = {},
|
|||||||
currentTerm,
|
currentTerm,
|
||||||
oldSearch;
|
oldSearch;
|
||||||
|
|
||||||
function performSearch(term, topicId, includeGroups, includeMentionableGroups, allowedUsers, group, resultsFn) {
|
function performSearch(term, topicId, includeGroups, includeMentionableGroups, includeMessageableGroups, allowedUsers, group, resultsFn) {
|
||||||
var cached = cache[term];
|
var cached = cache[term];
|
||||||
if (cached) {
|
if (cached) {
|
||||||
resultsFn(cached);
|
resultsFn(cached);
|
||||||
@ -20,6 +20,7 @@ function performSearch(term, topicId, includeGroups, includeMentionableGroups, a
|
|||||||
topic_id: topicId,
|
topic_id: topicId,
|
||||||
include_groups: includeGroups,
|
include_groups: includeGroups,
|
||||||
include_mentionable_groups: includeMentionableGroups,
|
include_mentionable_groups: includeMentionableGroups,
|
||||||
|
include_messageable_groups: includeMessageableGroups,
|
||||||
group: group,
|
group: group,
|
||||||
topic_allowed_users: allowedUsers }
|
topic_allowed_users: allowedUsers }
|
||||||
});
|
});
|
||||||
@ -88,6 +89,7 @@ export default function userSearch(options) {
|
|||||||
var term = options.term || "",
|
var term = options.term || "",
|
||||||
includeGroups = options.includeGroups,
|
includeGroups = options.includeGroups,
|
||||||
includeMentionableGroups = options.includeMentionableGroups,
|
includeMentionableGroups = options.includeMentionableGroups,
|
||||||
|
includeMessageableGroups = options.includeMessageableGroups,
|
||||||
allowedUsers = options.allowedUsers,
|
allowedUsers = options.allowedUsers,
|
||||||
topicId = options.topicId,
|
topicId = options.topicId,
|
||||||
group = options.group;
|
group = options.group;
|
||||||
@ -120,6 +122,7 @@ export default function userSearch(options) {
|
|||||||
topicId,
|
topicId,
|
||||||
includeGroups,
|
includeGroups,
|
||||||
includeMentionableGroups,
|
includeMentionableGroups,
|
||||||
|
includeMessageableGroups,
|
||||||
allowedUsers,
|
allowedUsers,
|
||||||
group,
|
group,
|
||||||
function(r) {
|
function(r) {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
{{user-selector topicId=topicId
|
{{user-selector topicId=topicId
|
||||||
onChangeCallback='triggerResize'
|
onChangeCallback='triggerResize'
|
||||||
id="private-message-users"
|
id="private-message-users"
|
||||||
includeMentionableGroups='true'
|
includeMessageableGroups='true'
|
||||||
class="span8"
|
class="span8"
|
||||||
placeholderKey="composer.users_placeholder"
|
placeholderKey="composer.users_placeholder"
|
||||||
tabindex="1"
|
tabindex="1"
|
||||||
|
@ -698,12 +698,16 @@ class UsersController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:include_mentionable_groups] == "true" && current_user
|
if current_user
|
||||||
to_render[:groups] = Group.mentionable(current_user)
|
groups =
|
||||||
.where("name ILIKE :term_like", term_like: "#{term}%")
|
if params[:include_mentionable_groups] == 'true'
|
||||||
.map do |m|
|
Group.mentionable(current_user)
|
||||||
{ name: m.name, full_name: m.full_name }
|
elsif params[:include_messageable_groups] == 'true'
|
||||||
|
Group.messageable(current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
to_render[:groups] = groups.where("name ILIKE :term_like", term_like: "#{term}%")
|
||||||
|
.map { |m| { name: m.name, full_name: m.full_name } }
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: to_render
|
render json: to_render
|
||||||
|
@ -1601,88 +1601,6 @@ describe UsersController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "search_users" do
|
|
||||||
|
|
||||||
let(:topic) { Fabricate :topic }
|
|
||||||
let(:user) { Fabricate :user, username: "joecabot", name: "Lawrence Tierney" }
|
|
||||||
|
|
||||||
before do
|
|
||||||
SearchIndexer.enable
|
|
||||||
Fabricate :post, user: user, topic: topic
|
|
||||||
end
|
|
||||||
|
|
||||||
it "searches when provided the term only" do
|
|
||||||
post :search_users, params: { term: user.name.split(" ").last }, format: :json
|
|
||||||
expect(response).to be_success
|
|
||||||
json = JSON.parse(response.body)
|
|
||||||
expect(json["users"].map { |u| u["username"] }).to include(user.username)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "searches when provided the topic only" do
|
|
||||||
post :search_users, params: { topic_id: topic.id }, format: :json
|
|
||||||
expect(response).to be_success
|
|
||||||
json = JSON.parse(response.body)
|
|
||||||
expect(json["users"].map { |u| u["username"] }).to include(user.username)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "searches when provided the term and topic" do
|
|
||||||
post :search_users, params: {
|
|
||||||
term: user.name.split(" ").last, topic_id: topic.id
|
|
||||||
}, format: :json
|
|
||||||
|
|
||||||
expect(response).to be_success
|
|
||||||
json = JSON.parse(response.body)
|
|
||||||
expect(json["users"].map { |u| u["username"] }).to include(user.username)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "searches only for users who have access to private topic" do
|
|
||||||
privileged_user = Fabricate(:user, trust_level: 4, username: "joecabit", name: "Lawrence Tierney")
|
|
||||||
privileged_group = Fabricate(:group)
|
|
||||||
privileged_group.add(privileged_user)
|
|
||||||
privileged_group.save
|
|
||||||
|
|
||||||
category = Fabricate(:category)
|
|
||||||
category.set_permissions(privileged_group => :readonly)
|
|
||||||
category.save
|
|
||||||
|
|
||||||
private_topic = Fabricate(:topic, category: category)
|
|
||||||
|
|
||||||
post :search_users, params: {
|
|
||||||
term: user.name.split(" ").last, topic_id: private_topic.id, topic_allowed_users: "true"
|
|
||||||
}, format: :json
|
|
||||||
|
|
||||||
expect(response).to be_success
|
|
||||||
json = JSON.parse(response.body)
|
|
||||||
expect(json["users"].map { |u| u["username"] }).to_not include(user.username)
|
|
||||||
expect(json["users"].map { |u| u["username"] }).to include(privileged_user.username)
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when `enable_names` is true" do
|
|
||||||
before do
|
|
||||||
SiteSetting.enable_names = true
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns names" do
|
|
||||||
post :search_users, params: { term: user.name }, format: :json
|
|
||||||
json = JSON.parse(response.body)
|
|
||||||
expect(json["users"].map { |u| u["name"] }).to include(user.name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when `enable_names` is false" do
|
|
||||||
before do
|
|
||||||
SiteSetting.enable_names = false
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns names" do
|
|
||||||
post :search_users, params: { term: user.name }, format: :json
|
|
||||||
json = JSON.parse(response.body)
|
|
||||||
expect(json["users"].map { |u| u["name"] }).not_to include(user.name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'send_activation_email' do
|
describe 'send_activation_email' do
|
||||||
context 'for an existing user' do
|
context 'for an existing user' do
|
||||||
let(:user) { Fabricate(:user, active: false) }
|
let(:user) { Fabricate(:user, active: false) }
|
||||||
|
@ -85,4 +85,136 @@ RSpec.describe UsersController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "search_users" do
|
||||||
|
let(:topic) { Fabricate :topic }
|
||||||
|
let(:user) { Fabricate :user, username: "joecabot", name: "Lawrence Tierney" }
|
||||||
|
let(:post1) { Fabricate(:post, user: user, topic: topic) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
SearchIndexer.enable
|
||||||
|
post1
|
||||||
|
end
|
||||||
|
|
||||||
|
it "searches when provided the term only" do
|
||||||
|
get "/u/search/users.json", params: { term: user.name.split(" ").last }
|
||||||
|
expect(response).to be_success
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
expect(json["users"].map { |u| u["username"] }).to include(user.username)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "searches when provided the topic only" do
|
||||||
|
get "/u/search/users.json", params: { topic_id: topic.id }
|
||||||
|
expect(response).to be_success
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
expect(json["users"].map { |u| u["username"] }).to include(user.username)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "searches when provided the term and topic" do
|
||||||
|
get "/u/search/users.json", params: {
|
||||||
|
term: user.name.split(" ").last, topic_id: topic.id
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(response).to be_success
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
expect(json["users"].map { |u| u["username"] }).to include(user.username)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "searches only for users who have access to private topic" do
|
||||||
|
privileged_user = Fabricate(:user, trust_level: 4, username: "joecabit", name: "Lawrence Tierney")
|
||||||
|
privileged_group = Fabricate(:group)
|
||||||
|
privileged_group.add(privileged_user)
|
||||||
|
privileged_group.save
|
||||||
|
|
||||||
|
category = Fabricate(:category)
|
||||||
|
category.set_permissions(privileged_group => :readonly)
|
||||||
|
category.save
|
||||||
|
|
||||||
|
private_topic = Fabricate(:topic, category: category)
|
||||||
|
|
||||||
|
get "/u/search/users.json", params: {
|
||||||
|
term: user.name.split(" ").last, topic_id: private_topic.id, topic_allowed_users: "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(response).to be_success
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
expect(json["users"].map { |u| u["username"] }).to_not include(user.username)
|
||||||
|
expect(json["users"].map { |u| u["username"] }).to include(privileged_user.username)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when `enable_names` is true" do
|
||||||
|
before do
|
||||||
|
SiteSetting.enable_names = true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns names" do
|
||||||
|
get "/u/search/users.json", params: { term: user.name }
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
expect(json["users"].map { |u| u["name"] }).to include(user.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when `enable_names` is false" do
|
||||||
|
before do
|
||||||
|
SiteSetting.enable_names = false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns names" do
|
||||||
|
get "/u/search/users.json", params: { term: user.name }
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
expect(json["users"].map { |u| u["name"] }).not_to include(user.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'groups' do
|
||||||
|
let!(:mentionable_group) { Fabricate(:group, mentionable_level: 99, messageable_level: 0) }
|
||||||
|
let!(:messageable_group) { Fabricate(:group, mentionable_level: 0, messageable_level: 99) }
|
||||||
|
|
||||||
|
describe 'when signed in' do
|
||||||
|
before do
|
||||||
|
sign_in(user)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "searches for messageable groups" do
|
||||||
|
get "/u/search/users.json", params: {
|
||||||
|
include_mentionable_groups: 'false',
|
||||||
|
include_messageable_groups: 'true'
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(response).to be_success
|
||||||
|
expect(JSON.parse(response.body)["groups"].first['name']).to eq(messageable_group.name)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'searches for mentionable groups' do
|
||||||
|
get "/u/search/users.json", params: {
|
||||||
|
include_messageable_groups: 'false',
|
||||||
|
include_mentionable_groups: 'true'
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(response).to be_success
|
||||||
|
expect(JSON.parse(response.body)["groups"].first['name']).to eq(mentionable_group.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'when not signed in' do
|
||||||
|
it 'should not include mentionable/messageable groups' do
|
||||||
|
get "/u/search/users.json", params: {
|
||||||
|
include_mentionable_groups: 'false',
|
||||||
|
include_messageable_groups: 'true'
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(response).to be_success
|
||||||
|
expect(JSON.parse(response.body)["groups"]).to eq(nil)
|
||||||
|
|
||||||
|
get "/u/search/users.json", params: {
|
||||||
|
include_messageable_groups: 'false',
|
||||||
|
include_mentionable_groups: 'true'
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(response).to be_success
|
||||||
|
expect(JSON.parse(response.body)["groups"]).to eq(nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user