]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/1863'
authorTom Hughes <tom@compton.nu>
Tue, 15 May 2018 17:36:55 +0000 (18:36 +0100)
committerTom Hughes <tom@compton.nu>
Tue, 15 May 2018 17:36:55 +0000 (18:36 +0100)
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/destroy.js.erb [moved from app/views/messages/delete.js.erb with 100% similarity]
app/views/messages/show.html.erb [moved from app/views/messages/read.html.erb with 92% similarity]
config/locales/en.yml
config/routes.rb
test/controllers/messages_controller_test.rb

index 11a71c3ee612d40c4b6396093ec436db4179ad2c..99884295bb30577ba08cfcaa0e3d1bad3a05d0b3 100644 (file)
@@ -6,8 +6,8 @@ class MessagesController < ApplicationController
   before_action :require_user
   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 :check_database_writable, :only => [:new, :reply, :mark, :destroy]
+  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])
 
@@ -115,13 +115,13 @@ class MessagesController < ApplicationController
     render :action => "no_such_message", :status => :not_found
   end
 
-  # Delete the message.
-  def delete
+  # 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.from_user_visible = false if @message.sender == current_user
     @message.to_user_visible = false if @message.recipient == current_user
     if @message.save && !request.xhr?
-      flash[:notice] = t ".deleted"
+      flash[:notice] = t ".destroyed"
 
       if params[:referer]
         redirect_to params[:referer]
