Rename messages#read to #show

Also rename the named path, to align with resourceful routing
This commit is contained in:
Andy Allan 2018-05-15 18:25:54 +08:00
parent 73df8447e3
commit 4ec70f7994
8 changed files with 21 additions and 21 deletions

View file

@ -7,7 +7,7 @@ class MessagesController < ApplicationController
before_action :lookup_user, :only => [:new]
before_action :check_database_readable
before_action :check_database_writable, :only => [:new, :reply, :mark]
before_action :allow_thirdparty_images, :only => [:new, :read]
before_action :allow_thirdparty_images, :only => [:new, :show]
# Allow the user to write a new message to another user. This action also
# deals with the sending of that message to the other user when the user
@ -61,7 +61,7 @@ class MessagesController < ApplicationController
end
# Show a message
def read
def show
@title = t ".title"
@message = Message.find(params[:message_id])

View file

@ -69,7 +69,7 @@ class Notifier < ActionMailer::Base
@from_user = message.sender.display_name
@text = message.body
@title = message.title
@readurl = read_message_url(message)
@readurl = message_url(message)
@replyurl = reply_message_url(message)
@author = @from_user

View file

@ -1,6 +1,6 @@
<tr id="inbox-<%= message_summary.id %>" class="inbox-row<%= "-unread" if not message_summary.message_read? %>">
<td class="inbox-sender"><%= link_to h(message_summary.sender.display_name), user_path(message_summary.sender) %></td>
<td class="inbox-subject"><%= link_to h(message_summary.title), read_message_path(message_summary) %></td>
<td class="inbox-subject"><%= link_to h(message_summary.title), message_path(message_summary) %></td>
<td class="inbox-sent"><%= l message_summary.sent_on, :format => :friendly %></td>
<td class="inbox-mark-unread"><%= button_to t('.unread_button'), mark_message_path(message_summary, :mark => 'unread'), { :remote => true } %></td>
<td class="inbox-mark-read"><%= button_to t('.read_button'), mark_message_path(message_summary, :mark => 'read'), { :remote => true } %></td>

View file

@ -1,6 +1,6 @@
<tr class="inbox-row">
<td class="inbox-sender"><%= link_to h(sent_message_summary.recipient.display_name), user_path(sent_message_summary.recipient) %></td>
<td class="inbox-subject"><%= link_to h(sent_message_summary.title), read_message_path(sent_message_summary) %></td>
<td class="inbox-subject"><%= link_to h(sent_message_summary.title), message_path(sent_message_summary) %></td>
<td class="inbox-sent"><%= l sent_message_summary.sent_on, :format => :friendly %></td>
<td class="inbox-destroy"><%= button_to t('.destroy_button'), destroy_message_path(sent_message_summary, :referer => request.fullpath) %></td>
</tr>

View file

@ -1107,7 +1107,7 @@ en:
people_mapping_nearby: "people mapping nearby"
reply:
wrong_user: "You are logged in as `%{user}' but the message you have asked to reply to was not sent to that user. Please login as the correct user in order to reply."
read:
show:
title: "Read message"
from: "From"
subject: "Subject"

View file

@ -264,7 +264,7 @@ OpenStreetMap::Application.routes.draw do
get "/user/:display_name/inbox" => "messages#inbox", :as => "inbox"
get "/user/:display_name/outbox" => "messages#outbox", :as => "outbox"
match "/message/new/:display_name" => "messages#new", :via => [:get, :post], :as => "new_message"
get "/message/read/:message_id" => "messages#read", :as => "read_message"
get "/message/read/:message_id" => "messages#show", :as => "message"
post "/message/mark/:message_id" => "messages#mark", :as => "mark_message"
get "/message/reply/:message_id" => "messages#reply", :as => "reply_message"
post "/message/delete/:message_id" => "messages#destroy", :as => "destroy_message"

View file

@ -22,7 +22,7 @@ class MessagesControllerTest < ActionController::TestCase
)
assert_routing(
{ :path => "/message/read/1", :method => :get },
{ :controller => "messages", :action => "read", :message_id => "1" }
{ :controller => "messages", :action => "show", :message_id => "1" }
)
assert_routing(
{ :path => "/message/mark/1", :method => :post },
@ -261,50 +261,50 @@ class MessagesControllerTest < ActionController::TestCase
end
##
# test the read action
def test_read
# test the show action
def test_show
user = create(:user)
recipient_user = create(:user)
other_user = create(:user)
unread_message = create(:message, :unread, :sender => user, :recipient => recipient_user)
# Check that the read message page requires us to login
get :read, :params => { :message_id => unread_message.id }
assert_redirected_to login_path(:referer => read_message_path(:message_id => unread_message.id))
# Check that the show message page requires us to login
get :show, :params => { :message_id => unread_message.id }
assert_redirected_to login_path(:referer => message_path(:message_id => unread_message.id))
# Login as the wrong user
session[:user] = other_user.id
# Check that we can't read the message
get :read, :params => { :message_id => unread_message.id }
assert_redirected_to login_path(:referer => read_message_path(:message_id => unread_message.id))
get :show, :params => { :message_id => unread_message.id }
assert_redirected_to login_path(:referer => message_path(:message_id => unread_message.id))
assert_equal "You are logged in as `#{other_user.display_name}' but the message you have asked to read was not sent by or to that user. Please login as the correct user in order to read it.", flash[:notice]
# Login as the message sender
session[:user] = user.id
# Check that the message sender can read the message
get :read, :params => { :message_id => unread_message.id }
get :show, :params => { :message_id => unread_message.id }
assert_response :success
assert_template "read"
assert_template "show"
assert_equal false, Message.find(unread_message.id).message_read
# Login as the message recipient
session[:user] = recipient_user.id
# Check that the message recipient can read the message
get :read, :params => { :message_id => unread_message.id }
get :show, :params => { :message_id => unread_message.id }
assert_response :success
assert_template "read"
assert_template "show"
assert_equal true, Message.find(unread_message.id).message_read
# Asking to read a message with no ID should fail
assert_raise ActionController::UrlGenerationError do
get :read
get :show
end
# Asking to read a message with a bogus ID should fail
get :read, :params => { :message_id => 99999 }
get :show, :params => { :message_id => 99999 }
assert_response :not_found
assert_template "no_such_message"
end