mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Add "Group owners" to posting options for groups
Context: https://meta.discourse.org/t/121589 This new setting option lets group owners message/mention large groups without granting that privilege to all members.
This commit is contained in:
parent
9cd3f96dee
commit
7b0517895e
@ -40,6 +40,7 @@ export default Ember.Component.extend({
|
|||||||
{ name: I18n.t("groups.alias_levels.only_admins"), value: 1 },
|
{ name: I18n.t("groups.alias_levels.only_admins"), value: 1 },
|
||||||
{ name: I18n.t("groups.alias_levels.mods_and_admins"), value: 2 },
|
{ name: I18n.t("groups.alias_levels.mods_and_admins"), value: 2 },
|
||||||
{ name: I18n.t("groups.alias_levels.members_mods_and_admins"), value: 3 },
|
{ name: I18n.t("groups.alias_levels.members_mods_and_admins"), value: 3 },
|
||||||
|
{ name: I18n.t("groups.alias_levels.owners_mods_and_admins"), value: 4 },
|
||||||
{ name: I18n.t("groups.alias_levels.everyone"), value: 99 }
|
{ name: I18n.t("groups.alias_levels.everyone"), value: 99 }
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
@ -83,6 +83,7 @@ class Group < ActiveRecord::Base
|
|||||||
only_admins: 1,
|
only_admins: 1,
|
||||||
mods_and_admins: 2,
|
mods_and_admins: 2,
|
||||||
members_mods_and_admins: 3,
|
members_mods_and_admins: 3,
|
||||||
|
owners_mods_and_admins: 4,
|
||||||
everyone: 99
|
everyone: 99
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,6 +165,9 @@ class Group < ActiveRecord::Base
|
|||||||
(
|
(
|
||||||
messageable_level = #{ALIAS_LEVELS[:members_mods_and_admins]} AND id in (
|
messageable_level = #{ALIAS_LEVELS[:members_mods_and_admins]} AND id in (
|
||||||
SELECT group_id FROM group_users WHERE user_id = :user_id)
|
SELECT group_id FROM group_users WHERE user_id = :user_id)
|
||||||
|
) OR (
|
||||||
|
messageable_level = #{ALIAS_LEVELS[:owners_mods_and_admins]} AND id in (
|
||||||
|
SELECT group_id FROM group_users WHERE user_id = :user_id AND owner IS TRUE)
|
||||||
)", levels: alias_levels(user), user_id: user && user.id)
|
)", levels: alias_levels(user), user_id: user && user.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,6 +178,10 @@ class Group < ActiveRecord::Base
|
|||||||
mentionable_level = #{ALIAS_LEVELS[:members_mods_and_admins]}
|
mentionable_level = #{ALIAS_LEVELS[:members_mods_and_admins]}
|
||||||
AND id in (
|
AND id in (
|
||||||
SELECT group_id FROM group_users WHERE user_id = :user_id)
|
SELECT group_id FROM group_users WHERE user_id = :user_id)
|
||||||
|
) OR (
|
||||||
|
mentionable_level = #{ALIAS_LEVELS[:owners_mods_and_admins]}
|
||||||
|
AND id in (
|
||||||
|
SELECT group_id FROM group_users WHERE user_id = :user_id AND owner IS TRUE)
|
||||||
)
|
)
|
||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
@ -185,11 +193,13 @@ class Group < ActiveRecord::Base
|
|||||||
levels = [ALIAS_LEVELS[:everyone],
|
levels = [ALIAS_LEVELS[:everyone],
|
||||||
ALIAS_LEVELS[:only_admins],
|
ALIAS_LEVELS[:only_admins],
|
||||||
ALIAS_LEVELS[:mods_and_admins],
|
ALIAS_LEVELS[:mods_and_admins],
|
||||||
ALIAS_LEVELS[:members_mods_and_admins]]
|
ALIAS_LEVELS[:members_mods_and_admins],
|
||||||
|
ALIAS_LEVELS[:owners_mods_and_admins]]
|
||||||
elsif user && user.moderator?
|
elsif user && user.moderator?
|
||||||
levels = [ALIAS_LEVELS[:everyone],
|
levels = [ALIAS_LEVELS[:everyone],
|
||||||
ALIAS_LEVELS[:mods_and_admins],
|
ALIAS_LEVELS[:mods_and_admins],
|
||||||
ALIAS_LEVELS[:members_mods_and_admins]]
|
ALIAS_LEVELS[:members_mods_and_admins],
|
||||||
|
ALIAS_LEVELS[:owners_mods_and_admins]]
|
||||||
end
|
end
|
||||||
|
|
||||||
levels
|
levels
|
||||||
|
@ -661,6 +661,7 @@ en:
|
|||||||
only_admins: "Only admins"
|
only_admins: "Only admins"
|
||||||
mods_and_admins: "Only moderators and Admins"
|
mods_and_admins: "Only moderators and Admins"
|
||||||
members_mods_and_admins: "Only group members, moderators and admins"
|
members_mods_and_admins: "Only group members, moderators and admins"
|
||||||
|
owners_mods_and_admins: "Only group owners, moderators and admins"
|
||||||
everyone: "Everyone"
|
everyone: "Everyone"
|
||||||
notifications:
|
notifications:
|
||||||
watching:
|
watching:
|
||||||
|
@ -346,6 +346,25 @@ describe Guardian do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "respects the group members messageable_level" do
|
||||||
|
group.update!(messageable_level: Group::ALIAS_LEVELS[:members_mods_and_admins])
|
||||||
|
expect(Guardian.new(user).can_send_private_message?(group)).to eq(false)
|
||||||
|
|
||||||
|
group.add(user)
|
||||||
|
expect(Guardian.new(user).can_send_private_message?(group)).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "respects the group owners messageable_level" do
|
||||||
|
group.update!(messageable_level: Group::ALIAS_LEVELS[:owners_mods_and_admins])
|
||||||
|
expect(Guardian.new(user).can_send_private_message?(group)).to eq(false)
|
||||||
|
|
||||||
|
group.add(user)
|
||||||
|
expect(Guardian.new(user).can_send_private_message?(group)).to eq(false)
|
||||||
|
|
||||||
|
group.add_owner(user)
|
||||||
|
expect(Guardian.new(user).can_send_private_message?(group)).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
context 'target user has private message disabled' do
|
context 'target user has private message disabled' do
|
||||||
before do
|
before do
|
||||||
another_user.user_option.update!(allow_private_messages: false)
|
another_user.user_option.update!(allow_private_messages: false)
|
||||||
|
@ -1020,6 +1020,23 @@ describe Post do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'when group owner can mention a group' do
|
||||||
|
before do
|
||||||
|
group.update!(mentionable_level: Group::ALIAS_LEVELS[:owners_mods_and_admins])
|
||||||
|
group.add_owner(post.user)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should create the mention' do
|
||||||
|
post.update!(raw: "hello @#{group.name}")
|
||||||
|
post.trigger_post_process
|
||||||
|
post.reload
|
||||||
|
|
||||||
|
expect(post.cooked).to eq(
|
||||||
|
%Q|<p>hello <a class="mention-group" href="/groups/#{group.name}">@#{group.name}</a></p>|
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -286,6 +286,14 @@ describe PostAlerter do
|
|||||||
}.to change(evil_trout.notifications, :count).by(0)
|
}.to change(evil_trout.notifications, :count).by(0)
|
||||||
|
|
||||||
expect(GroupMention.count).to eq(3)
|
expect(GroupMention.count).to eq(3)
|
||||||
|
|
||||||
|
group.update_columns(mentionable_level: Group::ALIAS_LEVELS[:owners_mods_and_admins])
|
||||||
|
group.add_owner(user)
|
||||||
|
expect {
|
||||||
|
create_post_with_alerts(raw: "Hello @group the owner can mention you", user: user)
|
||||||
|
}.to change(evil_trout.notifications, :count).by(1)
|
||||||
|
|
||||||
|
expect(GroupMention.count).to eq(4)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "triggers :before_create_notifications_for_users" do
|
it "triggers :before_create_notifications_for_users" do
|
||||||
|
Loading…
Reference in New Issue
Block a user