index 0944c3e1d27a273de56eebb3cc2c4fad8e840e6b..d08bedd8ca05a5c9f9d162a942248499a1b711bf 100644 (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
 
index e9d8311fcb23f0dd5a9b5e1392306b8ddd12b768..1e4cd8934532c2f56a8ed28373bef2db39a575fa 100644 (file)
@@ -1,8 +1,8 @@
 <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>
-  <td class="inbox-delete"><%= button_to t('.delete_button'), delete_message_path(message_summary, :referer => request.fullpath), { :remote => true } %></td>
+  <td class="inbox-destroy"><%= button_to t('.destroy_button'), destroy_message_path(message_summary, :referer => request.fullpath), { :remote => true } %></td>
 </tr>
index 44eaa0bce0879a7ad499fb7111d57b55a4ee4e00..5a64ea8db8e1c8e72e9525eacd9814710f7b1099 100644 (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-delete"><%= button_to t('.delete_button'), delete_message_path(sent_message_summary, :referer => request.fullpath) %></td>
+  <td class="inbox-destroy"><%= button_to t('.destroy_button'), destroy_message_path(sent_message_summary, :referer => request.fullpath) %></td>
 </tr>
similarity index 92%
rename from app/views/messages/read.html.erb
rename to app/views/messages/show.html.erb
index c18b586a44b12c080bc0c107054e680dea6e2a54..4d2f6f6ce9b7124df088f54143618fb469cafc1a 100644 (file)
@@ -16,7 +16,7 @@
   <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('.delete_button'), delete_message_path(@message), :class => 'delete-button' %>
+    <%= button_to t('.destroy_button'), destroy_message_path(@message), :class => 'destroy-button' %>
 
 <% else %>
 
index 51f8dbecd04ba2b7b0e69be7e1eba25fffb1ee8c..e948ca37eb111c9327447fed91ae8533e7a28830 100644 (file)
@@ -1078,7 +1078,7 @@ en:
       unread_button: "Mark as unread"
       read_button: "Mark as read"
       reply_button: "Reply"
-      delete_button: "Delete"
+      destroy_button: "Delete"
     new:
       title: "Send message"
       send_message_to: "Send a new message to %{name}"
@@ -1107,24 +1107,24 @@ 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"
       date: "Date"
       reply_button: "Reply"
       unread_button: "Mark as unread"
-      delete_button: "Delete"
+      destroy_button: "Delete"
       back: "Back"
       to: "To"
       wrong_user: "You are logged in as `%{user}' 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."
     sent_message_summary:
-      delete_button: "Delete"
+      destroy_button: "Delete"
     mark:
       as_read: "Message marked as read"
       as_unread: "Message marked as unread"
-    delete:
-      deleted: "Message deleted"
+    destroy:
+      destroyed: "Message deleted"
   site:
     about:
       next: Next
index ed5e6876be3138b45c74b8640e9f6f05ed9befb5..d750d5035bb6e90d88cca7a9bc7fd8e811a87d07 100644 (file)
@@ -264,10 +264,10 @@ 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"
-  match "/message/reply/:message_id" => "messages#reply", :via => [:get, :post], :as => "reply_message"
-  post "/message/delete/:message_id" => "messages#delete", :as => "delete_message"
+  get "/message/reply/:message_id" => "messages#reply", :as => "reply_message"
+  post "/message/delete/:message_id" => "messages#destroy", :as => "destroy_message"
 
   # oauth admin pages (i.e: for setting up new clients, etc...)
   scope "/user/:display_name" do
index dd9df8f451db8fb3c666f845b64f34e3ca615398..b7bc3bad0cd8eb47bd131df8f76033a493d7980d 100644 (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 },
@@ -32,13 +32,9 @@ class MessagesControllerTest < ActionController::TestCase
       { :path => "/message/reply/1", :method => :get },
       { :controller => "messages", :action => "reply", :message_id => "1" }
     )
-    assert_routing(
-      { :path => "/message/reply/1", :method => :post },
-      { :controller => "messages", :action => "reply", :message_id => "1" }
-    )
     assert_routing(
       { :path => "/message/delete/1", :method => :post },
-      { :controller => "messages", :action => "delete", :message_id => "1" }
+      { :controller => "messages", :action => "destroy", :message_id => "1" }
     )
   end
 
@@ -265,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
@@ -425,52 +421,52 @@ class MessagesControllerTest < ActionController::TestCase
   end
 
   ##
-  # test the delete action
-  def test_delete
+  # test the destroy action
+  def test_destroy
     user = create(:user)
     second_user = create(:user)
     other_user = create(:user)
     read_message = create(:message, :read, :recipient => user, :sender => second_user)
     sent_message = create(:message, :unread, :recipient => second_user, :sender => user)
 
-    # Check that the deleting a message requires us to login
-    post :delete, :params => { :message_id => read_message.id }
+    # Check that destroying a message requires us to login
+    post :destroy, :params => { :message_id => read_message.id }
     assert_response :forbidden
 
     # Login as a user with no messages
     session[:user] = other_user.id
 
-    # Check that deleting a message we didn't send or receive fails
-    post :delete, :params => { :message_id => read_message.id }
+    # Check that destroying a message we didn't send or receive fails
+    post :destroy, :params => { :message_id => read_message.id }
     assert_response :not_found
     assert_template "no_such_message"
 
     # Login as the message recipient_user
     session[:user] = user.id
 
-    # Check that the deleting a received message works
-    post :delete, :params => { :message_id => read_message.id }
+    # Check that the destroy a received message works
+    post :destroy, :params => { :message_id => read_message.id }
     assert_redirected_to inbox_path(:display_name => user.display_name)
     assert_equal "Message deleted", flash[:notice]
     m = Message.find(read_message.id)
     assert_equal true, m.from_user_visible
     assert_equal false, m.to_user_visible
 
-    # Check that the deleting a sent message works
-    post :delete, :params => { :message_id => sent_message.id, :referer => outbox_path(:display_name => user.display_name) }
+    # Check that the destroying a sent message works
+    post :destroy, :params => { :message_id => sent_message.id, :referer => outbox_path(:display_name => user.display_name) }
     assert_redirected_to outbox_path(:display_name => user.display_name)
     assert_equal "Message deleted", flash[:notice]
     m = Message.find(sent_message.id)
     assert_equal false, m.from_user_visible
     assert_equal true, m.to_user_visible
 
-    # Asking to delete a message with no ID should fail
+    # Asking to destroy a message with no ID should fail
     assert_raise ActionController::UrlGenerationError do
-      post :delete
+      post :destroy
     end
 
-    # Asking to delete a message with a bogus ID should fail
-    post :delete, :params => { :message_id => 99999 }
+    # Asking to destroy a message with a bogus ID should fail
+    post :destroy, :params => { :message_id => 99999 }
     assert_response :not_found
     assert_template "no_such_message"
   end