Merge remote-tracking branch 'upstream/pull/5120'

This commit is contained in:
Tom Hughes 2024-08-28 18:38:34 +01:00
commit 990b41cd4c
3 changed files with 30 additions and 3 deletions

View file

@ -88,6 +88,16 @@ class MessagesController < ApplicationController
@title = @message.title @title = @message.title
render :action => "new"
elsif message.sender == current_user
@message = Message.new(
:recipient => message.recipient,
:title => "Re: #{message.title.sub(/^Re:\s*/, '')}",
:body => "On #{message.sent_on} #{message.sender.display_name} wrote:\n\n#{message.body.gsub(/^/, '> ')}"
)
@title = @message.title
render :action => "new" render :action => "new"
else else
flash[:notice] = t ".wrong_user", :user => current_user.display_name flash[:notice] = t ".wrong_user", :user => current_user.display_name

View file

@ -18,8 +18,8 @@
<div class="richtext text-break"><%= @message.body.to_html %></div> <div class="richtext text-break"><%= @message.body.to_html %></div>
<div> <div>
<%= link_to t(".reply_button"), message_reply_path(@message), :class => "btn btn-primary" %>
<% if current_user == @message.recipient %> <% if current_user == @message.recipient %>
<%= link_to t(".reply_button"), message_reply_path(@message), :class => "btn btn-primary" %>
<%= link_to t(".unread_button"), message_mark_path(@message, :mark => "unread"), :method => "post", :class => "btn btn-primary" %> <%= link_to t(".unread_button"), message_mark_path(@message, :mark => "unread"), :method => "post", :class => "btn btn-primary" %>
<%= link_to t(".destroy_button"), message_path(@message), :method => "delete", :class => "btn btn-danger" %> <%= link_to t(".destroy_button"), message_path(@message), :method => "delete", :class => "btn btn-danger" %>
<% else %> <% else %>

View file

@ -263,6 +263,21 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest
end end
assert Message.find(message.id).message_read assert Message.find(message.id).message_read
# Login as the sending user
session_for(user)
# Check that the message reply page loads
get message_reply_path(message)
assert_response :success
assert_template "new"
assert_select "title", "Re: #{message.title} | OpenStreetMap"
assert_select "form[action='/messages']", :count => 1 do
assert_select "input[type='hidden'][name='display_name'][value='#{recipient_user.display_name}']"
assert_select "input#message_title[value='Re: #{message.title}']", :count => 1
assert_select "textarea#message_body", :count => 1
assert_select "input[type='submit'][value='Send']", :count => 1
end
# Asking to reply to a message with a bogus ID should fail # Asking to reply to a message with a bogus ID should fail
get message_reply_path(99999) get message_reply_path(99999)
assert_response :not_found assert_response :not_found
@ -292,21 +307,23 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest
# Login as the message sender # Login as the message sender
session_for(user) session_for(user)
# Check that the message sender can read the message # Check that the message sender can read the message and that Reply button is available
get message_path(message) get message_path(message)
assert_response :success assert_response :success
assert_template "show" assert_template "show"
assert_select "a[href='#{user_path recipient_user}']", :text => recipient_user.display_name assert_select "a[href='#{user_path recipient_user}']", :text => recipient_user.display_name
assert_select "a.btn.btn-primary", :text => "Reply"
assert_not Message.find(message.id).message_read assert_not Message.find(message.id).message_read
# Login as the message recipient # Login as the message recipient
session_for(recipient_user) session_for(recipient_user)
# Check that the message recipient can read the message # Check that the message recipient can read the message and that Reply button is available
get message_path(message) get message_path(message)
assert_response :success assert_response :success
assert_template "show" assert_template "show"
assert_select "a[href='#{user_path user}']", :text => user.display_name assert_select "a[href='#{user_path user}']", :text => user.display_name
assert_select "a.btn.btn-primary", :text => "Reply"
assert Message.find(message.id).message_read assert Message.find(message.id).message_read
# Asking to read a message with a bogus ID should fail # Asking to read a message with a bogus ID should fail