Use resourceful routing for message replies

This commit is contained in:
Andy Allan 2018-09-05 11:25:44 +08:00
parent db30ea642e
commit dfe21fec82
4 changed files with 8 additions and 7 deletions

View file

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

View file

@ -14,7 +14,7 @@
<div class="richtext"><%= @message.body.to_html %></div> <div class="richtext"><%= @message.body.to_html %></div>
<div class='message-buttons buttons'> <div class='message-buttons buttons'>
<%= button_to t('.reply_button'), reply_message_path(@message), :class => 'reply-button' %> <%= button_to t('.reply_button'), message_reply_path(@message), :class => 'reply-button' %>
<%= button_to t('.unread_button'), message_mark_path(@message, :mark => 'unread'), :class => 'mark-unread-button' %> <%= button_to t('.unread_button'), message_mark_path(@message, :mark => 'unread'), :class => 'mark-unread-button' %>
<%= button_to t('.destroy_button'), message_path(@message), :method => 'delete', :class => 'destroy-button' %> <%= button_to t('.destroy_button'), message_path(@message), :method => 'delete', :class => 'destroy-button' %>

View file

@ -266,6 +266,7 @@ OpenStreetMap::Application.routes.draw do
# messages # messages
resources :messages, :only => [:create, :show, :destroy] do resources :messages, :only => [:create, :show, :destroy] do
post :mark post :mark
match :reply, :via => [:get, :post]
collection do collection do
get :inbox get :inbox
get :outbox get :outbox
@ -276,7 +277,7 @@ OpenStreetMap::Application.routes.draw do
get "/message/new/:display_name" => "messages#new", :as => "new_message" get "/message/new/:display_name" => "messages#new", :as => "new_message"
get "/message/read/:message_id", :to => redirect(:path => "/messages/%{message_id}") get "/message/read/:message_id", :to => redirect(:path => "/messages/%{message_id}")
post "/message/mark/:message_id" => "messages#mark" # remove after deployment post "/message/mark/:message_id" => "messages#mark" # remove after deployment
match "/message/reply/:message_id" => "messages#reply", :via => [:get, :post], :as => "reply_message" match "/message/reply/:message_id" => "messages#reply", :via => [:get, :post] # remove after deployment
# oauth admin pages (i.e: for setting up new clients, etc...) # oauth admin pages (i.e: for setting up new clients, etc...)
scope "/user/:display_name" do scope "/user/:display_name" do

View file

@ -29,11 +29,11 @@ class MessagesControllerTest < ActionController::TestCase
{ :controller => "messages", :action => "mark", :message_id => "1" } { :controller => "messages", :action => "mark", :message_id => "1" }
) )
assert_routing( assert_routing(
{ :path => "/message/reply/1", :method => :get }, { :path => "/messages/1/reply", :method => :get },
{ :controller => "messages", :action => "reply", :message_id => "1" } { :controller => "messages", :action => "reply", :message_id => "1" }
) )
assert_routing( assert_routing(
{ :path => "/message/reply/1", :method => :post }, { :path => "/messages/1/reply", :method => :post },
{ :controller => "messages", :action => "reply", :message_id => "1" } { :controller => "messages", :action => "reply", :message_id => "1" }
) )
assert_routing( assert_routing(
@ -232,14 +232,14 @@ class MessagesControllerTest < ActionController::TestCase
# Check that the message reply page requires us to login # Check that the message reply page requires us to login
get :reply, :params => { :message_id => unread_message.id } get :reply, :params => { :message_id => unread_message.id }
assert_redirected_to login_path(:referer => reply_message_path(:message_id => unread_message.id)) assert_redirected_to login_path(:referer => message_reply_path(:message_id => unread_message.id))
# Login as the wrong user # Login as the wrong user
session[:user] = other_user.id session[:user] = other_user.id
# Check that we can't reply to somebody else's message # Check that we can't reply to somebody else's message
get :reply, :params => { :message_id => unread_message.id } get :reply, :params => { :message_id => unread_message.id }
assert_redirected_to login_path(:referer => reply_message_path(:message_id => unread_message.id)) assert_redirected_to login_path(:referer => message_reply_path(:message_id => unread_message.id))
assert_equal "You are logged in as `#{other_user.display_name}' 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.", flash[:notice] assert_equal "You are logged in as `#{other_user.display_name}' 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.", flash[:notice]
# Login as the right user # Login as the right user