Improvements to group mentions (#8927)

* FIX: Avoid highlight mention to groups that are not public
* UX: Composer autocomplete will suggest all visible group names
This commit is contained in:
Dan Ungureanu 2020-02-12 10:11:10 +02:00 committed by GitHub
parent fc3d547268
commit 3f50481188
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 9 deletions

View File

@ -180,7 +180,7 @@ export default Component.extend({
term, term,
topicId, topicId,
categoryId, categoryId,
includeMentionableGroups: true includeGroups: true
}); });
}, },

View File

@ -308,7 +308,7 @@ class UsersController < ApplicationController
groups = Group.where(name: usernames).pluck(:name) groups = Group.where(name: usernames).pluck(:name)
mentionable_groups = mentionable_groups =
if current_user if current_user
Group.mentionable(current_user) Group.mentionable
.where(name: usernames) .where(name: usernames)
.pluck(:name, :user_count) .pluck(:name, :user_count)
.map do |name, user_count| .map do |name, user_count|
@ -901,22 +901,21 @@ class UsersController < ApplicationController
groups = groups =
if current_user if current_user
if params[:include_mentionable_groups] == 'true' if params[:include_groups] == 'true'
Group.visible_groups(current_user)
elsif params[:include_mentionable_groups] == 'true'
Group.mentionable(current_user) Group.mentionable(current_user)
elsif params[:include_messageable_groups] == 'true' elsif params[:include_messageable_groups] == 'true'
Group.messageable(current_user) Group.messageable(current_user)
end end
end end
include_groups = params[:include_groups] == "true"
# blank term is only handy for in-topic search of users after @ # blank term is only handy for in-topic search of users after @
# we do not want group results ever if term is blank # we do not want group results ever if term is blank
include_groups = groups = nil if term.blank? groups = nil if term.blank?
if include_groups || groups if groups
groups = Group.search_groups(term, groups: groups) groups = Group.search_groups(term, groups: groups)
groups = groups.where(visibility_level: Group.visibility_levels[:public]) if include_groups
groups = groups.order('groups.name asc') groups = groups.order('groups.name asc')
to_render[:groups] = groups.map do |m| to_render[:groups] = groups.map do |m|

View File

@ -3176,6 +3176,15 @@ describe UsersController do
) )
end end
let!(:private_group) do
Fabricate(:group,
mentionable_level: Group::ALIAS_LEVELS[:members_mods_and_admins],
messageable_level: Group::ALIAS_LEVELS[:members_mods_and_admins],
visibility_level: Group.visibility_levels[:members],
name: 'aaa4'
)
end
describe 'when signed in' do describe 'when signed in' do
before do before do
sign_in(user) sign_in(user)
@ -3198,7 +3207,7 @@ describe UsersController do
groups = JSON.parse(response.body)["groups"] groups = JSON.parse(response.body)["groups"]
expect(groups.map { |group| group['name'] }) expect(groups.map { |group| group['name'] })
.to_not include(mentionable_group_2.name) .to_not include(private_group.name)
end end
it "doesn't search for groups" do it "doesn't search for groups" do