Skip to content

Commit 54a2e46

Browse files
committed
Handle URLs that may already have query params
A few complex lines were moved to their own methods to make reading the method a bit easier
1 parent a11558c commit 54a2e46

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

Diff for: Gemfile.lock

+1
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ GEM
361361

362362
PLATFORMS
363363
arm64-darwin-22
364+
arm64-darwin-23
364365
x86_64-darwin-19
365366
x86_64-darwin-20
366367
x86_64-darwin-21

Diff for: app/helpers/record_helper.rb

+17-3
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,27 @@ def gis_access_link(metadata)
8484
# At this point, we don't show download links for non-MIT records. For MIT records, the download link is stored
8585
# consistently as a download link. We are confirming that the link text is 'Data' for added confirmation.
8686
if access_type(metadata) == 'unknown: check with owning institution'
87-
links.select { |link| link['kind'] == 'Website' }.first['url']
87+
website_url(links)
8888
else
89-
url = links.select { |link| link['kind'] == 'Download' && link['text'] == 'Data' }.first['url']
90-
"#{url}?timdexui=true"
89+
url = download_url(links)
90+
append_timdexui(url)
9191
end
9292
end
9393

94+
def website_url(links)
95+
links.select { |link| link['kind'] == 'Website' }.first['url']
96+
end
97+
98+
def download_url(links)
99+
links.select { |link| link['kind'] == 'Download' && link['text'] == 'Data' }.first['url']
100+
end
101+
102+
def append_timdexui(url)
103+
uri = Addressable::URI.parse(url)
104+
uri.query_values = (uri.query_values || {}).merge(timdexui: true)
105+
uri.to_s
106+
end
107+
94108
def access_type(metadata)
95109
access_right = metadata['rights']&.select { |right| right['kind'] == 'Access to files' }
96110
return if access_right.blank?

Diff for: test/helpers/record_helper_test.rb

+12
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,18 @@ class RecordHelperTest < ActionView::TestCase
247247
assert_equal 'https://example.org/dz_f7regions_2016.zip?timdexui=true', gis_access_link(access_auth)
248248
end
249249

250+
test 'append_timdexui_with_no_existing_query_values' do
251+
url = 'https://example.org/dz_f7regions_2016.zip'
252+
assert_equal('https://example.org/dz_f7regions_2016.zip?timdexui=true',
253+
append_timdexui(url))
254+
end
255+
256+
test 'append_timdexui_with_existing_query_values' do
257+
url = 'https://example.org/dz_f7regions_2016.zip?hallo=goodbye'
258+
assert_equal('https://example.org/dz_f7regions_2016.zip?hallo=goodbye&timdexui=true',
259+
append_timdexui(url))
260+
end
261+
250262
test 'source_metadata_available? returns true if source metadata link exists' do
251263
links = [{ 'kind' => 'Download', 'text' => 'Source Metadata', 'url' => 'https://example.org/metadata.zip' }]
252264
assert source_metadata_available?(links)

0 commit comments

Comments
 (0)