From: Tom Hughes Date: Wed, 3 Oct 2018 17:59:33 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/pull/2014' X-Git-Tag: live~3419 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/b8a8a88004d25837a10436fdc13128146b32c32b?hp=3ec67ea2d395f9ae78f806f8e583e10d691861de Merge remote-tracking branch 'upstream/pull/2014' --- diff --git a/.rubocop.yml b/.rubocop.yml index abf25d3cd..b33f9046c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -56,10 +56,6 @@ Style/FormatStringToken: Style/IfInsideElse: Enabled: false -Style/GlobalVars: - Exclude: - - 'lib/quad_tile/extconf.rb' - Style/GuardClause: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 00851ffcc..8fc701cb3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -38,7 +38,7 @@ Metrics/AbcSize: # Configuration parameters: CountComments, ExcludedMethods. # ExcludedMethods: refine Metrics/BlockLength: - Max: 259 + Max: 262 # Offense count: 11 # Configuration parameters: CountBlocks. diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index cebf5d95b..13a395da8 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -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? diff --git a/app/models/notifier.rb b/app/models/notifier.rb index 2ff9c85d7..4b53c66f6 100644 --- a/app/models/notifier.rb +++ b/app/models/notifier.rb @@ -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) diff --git a/app/views/messages/_message_summary.html.erb b/app/views/messages/_message_summary.html.erb index 1e4cd8934..6ed41a0e0 100644 --- a/app/views/messages/_message_summary.html.erb +++ b/app/views/messages/_message_summary.html.erb @@ -2,7 +2,7 @@ <%= link_to h(message_summary.sender.display_name), user_path(message_summary.sender) %> <%= link_to h(message_summary.title), message_path(message_summary) %> <%= l message_summary.sent_on, :format => :friendly %> - <%= button_to t('.unread_button'), mark_message_path(message_summary, :mark => 'unread'), { :remote => true } %> - <%= button_to t('.read_button'), mark_message_path(message_summary, :mark => 'read'), { :remote => true } %> - <%= button_to t('.destroy_button'), destroy_message_path(message_summary, :referer => request.fullpath), { :remote => true } %> + <%= button_to t('.unread_button'), message_mark_path(message_summary, :mark => 'unread'), { :remote => true } %> + <%= button_to t('.read_button'), message_mark_path(message_summary, :mark => 'read'), { :remote => true } %> + <%= button_to t('.destroy_button'), message_path(message_summary, :referer => request.fullpath), { :method => :delete, :remote => true } %> diff --git a/app/views/messages/_sent_message_summary.html.erb b/app/views/messages/_sent_message_summary.html.erb index a9346fb5e..028ab135b 100644 --- a/app/views/messages/_sent_message_summary.html.erb +++ b/app/views/messages/_sent_message_summary.html.erb @@ -2,5 +2,5 @@ <%= link_to h(sent_message_summary.recipient.display_name), user_path(sent_message_summary.recipient) %> <%= link_to h(sent_message_summary.title), message_path(sent_message_summary) %> <%= l sent_message_summary.sent_on, :format => :friendly %> - <%= button_to t('.destroy_button'), destroy_message_path(sent_message_summary, :referer => request.fullpath), { :remote => true } %> + <%= button_to t('.destroy_button'), message_path(sent_message_summary, :referer => request.fullpath), { :method => :delete, :remote => true } %> diff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erb index 934cfb99a..e3634e232 100644 --- a/app/views/messages/show.html.erb +++ b/app/views/messages/show.html.erb @@ -14,9 +14,9 @@
<%= @message.body.to_html %>
- <%= 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 %> diff --git a/config/routes.rb b/config/routes.rb index 2750485b9..729e71efa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/test/controllers/messages_controller_test.rb b/test/controllers/messages_controller_test.rb index 8926f7311..0b3a59b39 100644 --- a/test/controllers/messages_controller_test.rb +++ b/test/controllers/messages_controller_test.rb @@ -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