A platform for community discussion. Free, open, simple.
FIX: Display unread/new PM links only when viewing own user. (#14290)
Alan Guo Xiang Tan7b77dd5c0557
diff --git a/app/assets/javascripts/discourse/app/templates/user/messages.hbs b/app/assets/javascripts/discourse/app/templates/user/messages.hbsindex fbe1bf4f2f3..248ab54c8ec 100644--- a/app/assets/javascripts/discourse/app/templates/user/messages.hbs+++ b/app/assets/javascripts/discourse/app/templates/user/messages.hbs@@ -31,16 +31,20 @@{{i18n "user.messages.sent"}}{{/link-to}}</li>- <li>- {{#link-to "userPrivateMessages.new" model class="new"}}- {{newLinkText}}- {{/link-to}}- </li>- <li>- {{#link-to "userPrivateMessages.unread" model class="unread"}}- {{unreadLinkText}}- {{/link-to}}- </li>++ {{#if viewingSelf}}+ <li>+ {{#link-to "userPrivateMessages.new" model class="new"}}+ {{newLinkText}}+ {{/link-to}}+ </li>+ <li>+ {{#link-to "userPrivateMessages.unread" model class="unread"}}+ {{unreadLinkText}}+ {{/link-to}}+ </li>+ {{/if}}+<li>{{#link-to "userPrivateMessages.archive" model}}{{i18n "user.messages.archive"}}@@ -54,16 +58,20 @@{{i18n "user.messages.latest"}}{{/link-to}}</li>- <li>- {{#link-to "userPrivateMessages.groupNew" group.name class="new"}}- {{newLinkText}}- {{/link-to}}- </li>- <li>- {{#link-to "userPrivateMessages.groupUnread" group.name class="unread"}}- {{unreadLinkText}}- {{/link-to}}- </li>++ {{#if viewingSelf}}+ <li>+ {{#link-to "userPrivateMessages.groupNew" group.name class="new"}}+ {{newLinkText}}+ {{/link-to}}+ </li>+ <li>+ {{#link-to "userPrivateMessages.groupUnread" group.name class="unread"}}+ {{unreadLinkText}}+ {{/link-to}}+ </li>+ {{/if}}+<li>{{#link-to "userPrivateMessages.groupArchive" group.name}}{{i18n "user.messages.archive"}}@@ -82,16 +90,20 @@{{i18n "user.messages.sent"}}{{/link-to}}</li>- <li>- {{#link-to "userPrivateMessages.personalNew" model class="new"}}- {{newLinkText}}- {{/link-to}}- </li>- <li>- {{#link-to "userPrivateMessages.personalUnread" model class="unread"}}- {{unreadLinkText}}- {{/link-to}}- </li>++ {{#if viewingSelf}}+ <li>+ {{#link-to "userPrivateMessages.personalNew" model class="new"}}+ {{newLinkText}}+ {{/link-to}}+ </li>+ <li>+ {{#link-to "userPrivateMessages.personalUnread" model class="unread"}}+ {{unreadLinkText}}+ {{/link-to}}+ </li>+ {{/if}}+<li>{{#link-to "userPrivateMessages.personalArchive" model}}{{i18n "user.messages.archive"}}diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.jsindex c41e7e4e9ed..b63927f8041 100644--- a/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js@@ -7,6 +7,7 @@ import {exists,publishToMessageBus,query,+ updateCurrentUser,} from "discourse/tests/helpers/qunit-helpers";import selectKit from "discourse/tests/helpers/select-kit-helper";import { PERSONAL_INBOX } from "discourse/controllers/user-private-messages";@@ -38,6 +39,22 @@ acceptance("displays the group notifications button");});++ test("viewing messages of another user", async function (assert) {+ updateCurrentUser({ id: 5, username: "charlie" });++ await visit("/u/eviltrout/messages");++ assert.ok(+ !exists(".messages-nav li a.new"),+ "it does not display new filter"+ );++ assert.ok(+ !exists(".messages-nav li a.unread"),+ "it does not display unread filter"+ );+ });});diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rbindex 34c505bb194..7c7e3d24926 100644--- a/app/controllers/list_controller.rb+++ b/app/controllers/list_controller.rb@@ -155,6 +155,14 @@ class ListController < ApplicationControllertarget_user = fetch_user_from_params({ include_inactive: current_user.try(:staff?) }, [:user_stat, :user_option])case action+ when :private_messages_unread,+ :private_messages_new,+ :private_messages_group_new,+ :private_messages_group_unread,+ :private_messages_all_new,+ :private_messages_all_unread++ raise Discourse::NotFound if target_user.id != current_user.idwhen :private_messages_tagraise Discourse::NotFound if !guardian.can_tag_pms?when :private_messages_warningsdiff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rbindex 9bd7c6f8596..c00c7c96097 100644--- a/spec/requests/list_controller_spec.rb+++ b/spec/requests/list_controller_spec.rb@@ -703,10 +703,10 @@ RSpec.describe ListController doendend- it "returns 403 error when the user can't see private message" do+ it "returns 404 when the user can't see private message" dosign_in(Fabricate(:user))get "/topics/private-messages-unread/#{pm_user.username}.json"- expect(response.status).to eq(403)+ expect(response.status).to eq(404)endit "succeeds when the user can see private messages" do