]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/2012'
authorTom Hughes <tom@compton.nu>
Wed, 3 Oct 2018 17:54:19 +0000 (18:54 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 3 Oct 2018 17:54:19 +0000 (18:54 +0100)
.rubocop_todo.yml
app/controllers/messages_controller.rb
app/models/notifier.rb
app/views/messages/_message_summary.html.erb
app/views/messages/_sent_message_summary.html.erb
app/views/messages/show.html.erb
config/routes.rb
test/controllers/messages_controller_test.rb

index 293135907385bc9b3d0890b8be3db2ceac17c430..d3e51600ddd815bab3e57cfd794ac99cf4531f82 100644 (file)
@@ -38,7 +38,7 @@ Metrics/AbcSize:
 # Configuration parameters: CountComments, ExcludedMethods.
 # ExcludedMethods: refine
 Metrics/BlockLength:
-  Max: 259
+  Max: 262
 
 # Offense count: 11
 # Configuration parameters: CountBlocks.
index 54850d403de9feb035ce5b5a91ec5d611c9f0cd8..cf3995b2b9a066b17d1680d32d85cb979c078e61 100644 (file)
@@ -110,7 +110,7 @@ class MessagesController < ApplicationController
 
   # Destroy the message.
   def destroy
-    @message = Message.where("to_user_id = ? OR from_user_id = ?", current_user.id, current_user.id).find(params[:message_id])
+    @message = Message.where("to_user_id = ? OR from_user_id = ?", current_user.id, current_user.id).find(params[:id])
     @message.from_user_visible = false if @message.sender == current_user
     @message.to_user_visible = false if @message.recipient == current_user
     if @message.save && !request.xhr?
index 3cc1be1e66548ef2d98d0695db89ecf163829cc3..01b8076070fe21bbacb3e1bf25eee885f2ad0353 100644 (file)
@@ -70,7 +70,7 @@ class Notifier < ActionMailer::Base
       @text = message.body
       @title = message.title
       @readurl = message_url(message)
-      @replyurl = reply_message_url(message)
+      @replyurl = message_reply_url(message)
       @author = @from_user
 
       attach_user_avatar(message.sender)
index 1e4cd8934532c2f56a8ed28373bef2db39a575fa..6ed41a0e0bf984eb8296dbf575597d92791dad44 100644 (file)
@@ -2,7 +2,7 @@
   <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), 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>
-  <td class="inbox-destroy"><%= button_to t('.destroy_button'), destroy_message_path(message_summary, :referer => request.fullpath), { :remote => true } %></td>
+  <td class="inbox-mark-unread"><%= button_to t('.unread_button'), message_mark_path(message_summary, :mark => 'unread'), { :remote => true } %></td>
+  <td class="inbox-mark-read"><%= button_to t('.read_button'), message_mark_path(message_summary, :mark => 'read'), { :remote => true } %></td>
+  <td class="inbox-destroy"><%= button_to t('.destroy_button'), message_path(message_summary, :referer => request.fullpath), { :method => :delete, :remote => true } %></td>
 </tr>
index a9346fb5ee9343879dbcf51ab641f5dfe0fd39c1..028ab135b9ac79d9b931326404796ebefe7c31f7 100644 (file)
@@ -2,5 +2,5 @@
   <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), 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), { :remote => true } %></td>
+  <td class="inbox-destroy"><%= button_to t('.destroy_button'), message_path(sent_message_summary, :referer => request.fullpath), { :method => :delete, :remote => true } %></td>
 </tr>
index 934cfb99a74499a27fa43372fffea2bc5674613d..e3634e232807a9600e6157d41a017e5ffed93784 100644 (file)
@@ -14,9 +14,9 @@
   <div class="richtext"><%= @message.body.to_html %></div>
 
   <div class='message-buttons buttons'>
-    <%= button_to t('.reply_button'), reply_message_path(@message), :class => 'reply-button' %>
-    <%= button_to t('.unread_button'), mark_message_path(@message, :mark => 'unread'), :class => 'mark-unread-button' %>
-    <%= button_to t('.destroy_button'), destroy_message_path(@message), :class => 'destroy-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('.destroy_button'), message_path(@message), :method => 'delete', :class => 'destroy-button' %>
 
 <% else %>
 
index e609948631818096551bc01cf89579f4d9788e51..b2a0f84c37e83e28fa760b58c7351c1b9ad67c49 100644 (file)
@@ -262,7 +262,9 @@ OpenStreetMap::Application.routes.draw do
   get "/export/embed" => "export#embed"
 
   # messages
