Redirect to inbox after marking a message as read/unread disregarding referer

Avoids staying on the message page after the "Mark as unread" button is clicked and immediately reading the message again.
This commit is contained in:
Anton Khorev 2024-05-05 15:32:47 +03:00
parent 4c21a09b32
commit 5da2957591
2 changed files with 7 additions and 7 deletions

View file

@ -127,7 +127,7 @@ class MessagesController < ApplicationController
@message.message_read = message_read @message.message_read = message_read
if @message.save if @message.save
flash[:notice] = notice flash[:notice] = notice
redirect_back_or_to inbox_messages_path, :status => :see_other redirect_to inbox_messages_path, :status => :see_other
end end
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
@title = t "messages.no_such_message.title" @title = t "messages.no_such_message.title"

View file

@ -407,14 +407,14 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest
assert_redirected_to inbox_messages_path assert_redirected_to inbox_messages_path
assert_not Message.find(message.id).message_read assert_not Message.find(message.id).message_read
# Check that the marking a message read via XHR works # Check that the marking a message read works and redirects to inbox from the message page
post message_mark_path(:message_id => message, :mark => "read") post message_mark_path(:message_id => message, :mark => "read"), :headers => { :referer => message_path(message) }
assert_response :see_other assert_redirected_to inbox_messages_path
assert Message.find(message.id).message_read assert Message.find(message.id).message_read
# Check that the marking a message unread via XHR works # Check that the marking a message unread works and redirects to inbox from the message page
post message_mark_path(:message_id => message, :mark => "unread") post message_mark_path(:message_id => message, :mark => "unread"), :headers => { :referer => message_path(message) }
assert_response :see_other assert_redirected_to inbox_messages_path
assert_not Message.find(message.id).message_read assert_not Message.find(message.id).message_read
# Asking to mark a message with no ID should fail # Asking to mark a message with no ID should fail