mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
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:
@ -51,6 +51,8 @@ function updateFound($mentions, usernames) {
|
|||||||
group: true,
|
group: true,
|
||||||
mentionable: mentionableGroups[username]
|
mentionable: mentionableGroups[username]
|
||||||
});
|
});
|
||||||
|
} else if (foundGroups[username]) {
|
||||||
|
replaceSpan($e, username, { group: true });
|
||||||
} else if (checked[username]) {
|
} else if (checked[username]) {
|
||||||
$e.addClass("mention-tested");
|
$e.addClass("mention-tested");
|
||||||
}
|
}
|
||||||
|
@ -760,12 +760,15 @@ blockquote > *:last-child {
|
|||||||
|
|
||||||
a.mention,
|
a.mention,
|
||||||
a.mention-group {
|
a.mention-group {
|
||||||
padding: 2px 4px;
|
|
||||||
color: dark-light-choose($primary-high, $secondary-low);
|
|
||||||
background: $primary-low;
|
|
||||||
border-radius: 8px;
|
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-size: 0.93em;
|
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 {
|
.popup-menu {
|
||||||
|
@ -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(current_user, include_public: false)
|
||||||
.where(name: usernames)
|
.where(name: usernames)
|
||||||
.pluck(:name, :user_count)
|
.pluck(:name, :user_count)
|
||||||
.map do |name, user_count|
|
.map do |name, user_count|
|
||||||
|
@ -2402,7 +2402,10 @@ describe UsersController do
|
|||||||
|
|
||||||
describe '#is_local_username' do
|
describe '#is_local_username' do
|
||||||
fab!(:user) { Fabricate(:user) }
|
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!(:topic) { Fabricate(:topic) }
|
||||||
fab!(:allowed_user) { Fabricate(:user) }
|
fab!(:allowed_user) { Fabricate(:user) }
|
||||||
let(:private_topic) { Fabricate(:private_message_topic, user: allowed_user) }
|
let(:private_topic) { Fabricate(:private_message_topic, user: allowed_user) }
|
||||||
@ -2416,11 +2419,21 @@ describe UsersController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "finds the group" do
|
it "finds the group" do
|
||||||
|
sign_in(user)
|
||||||
get "/u/is_local_username.json", params: { username: group.name }
|
get "/u/is_local_username.json", params: { username: group.name }
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
json = JSON.parse(response.body)
|
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
|
end
|
||||||
|
|
||||||
it "supports multiples usernames" do
|
it "supports multiples usernames" do
|
||||||
|
@ -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)[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)[0].innerHTML, "@invalid");
|
||||||
assert.equal($("span.mention", $root)[1].innerHTML, "@valid_group");
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user