A platform for community discussion. Free, open, simple.
FEATURE: Add "Group owners" to posting options for groups
Penar Musaraj7b0517895e10
diff --git a/app/assets/javascripts/discourse/components/groups-form-interaction-fields.js.es6 b/app/assets/javascripts/discourse/components/groups-form-interaction-fields.js.es6index 3b792fdbf3d..f4756978a65 100644--- a/app/assets/javascripts/discourse/components/groups-form-interaction-fields.js.es6+++ b/app/assets/javascripts/discourse/components/groups-form-interaction-fields.js.es6@@ -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.mods_and_admins"), value: 2 },{ 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 }];},diff --git a/app/models/group.rb b/app/models/group.rbindex 19cad44a4f9..92515247ba7 100644--- a/app/models/group.rb+++ b/app/models/group.rb@@ -83,6 +83,7 @@ class Group < ActiveRecord::Baseonly_admins: 1,mods_and_admins: 2,members_mods_and_admins: 3,+ owners_mods_and_admins: 4,everyone: 99}@@ -164,6 +165,9 @@ class Group < ActiveRecord::Base(messageable_level = #{ALIAS_LEVELS[:members_mods_and_admins]} AND id in (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)}@@ -174,7 +178,11 @@ class Group < ActiveRecord::Basementionable_level = #{ALIAS_LEVELS[:members_mods_and_admins]}AND id in (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)+ )SQLend@@ -185,11 +193,13 @@ class Group < ActiveRecord::Baselevels = [ALIAS_LEVELS[:everyone],ALIAS_LEVELS[:only_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?levels = [ALIAS_LEVELS[:everyone],ALIAS_LEVELS[:mods_and_admins],- ALIAS_LEVELS[:members_mods_and_admins]]+ ALIAS_LEVELS[:members_mods_and_admins],+ ALIAS_LEVELS[:owners_mods_and_admins]]endlevelsdiff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex b7d2452fc5c..aad6399c5f2 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -661,6 +661,7 @@ en:only_admins: "Only admins"mods_and_admins: "Only 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"notifications:watching:diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rbindex adab91e7288..aab726c5667 100644--- a/spec/components/guardian_spec.rb+++ b/spec/components/guardian_spec.rb@@ -346,6 +346,25 @@ describe Guardian doendend+ 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' dobefore doanother_user.user_option.update!(allow_private_messages: false)diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rbindex 529306015c0..77ce5688ab9 100644--- a/spec/models/post_spec.rb+++ b/spec/models/post_spec.rb@@ -1020,6 +1020,23 @@ describe Post do)endend++ 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+ endendenddiff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rbindex 9e3c4bba510..d8e38e7773c 100644--- a/spec/services/post_alerter_spec.rb+++ b/spec/services/post_alerter_spec.rb@@ -286,6 +286,14 @@ describe PostAlerter do}.to change(evil_trout.notifications, :count).by(0)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)endit "triggers :before_create_notifications_for_users" do