Skip to content

A platform for community discussion. Free, open, simple.

FIX: UX improvements for system messages when PMs are disabled

Robin Ward782d75069ecc
diff --git a/app/assets/javascripts/discourse/components/topic-footer-buttons.js.es6 b/app/assets/javascripts/discourse/components/topic-footer-buttons.js.es6
index e370f0d3379..d5ae0f8b0ad 100644
--- a/app/assets/javascripts/discourse/components/topic-footer-buttons.js.es6
+++ b/app/assets/javascripts/discourse/components/topic-footer-buttons.js.es6
@@ -6,6 +6,16 @@ export default Ember.Component.extend({
// Allow us to extend it
layoutName: 'components/topic-footer-buttons',
+ @computed('topic.isPrivateMessage')
+ canArchive(isPM) {
+ return this.siteSettings.enable_private_messages && isPM;
+ },
+
+ @computed('topic.isPrivateMessage')
+ showNotificationsButton(isPM) {
+ return (!isPM) || this.siteSettings.enable_private_messages;
+ },
+
@computed('topic.details.can_invite_to')
canInviteTo(result) {
return !this.site.mobileView && result;
diff --git a/app/assets/javascripts/discourse/templates/components/topic-footer-buttons.hbs b/app/assets/javascripts/discourse/templates/components/topic-footer-buttons.hbs
index 3af1dba0172..b38900977fb 100644
--- a/app/assets/javascripts/discourse/templates/components/topic-footer-buttons.hbs
+++ b/app/assets/javascripts/discourse/templates/components/topic-footer-buttons.hbs
@@ -50,8 +50,8 @@
disabled=inviteDisabled}}
{{/if}}
- {{#if topic.isPrivateMessage}}
- {{d-button class="standard"
+ {{#if canArchive}}
+ {{d-button class="standard archive-topic"
title=archiveTitle
label=archiveLabel
icon=archiveIcon
@@ -79,7 +79,9 @@
{{pinned-button pinned=topic.pinned topic=topic}}
</div>
-{{topic-notifications-button notificationLevel=topic.details.notification_level topic=topic}}
+{{#if showNotificationsButton}}
+ {{topic-notifications-button notificationLevel=topic.details.notification_level topic=topic}}
+{{/if}}
{{plugin-outlet name="after-topic-footer-buttons"
args=(hash topic=topic)
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 1ae78c2e55b..84d12f05b5d 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -1034,6 +1034,7 @@ en:
summary_max_results: "Maximum posts returned by 'Summary This Topic'"
enable_private_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 private messages are disabled"
enable_private_email_messages: "Allow trust level 4 (configurable via min trust level to send messages) users to send private email messages. Note that staff can always send messages no matter what."
enable_long_polling: "Message bus used for notification can use long polling"
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 62c47d2cd25..f6a5471f63d 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -507,6 +507,8 @@ posting:
enable_private_messages:
default: true
client: true
+ enable_system_message_replies:
+ default: true
enable_private_email_messages:
default: false
client: true
diff --git a/lib/guardian/post_guardian.rb b/lib/guardian/post_guardian.rb
index d4ce94fdffe..bda12b7d947 100644
--- a/lib/guardian/post_guardian.rb
+++ b/lib/guardian/post_guardian.rb
@@ -80,6 +80,9 @@ module PostGuardian
# Creating Method
def can_create_post?(parent)
+
+ return false if !SiteSetting.enable_system_message_replies? && parent.try(:subtype) == "system_message"
+
(!SpamRule::AutoSilence.silence?(@user) || (!!parent.try(:private_message?) && parent.allowed_users.include?(@user))) && (
!parent ||
!parent.category ||
diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb
index df904c0aa40..a849e68cb22 100644
--- a/spec/components/guardian_spec.rb
+++ b/spec/components/guardian_spec.rb
@@ -857,6 +857,25 @@ describe Guardian do
end
end
+ context "system message" do
+ let(:private_message) {
+ Fabricate(
+ :topic,
+ archetype: Archetype.private_message,
+ subtype: 'system_message',
+ category_id: nil
+ )
+ }
+
+ before { user.save! }
+ it "allows the user to reply to system messages" do
+ expect(Guardian.new(user).can_create_post?(private_message)).to eq(true)
+ SiteSetting.enable_system_message_replies = false
+ expect(Guardian.new(user).can_create_post?(private_message)).to eq(false)
+ end
+
+ end
+
context "private message" do
let(:private_message) { Fabricate(:topic, archetype: Archetype.private_message, category_id: nil) }