-  resources :messages, :only => [:create, :show] do
+  resources :messages, :only => [:create, :show, :destroy] do
+    post :mark
+    match :reply, :via => [:get, :post]
     collection do
       get :inbox
       get :outbox
@@ -272,9 +274,8 @@ OpenStreetMap::Application.routes.draw do
   get "/user/:display_name/outbox", :to => redirect(:path => "/messages/outbox")
   get "/message/new/:display_name" => "messages#new", :as => "new_message"
   get "/message/read/:message_id", :to => redirect(:path => "/messages/%{message_id}")
-  post "/message/mark/:message_id" => "messages#mark", :as => "mark_message"
-  match "/message/reply/:message_id" => "messages#reply", :via => [:get, :post], :as => "reply_message"
-  post "/message/delete/:message_id" => "messages#destroy", :as => "destroy_message"
+  post "/message/mark/:message_id" => "messages#mark" # remove after deployment
+  match "/message/reply/:message_id" => "messages#reply", :via => [:get, :post] # remove after deployment
 
   # oauth admin pages (i.e: for setting up new clients, etc...)
   scope "/user/:display_name" do
index 940144a174807df8b50742d06da09fc1a12ab7b1..8536a1b010dece6dccd52f7e23193fd24fd453ce 100644 (file)
@@ -25,20 +25,20 @@ class MessagesControllerTest < ActionController::TestCase
       { :controller => "messages", :action => "show", :id => "1" }
     )
     assert_routing(
-      { :path => "/message/mark/1", :method => :post },
+      { :path => "/messages/1/mark", :method => :post },
       { :controller => "messages", :action => "mark", :message_id => "1" }
     )
     assert_routing(
-      { :path => "/message/reply/1", :method => :get },
+      { :path => "/messages/1/reply", :method => :get },
       { :controller => "messages", :action => "reply", :message_id => "1" }
     )
     assert_routing(
-      { :path => "/message/reply/1", :method => :post },
+      { :path => "/messages/1/reply", :method => :post },
       { :controller => "messages", :action => "reply", :message_id => "1" }
     )
     assert_routing(
-      { :path => "/message/delete/1", :method => :post },
-      { :controller => "messages", :action => "destroy", :message_id => "1" }
+      { :path => "/messages/1", :method => :delete },
+      { :controller => "messages", :action => "destroy", :id => "1" }
     )
   end
 
@@ -232,14 +232,14 @@ class MessagesControllerTest < ActionController::TestCase
 
     # Check that the message reply page requires us to login
     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
     session[:user] = other_user.id
 
     # Check that we can't reply to somebody else's message
     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]
 
     # Login as the right user
@@ -429,14 +429,14 @@ class MessagesControllerTest < ActionController::TestCase
     sent_message = create(:message, :unread, :recipient => second_user, :sender => user)
 
     # Check that destroying a message requires us to login
-    post :destroy, :params => { :message_id => read_message.id }
+    delete :destroy, :params => { :id => read_message.id }
     assert_response :forbidden
 
     # Login as a user with no messages
     session[:user] = other_user.id
 
     # Check that destroying a message we didn't send or receive fails
-    post :destroy, :params => { :message_id => read_message.id }
+    delete :destroy, :params => { :id => read_message.id }
     assert_response :not_found
     assert_template "no_such_message"
 
@@ -444,7 +444,7 @@ class MessagesControllerTest < ActionController::TestCase
     session[:user] = user.id
 
     # Check that the destroy a received message works
-    post :destroy, :params => { :message_id => read_message.id }
+    delete :destroy, :params => { :id => read_message.id }
     assert_redirected_to inbox_messages_path
     assert_equal "Message deleted", flash[:notice]
     m = Message.find(read_message.id)
@@ -452,7 +452,7 @@ class MessagesControllerTest < ActionController::TestCase
     assert_equal false, m.to_user_visible
 
     # Check that the destroying a sent message works
-    post :destroy, :params => { :message_id => sent_message.id, :referer => outbox_messages_path }
+    delete :destroy, :params => { :id => sent_message.id, :referer => outbox_messages_path }
     assert_redirected_to outbox_messages_path
     assert_equal "Message deleted", flash[:notice]
     m = Message.find(sent_message.id)
@@ -465,7 +465,7 @@ class MessagesControllerTest < ActionController::TestCase
     end
 
     # Asking to destroy a message with a bogus ID should fail
-    post :destroy, :params => { :message_id => 99999 }
+    delete :destroy, :params => { :id => 99999 }
     assert_response :not_found
     assert_template "no_such_message"
   end