FIX: If a group is unmentionable, don't render it as mentionable

Now if a group is visible but unmentionable, users can search for it
when composing by typing with `@`, but it will be rendered without the
grey background color.

It will also no longer pop up a JIT warning saying "You are about to
mention X people" because the group will not be mentioned.
This commit is contained in:
Robin Ward 2020-02-14 12:27:46 -05:00
parent c31039d51f
commit d51107e2c9
5 changed files with 28 additions and 10 deletions

View File

@ -51,6 +51,8 @@ function updateFound($mentions, usernames) {
group: true,
mentionable: mentionableGroups[username]
});
} else if (foundGroups[username]) {
replaceSpan($e, username, { group: true });
} else if (checked[username]) {
$e.addClass("mention-tested");
}

View File

@ -760,12 +760,15 @@ blockquote > *:last-child {
a.mention,
a.mention-group {
padding: 2px 4px;
color: dark-light-choose($primary-high, $secondary-low);
background: $primary-low;
border-radius: 8px;
font-weight: bold;
font-size: 0.93em;
color: $primary;
&.notify {
color: dark-light-choose($primary-high, $secondary-low);
padding: 2px 4px;
background: $primary-low;
border-radius: 8px;
}
}
.popup-menu {

View File

@ -308,7 +308,7 @@ class UsersController < ApplicationController
groups = Group.where(name: usernames).pluck(:name)
mentionable_groups =
if current_user
Group.mentionable(current_user)
Group.mentionable(current_user, include_public: false)
.where(name: usernames)
.pluck(:name, :user_count)
.map do |name, user_count|

View File

@ -2402,7 +2402,10 @@ describe UsersController do
describe '#is_local_username' do
fab!(:user) { Fabricate(:user) }
fab!(:group) { Fabricate(:group, name: "Discourse") }
fab!(:group) { Fabricate(:group, name: "Discourse", mentionable_level: Group::ALIAS_LEVELS[:everyone]) }
let(:unmentionable) {
Fabricate(:group, name: "Unmentionable", mentionable_level: Group::ALIAS_LEVELS[:nobody])
}
fab!(:topic) { Fabricate(:topic) }
fab!(:allowed_user) { Fabricate(:user) }
let(:private_topic) { Fabricate(:private_message_topic, user: allowed_user) }
@ -2416,11 +2419,21 @@ describe UsersController do
end
it "finds the group" do
sign_in(user)
get "/u/is_local_username.json", params: { username: group.name }
expect(response.status).to eq(200)
json = JSON.parse(response.body)
expect(json["valid_groups"][0]).to eq(group.name)
expect(json["valid_groups"]).to include(group.name)
expect(json["mentionable_groups"].find { |g| g['name'] == group.name }).to be_present
end
it "finds unmentionable groups" do
sign_in(user)
get "/u/is_local_username.json", params: { username: unmentionable.name }
expect(response.status).to eq(200)
json = JSON.parse(response.body)
expect(json["valid_groups"]).to include(unmentionable.name)
expect(json["mentionable_groups"]).to be_blank
end
it "supports multiples usernames" do

View File

@ -55,7 +55,7 @@ QUnit.test("linkSeenMentions replaces users and groups", async assert => {
});
assert.equal($("a", $root)[0].text, "@valid_user");
assert.equal($("a", $root)[1].text, "@mentionable_group");
assert.equal($("a", $root)[1].text, "@valid_group");
assert.equal($("a.notify", $root).text(), "@mentionable_group");
assert.equal($("span.mention", $root)[0].innerHTML, "@invalid");
assert.equal($("span.mention", $root)[1].innerHTML, "@valid_group");
});