Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html mails show a link to an updated attachment instead of just the name #107

Merged
merged 3 commits into from
May 6, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,16 @@ def link_to_issue(issue, options={})
def link_to_attachment(attachment, options={})
text = options.delete(:text) || attachment.filename
action = options.delete(:download) ? 'download' : 'show'
only_path = options.delete(:only_path) { true }

link_to h(text),
{:controller => '/attachments',
:action => action,
:id => attachment,
:filename => attachment.filename },
:filename => attachment.filename,
:host => Setting.host_name,
:protocol => Setting.protocol,
:only_path => only_path },
options
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/user_mailer/issue_updated.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<ul>
<% @journal.details.each do |detail| %>
<li><%= @journal.render_detail(detail, :no_html => true) %></li>
<li><%= @journal.render_detail(detail) %></li>
<% end %>
</ul>

Expand Down
2 changes: 1 addition & 1 deletion lib/open_project/journal_formatter/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def controller

def format_html_attachment_detail(key, value)
if !value.blank? && a = Attachment.find_by_id(key.to_i)
link_to_attachment(a)
link_to_attachment(a, :only_path => false )
else
value if value.present?
end
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/acts_as_journalized/lib/journal_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def render_detail(detail, options = { :no_html => false })

return nil if formatter.nil?

formatter.render(key, values, options)
formatter.render(key, values, options).html_safe
end

def formatter_instance(formatter_key)
Expand Down
6 changes: 5 additions & 1 deletion test/functional/issues_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,9 @@ def test_put_update_with_note_and_spent_time
end

def test_put_update_with_attachment_only
Setting.host_name = 'mydomain.foo'
Setting.protocol = 'https'

set_tmp_attachments_directory

# anonymous user
Expand All @@ -928,7 +931,8 @@ def test_put_update_with_attachment_only
assert_equal User.anonymous, j.user

mail = ActionMailer::Base.deliveries.last
assert mail.body.encoded.include?('testfile.txt')
assert mail.text_part.body.encoded.include?('testfile.txt')
assert mail.html_part.body.encoded =~ /<a href="https:\/\/mydomain.foo\/attachments\/\d+\/testfile.txt">testfile.txt<\/a>/
end

def test_put_update_with_attachment_that_fails_to_save
Expand Down
18 changes: 12 additions & 6 deletions test/functional/user_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ def test_generated_links_in_emails
"https://mydomain.foo/issues/#{issue.id}",
:text => "My Tracker ##{issue.id}: My awesome Ticket"
# link to a description diff
assert_select 'li',
:text => "Description changed (https://mydomain.foo/journals/#{journal.id}/diff/description)"
assert_select 'li', :text => /Description changed/
assert_select 'li>a[href=?]',
"https://mydomain.foo/journals/#{journal.id}/diff/description",
:text => "Details"
# link to a referenced ticket
assert_select 'a[href=?][title=?]',
"https://mydomain.foo/issues/#{related_issue.id}",
Expand Down Expand Up @@ -103,8 +105,10 @@ def test_generated_links_with_prefix
"http://mydomain.foo/rdm/issues/#{issue.id}",
:text => "My Tracker ##{issue.id}: My awesome Ticket"
# link to a description diff
assert_select 'li',
:text => "Description changed (http://mydomain.foo/rdm/journals/#{journal.id}/diff/description)"
assert_select 'li', :text => /Description changed/
assert_select 'li>a[href=?]',
"http://mydomain.foo/rdm/journals/#{journal.id}/diff/description",
:text => "Details"
# link to a referenced ticket
assert_select 'a[href=?][title=?]',
"http://mydomain.foo/rdm/issues/#{related_issue.id}",
Expand Down Expand Up @@ -142,8 +146,10 @@ def test_generated_links_with_prefix_and_no_relative_url_root
"http://mydomain.foo/rdm/issues/#{issue.id}",
:text => "My Tracker ##{issue.id}: My awesome Ticket"
# link to a description diff
assert_select 'li',
:text => "Description changed (http://mydomain.foo/rdm/journals/#{journal.id}/diff/description)"
assert_select 'li', :text => /Description changed/
assert_select 'li>a[href=?]',
"http://mydomain.foo/rdm/journals/#{journal.id}/diff/description",
:text => "Details"
# link to a referenced ticket
assert_select 'a[href=?][title=?]',
"http://mydomain.foo/rdm/issues/#{related_issue.id}",
Expand Down