UX: Include public groups in mentionable groups set (#8516)
This commit is contained in:
parent
9f4c9bafa1
commit
3ec2081059
|
@ -204,8 +204,8 @@ class Group < ActiveRecord::Base
|
||||||
groups
|
groups
|
||||||
}
|
}
|
||||||
|
|
||||||
scope :mentionable, lambda { |user|
|
scope :mentionable, lambda { |user, include_public: true|
|
||||||
where(self.mentionable_sql_clause,
|
where(self.mentionable_sql_clause(include_public: include_public),
|
||||||
levels: alias_levels(user),
|
levels: alias_levels(user),
|
||||||
user_id: user&.id
|
user_id: user&.id
|
||||||
)
|
)
|
||||||
|
@ -222,8 +222,8 @@ class Group < ActiveRecord::Base
|
||||||
)", levels: alias_levels(user), user_id: user && user.id)
|
)", levels: alias_levels(user), user_id: user && user.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
def self.mentionable_sql_clause
|
def self.mentionable_sql_clause(include_public: true)
|
||||||
<<~SQL
|
clause = +<<~SQL
|
||||||
mentionable_level in (:levels)
|
mentionable_level in (:levels)
|
||||||
OR (
|
OR (
|
||||||
mentionable_level = #{ALIAS_LEVELS[:members_mods_and_admins]}
|
mentionable_level = #{ALIAS_LEVELS[:members_mods_and_admins]}
|
||||||
|
@ -235,6 +235,12 @@ class Group < ActiveRecord::Base
|
||||||
SELECT group_id FROM group_users WHERE user_id = :user_id AND owner IS TRUE)
|
SELECT group_id FROM group_users WHERE user_id = :user_id AND owner IS TRUE)
|
||||||
)
|
)
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
|
if include_public
|
||||||
|
clause << "OR visibility_level = #{Group.visibility_levels[:public]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
clause
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.alias_levels(user)
|
def self.alias_levels(user)
|
||||||
|
|
|
@ -458,7 +458,7 @@ class PostAlerter
|
||||||
def expand_group_mentions(groups, post)
|
def expand_group_mentions(groups, post)
|
||||||
return unless post.user && groups
|
return unless post.user && groups
|
||||||
|
|
||||||
Group.mentionable(post.user).where(id: groups.map(&:id)).each do |group|
|
Group.mentionable(post.user, include_public: false).where(id: groups.map(&:id)).each do |group|
|
||||||
next if group.user_count >= SiteSetting.max_users_notified_per_group_mention
|
next if group.user_count >= SiteSetting.max_users_notified_per_group_mention
|
||||||
yield group, group.users
|
yield group, group.users
|
||||||
end
|
end
|
||||||
|
|
|
@ -341,7 +341,10 @@ describe PrettyText do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not create mention for a non mentionable group" do
|
it "does not create mention for a non mentionable group" do
|
||||||
group = Fabricate(:group, mentionable_level: Group::ALIAS_LEVELS[:nobody])
|
group = Fabricate(:group,
|
||||||
|
visibility_level: Group.visibility_levels[:members],
|
||||||
|
mentionable_level: Group::ALIAS_LEVELS[:nobody]
|
||||||
|
)
|
||||||
|
|
||||||
expect(PrettyText.cook("test @#{group.name} test")).to eq(
|
expect(PrettyText.cook("test @#{group.name} test")).to eq(
|
||||||
%Q|<p>test <span class="mention">@#{group.name}</span> test</p>|
|
%Q|<p>test <span class="mention">@#{group.name}</span> test</p>|
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe Group do
|
||||||
|
let(:group) do
|
||||||
|
Fabricate(
|
||||||
|
:group,
|
||||||
|
visibility_level: Group.visibility_levels[:public],
|
||||||
|
mentionable_level: Group::ALIAS_LEVELS[:nobody],
|
||||||
|
users: [ Fabricate(:user) ]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:post) { Fabricate(:post, raw: "mention @#{group.name}") }
|
||||||
|
|
||||||
|
before do
|
||||||
|
Jobs.run_immediately!
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'users can mention public groups, but does not create a notification' do
|
||||||
|
expect { post }.not_to change { Notification.where(notification_type: Notification.types[:group_mentioned]).count }
|
||||||
|
expect(post.cooked).to include("<a class=\"mention-group\" href=\"/groups/#{group.name}\">@#{group.name}</a>")
|
||||||
|
end
|
||||||
|
end
|
|
@ -985,6 +985,7 @@ describe Post do
|
||||||
describe 'mentions' do
|
describe 'mentions' do
|
||||||
fab!(:group) do
|
fab!(:group) do
|
||||||
Fabricate(:group,
|
Fabricate(:group,
|
||||||
|
visibility_level: Group.visibility_levels[:members],
|
||||||
mentionable_level: Group::ALIAS_LEVELS[:members_mods_and_admins]
|
mentionable_level: Group::ALIAS_LEVELS[:members_mods_and_admins]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -451,6 +451,11 @@ describe GroupsController do
|
||||||
it "should return the right response" do
|
it "should return the right response" do
|
||||||
sign_in(user)
|
sign_in(user)
|
||||||
|
|
||||||
|
group.update!(
|
||||||
|
mentionable_level: Group::ALIAS_LEVELS[:owners_mods_and_admins],
|
||||||
|
visibility_level: Group.visibility_levels[:logged_on_users]
|
||||||
|
)
|
||||||
|
|
||||||
get "/groups/#{group.name}/mentionable.json"
|
get "/groups/#{group.name}/mentionable.json"
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
|
|
||||||
|
@ -467,6 +472,17 @@ describe GroupsController do
|
||||||
|
|
||||||
response_body = JSON.parse(response.body)
|
response_body = JSON.parse(response.body)
|
||||||
expect(response_body["mentionable"]).to eq(true)
|
expect(response_body["mentionable"]).to eq(true)
|
||||||
|
|
||||||
|
group.update!(
|
||||||
|
mentionable_level: Group::ALIAS_LEVELS[:nobody],
|
||||||
|
visibility_level: Group.visibility_levels[:public]
|
||||||
|
)
|
||||||
|
|
||||||
|
get "/groups/#{group.name}/mentionable.json"
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
|
||||||
|
response_body = JSON.parse(response.body)
|
||||||
|
expect(response_body["mentionable"]).to eq(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3163,26 +3163,27 @@ describe UsersController do
|
||||||
context 'groups' do
|
context 'groups' do
|
||||||
let!(:mentionable_group) do
|
let!(:mentionable_group) do
|
||||||
Fabricate(:group,
|
Fabricate(:group,
|
||||||
mentionable_level: 99,
|
mentionable_level: Group::ALIAS_LEVELS[:everyone],
|
||||||
messageable_level: 0,
|
messageable_level: Group::ALIAS_LEVELS[:nobody],
|
||||||
visibility_level: 0,
|
visibility_level: Group.visibility_levels[:public],
|
||||||
name: 'aaa1'
|
name: 'aaa1'
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
let!(:mentionable_group_2) do
|
let!(:mentionable_group_2) do
|
||||||
Fabricate(:group,
|
Fabricate(:group,
|
||||||
mentionable_level: 99,
|
mentionable_level: Group::ALIAS_LEVELS[:everyone],
|
||||||
messageable_level: 0,
|
messageable_level: Group::ALIAS_LEVELS[:nobody],
|
||||||
visibility_level: 1,
|
visibility_level: Group.visibility_levels[:logged_on_users],
|
||||||
name: 'aaa2'
|
name: 'aaa2'
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
let!(:messageable_group) do
|
let!(:messageable_group) do
|
||||||
Fabricate(:group,
|
Fabricate(:group,
|
||||||
mentionable_level: 0,
|
mentionable_level: Group::ALIAS_LEVELS[:nobody],
|
||||||
messageable_level: 99,
|
messageable_level: Group::ALIAS_LEVELS[:everyone],
|
||||||
|
visibility_level: Group.visibility_levels[:logged_on_users],
|
||||||
name: 'aaa3'
|
name: 'aaa3'
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue