Skip to content

Commit e98c8fb

Browse files
committed
image url generation through proper routing helpers
- also includes the API key in the URL
1 parent 7b414bd commit e98c8fb

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/redmine_gtt_print/issue_to_json.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ module RedmineGttPrint
66
# server.
77
#
88
class IssueToJson
9+
include Rails.application.routes.url_helpers
10+
11+
# what works in the mailer is good enough for the image URL generation as
12+
# well
13+
def default_url_options
14+
::Mailer.default_url_options
15+
end
16+
917
def initialize(issue, layout, other_attributes = {})
1018
@issue = issue
1119
@layout = layout
@@ -34,7 +42,7 @@ def call
3442
def image_urls(issue)
3543
issue.attachments.map do |a|
3644
if a.image?
37-
"#{Setting.protocol}://#{Setting.host_name}/attachments/download/#{a.id}/#{a.filename}"
45+
download_named_attachment_url(a, a.filename, key: User.current.api_key)
3846
end
3947
end.compact
4048
end

test/unit/issue_to_json_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class IssueToJsonTest < ActiveSupport::TestCase
4343
assert j = RedmineGttPrint::IssueToJson.(i, 'layout')
4444
assert h = JSON.parse(j)
4545
assert_equal i.subject, h['attributes']['subject']
46+
assert h['attributes']['image_url_1'].present?
4647
assert_nil h['attributes']['map']
4748
end
4849

0 commit comments

Comments
 (0)