Style/IfInsideElse:
Enabled: false
-Style/GlobalVars:
- Exclude:
- - 'lib/quad_tile/extconf.rb'
-
Style/GuardClause:
Enabled: false
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
- Max: 259
+ Max: 262
# Offense count: 11
# Configuration parameters: CountBlocks.
# 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?
@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)
<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>
<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>
<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 %>
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
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
{ :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
# 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
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"
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)
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)
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