mirror of
https://github.com/discourse/discourse.git
synced 2024-12-14 06:23:44 +08:00
FIX: Avoid marking notifications as seen in readonly mode.
This commit is contained in:
parent
1b17482eab
commit
f10f87cc68
|
@ -25,11 +25,12 @@ class NotificationsController < ApplicationController
|
|||
notifications = Notification.recent_report(current_user, limit)
|
||||
changed = false
|
||||
|
||||
if notifications.present?
|
||||
if notifications.present? && !(params.has_key?(:slient) || @readonly_mode)
|
||||
# ordering can be off due to PMs
|
||||
max_id = notifications.map(&:id).max
|
||||
changed = current_user.saw_notification_id(max_id) unless params.has_key?(:silent)
|
||||
changed = current_user.saw_notification_id(max_id)
|
||||
end
|
||||
|
||||
user.reload
|
||||
user.publish_notifications_state if changed
|
||||
|
||||
|
|
|
@ -33,7 +33,8 @@ end
|
|||
describe NotificationsController do
|
||||
context 'when logged in' do
|
||||
context 'as normal user' do
|
||||
let!(:user) { sign_in(Fabricate(:user)) }
|
||||
fab!(:user) { sign_in(Fabricate(:user)) }
|
||||
fab!(:notification) { Fabricate(:notification, user: user) }
|
||||
|
||||
describe '#index' do
|
||||
it 'should succeed for recent' do
|
||||
|
@ -47,7 +48,6 @@ describe NotificationsController do
|
|||
end
|
||||
|
||||
it 'should mark notifications as viewed' do
|
||||
Fabricate(:notification, user: user)
|
||||
expect(user.reload.unread_notifications).to eq(1)
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
get "/notifications.json", params: { recent: true }
|
||||
|
@ -56,7 +56,6 @@ describe NotificationsController do
|
|||
end
|
||||
|
||||
it 'should not mark notifications as viewed if silent param is present' do
|
||||
Fabricate(:notification, user: user)
|
||||
expect(user.reload.unread_notifications).to eq(1)
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
get "/notifications", params: { recent: true, silent: true }
|
||||
|
@ -64,6 +63,17 @@ describe NotificationsController do
|
|||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
end
|
||||
|
||||
it 'should not mark notifications as viewed in readonly mode' do
|
||||
Discourse.received_redis_readonly!
|
||||
expect(user.reload.unread_notifications).to eq(1)
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
get "/notifications", params: { recent: true, silent: true }
|
||||
expect(user.reload.unread_notifications).to eq(1)
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
ensure
|
||||
Discourse.clear_redis_readonly!
|
||||
end
|
||||
|
||||
context 'when username params is not valid' do
|
||||
it 'should raise the right error' do
|
||||
get "/notifications.json", params: { username: 'somedude' }
|
||||
|
@ -78,7 +88,6 @@ describe NotificationsController do
|
|||
end
|
||||
|
||||
it "can update a single notification" do
|
||||
notification = Fabricate(:notification, user: user)
|
||||
notification2 = Fabricate(:notification, user: user)
|
||||
put "/notifications/mark-read.json", params: { id: notification.id }
|
||||
expect(response.status).to eq(200)
|
||||
|
@ -91,7 +100,6 @@ describe NotificationsController do
|
|||
end
|
||||
|
||||
it "updates the `read` status" do
|
||||
Fabricate(:notification, user: user)
|
||||
expect(user.reload.unread_notifications).to eq(1)
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
put "/notifications/mark-read.json"
|
||||
|
@ -120,7 +128,7 @@ describe NotificationsController do
|
|||
end
|
||||
|
||||
context 'as admin' do
|
||||
let!(:admin) { sign_in(Fabricate(:admin)) }
|
||||
fab!(:admin) { sign_in(Fabricate(:admin)) }
|
||||
|
||||
describe '#create' do
|
||||
it "can create notification" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user