From 4205c528d0b2422180e8b6f489f9e7fc6f0aa828 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 27 Aug 2018 11:38:11 +1000 Subject: [PATCH] FEATURE: hide enable_personal_email_messages and min_trust_to_send_email_messages These site settings are very hard to explain and only applicable for very specific Discourse setups. If an admin "enables staged users" which is used in support scenarios then all staff can send "messages" directly to an "email". The setting allows you to extend this to TL4 or any trust level. Actual use case would be a support type setup with restricted staff. It is quite rare so hiding this for now and re-evaluate keeping the setting in 2019 --- app/serializers/current_user_serializer.rb | 2 +- config/locales/server.en.yml | 5 ----- config/site_settings.yml | 2 ++ lib/guardian.rb | 13 +++++++++---- lib/topic_creator.rb | 2 +- spec/components/topic_creator_spec.rb | 6 +++--- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/serializers/current_user_serializer.rb b/app/serializers/current_user_serializer.rb index cd44c75f663..2ddfe2533ee 100644 --- a/app/serializers/current_user_serializer.rb +++ b/app/serializers/current_user_serializer.rb @@ -101,7 +101,7 @@ class CurrentUserSerializer < BasicUserSerializer end def can_send_private_email_messages - scope.cand_send_private_messages_to_email? + scope.can_send_private_messages_to_email? end def can_edit diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 3e1e7ef4677..8c4eca02b15 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1186,8 +1186,6 @@ en: enable_personal_messages: "Allow trust level 1 (configurable via min trust level to send messages) users to create messages and reply to messages. Note that staff can always send messages no matter what." enable_system_message_replies: "Allows users to reply to system messages, even if personal messages are disabled" - enable_personal_email_messages: "Allow trust level 4 (configurable via min trust level to send messages) users to send personal email messages. Note that staff can always send messages no matter what." - enable_long_polling: "Message bus used for notification can use long polling" long_polling_base_url: "Base URL used for long polling (when a CDN is serving dynamic content, be sure to set this to origin pull) eg: http://origin.site.com" long_polling_interval: "Amount of time the server should wait before responding to clients when there is no data to send (logged on users only)" @@ -1456,9 +1454,6 @@ en: min_trust_to_allow_self_wiki: "The minimum trust level required to make user's own post wiki." min_trust_to_send_messages: "The minimum trust level required to create new personal messages." - - min_trust_to_send_email_messages: "The minimum trust level required to send new personal messages via email (to staged users)." - min_trust_to_flag_posts: "The minimum trust level required to flag posts" min_trust_to_post_links: "The minimum trust level required to include links in posts" min_trust_to_post_images: "The minimum trust level required to include images in a post" diff --git a/config/site_settings.yml b/config/site_settings.yml index 2abaf22150c..6f4a14d3181 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -558,6 +558,7 @@ posting: enable_system_message_replies: default: true enable_personal_email_messages: + hidden: true default: false client: true validator: "EnablePrivateEmailMessagesValidator" @@ -1018,6 +1019,7 @@ trust: default: 1 enum: 'TrustLevelSetting' min_trust_to_send_email_messages: + hidden: true default: 4 enum: 'TrustLevelSetting' min_trust_to_flag_posts: diff --git a/lib/guardian.rb b/lib/guardian.rb index de87f2e9eae..8c7c6afb8d8 100644 --- a/lib/guardian.rb +++ b/lib/guardian.rb @@ -335,15 +335,20 @@ class Guardian (!is_silenced? || target.staff?) end - def cand_send_private_messages_to_email? + def can_send_private_messages_to_email? # Staged users must be enabled to create a temporary user. SiteSetting.enable_staged_users && # User is authenticated authenticated? && # User is trusted enough - @user.has_trust_level?(SiteSetting.min_trust_to_send_email_messages) && - # PMs to email addresses are enabled - (is_staff? || SiteSetting.enable_personal_email_messages) + (is_staff? || + ( + # TODO: 2019 evaluate if we need this flexibility + # perhaps we enable this unconditionally to TL4? + @user.has_trust_level?(SiteSetting.min_trust_to_send_email_messages) && + SiteSetting.enable_personal_email_messages + ) + ) end def can_see_emails? diff --git a/lib/topic_creator.rb b/lib/topic_creator.rb index 6394156fcb9..a62d42bd6fc 100644 --- a/lib/topic_creator.rb +++ b/lib/topic_creator.rb @@ -183,7 +183,7 @@ class TopicCreator rollback_with!(topic, :no_user_selected) end - if @opts[:target_emails].present? && !@guardian.cand_send_private_messages_to_email? then + if @opts[:target_emails].present? && !@guardian.can_send_private_messages_to_email? then rollback_with!(topic, :reply_by_email_disabled) end diff --git a/spec/components/topic_creator_spec.rb b/spec/components/topic_creator_spec.rb index e56da86f49e..aa9a47685af 100644 --- a/spec/components/topic_creator_spec.rb +++ b/spec/components/topic_creator_spec.rb @@ -126,7 +126,7 @@ describe TopicCreator do end end - context 'private message' do + context 'personal message' do context 'success cases' do before do @@ -146,7 +146,7 @@ describe TopicCreator do end it "should be possible for a trusted user to send private messages via email" do - SiteSetting.expects(:enable_personal_email_messages).returns(true) + SiteSetting.enable_personal_email_messages = true SiteSetting.min_trust_to_send_email_messages = TrustLevel[1] expect(TopicCreator.create(user, Guardian.new(user), pm_to_email_valid_attrs)).to be_valid @@ -155,7 +155,7 @@ describe TopicCreator do context 'failure cases' do it "should be rollback the changes when email is invalid" do - SiteSetting.expects(:enable_personal_email_messages).returns(true) + SiteSetting.enable_personal_email_messages = true SiteSetting.min_trust_to_send_email_messages = TrustLevel[1] attrs = pm_to_email_valid_attrs.dup attrs[:target_emails] = "t" * 256