Skip to content

Commit a771df4

Browse files
authored
Merge pull request #192 from MITLibraries/gdt-317-return-to-search
Download links target _blank and append UI marker
2 parents e616f95 + 54a2e46 commit a771df4

File tree

4 files changed

+150
-122
lines changed

4 files changed

+150
-122
lines changed

Gemfile.lock

Lines changed: 1 addition & 0 deletions
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

app/helpers/record_helper.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +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-
links.select { |link| link['kind'] == 'Download' && link['text'] == 'Data' }.first['url']
89+
url = download_url(links)
90+
append_timdexui(url)
9091
end
9192
end
9293

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+
93108
def access_type(metadata)
94109
access_right = metadata['rights']&.select { |right| right['kind'] == 'Access to files' }
95110
return if access_right.blank?

app/views/record/_access_buttons.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<% if access_type(@record) == 'no authentication required' %>
55
<a class="btn button-primary access-button" href="<%= gis_access_link(@record) %>">Download geodata files</a>
66
<% elsif access_type(@record) == 'MIT authentication required' %>
7-
<a class="btn button-primary access-button" href="<%= gis_access_link(@record) %>">
7+
<a class="btn button-primary access-button" href="<%= gis_access_link(@record) %>" target="_blank">
88
Download geodata files <span class="auth-notice">MIT authentication</span>
99
</a>
1010
<% else %>

test/helpers/record_helper_test.rb

Lines changed: 131 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -103,148 +103,160 @@ class RecordHelperTest < ActionView::TestCase
103103
end
104104

105105
test 'access_type returns nil if corresponding right is blank' do
106-
rights = {
107-
'rights' => [
108-
{
109-
'description' => 'foo',
110-
'kind' => 'bar'
111-
}
112-
]
113-
}
106+
rights = {
107+
'rights' => [
108+
{
109+
'description' => 'foo',
110+
'kind' => 'bar'
111+
}
112+
]
113+
}
114114
assert_nil access_type(rights)
115115
end
116116

117117
test 'access_type returns the description of the corresponding right' do
118118
rights = {
119-
'rights' => [
120-
{
121-
'description' => 'foo',
122-
'kind' => 'bar'
123-
},
124-
{
125-
'description' => 'no authentication required',
126-
'kind' => 'Access to files'
127-
}
128-
]
129-
}
119+
'rights' => [
120+
{
121+
'description' => 'foo',
122+
'kind' => 'bar'
123+
},
124+
{
125+
'description' => 'no authentication required',
126+
'kind' => 'Access to files'
127+
}
128+
]
129+
}
130130
assert_equal 'no authentication required', access_type(rights)
131131
end
132132

133133
test 'gis_access_link returns nil if access type is blank' do
134134
links_no_rights = {
135-
'links' => [
136-
{
137-
'kind' => 'Download',
138-
'text' => 'Data',
139-
'url' => 'https://example.org/dz_f7regions_2016.zip'
140-
},
141-
{
142-
'kind' => 'Website',
143-
'text' => 'Website',
144-
'url' => 'https://example.org/gismit:dz_f7regions_2016'
145-
}
146-
]
147-
}
135+
'links' => [
136+
{
137+
'kind' => 'Download',
138+
'text' => 'Data',
139+
'url' => 'https://example.org/dz_f7regions_2016.zip'
140+
},
141+
{
142+
'kind' => 'Website',
143+
'text' => 'Website',
144+
'url' => 'https://example.org/gismit:dz_f7regions_2016'
145+
}
146+
]
147+
}
148148
assert_nil access_type(links_no_rights)
149149
assert_nil gis_access_link(links_no_rights)
150150
end
151151

152152
test 'gis_access_link returns nil if links are blank' do
153153
rights_no_links = {
154-
'rights' => [
155-
{
156-
'description' => 'foo',
157-
'kind' => 'bar'
158-
},
159-
{
160-
'description' => 'no authentication required',
161-
'kind' => 'Access to files'
162-
}
163-
]
164-
}
154+
'rights' => [
155+
{
156+
'description' => 'foo',
157+
'kind' => 'bar'
158+
},
159+
{
160+
'description' => 'no authentication required',
161+
'kind' => 'Access to files'
162+
}
163+
]
164+
}
165165
assert_nil gis_access_link(rights_no_links)
166166
end
167167

168168
test 'gis_access_link is website URL for non-MIT records' do
169169
access_elsewhere = {
170-
'rights' => [
171-
{
172-
'description' => 'foo',
173-
'kind' => 'bar'
174-
},
175-
{
176-
'description' => 'unknown: check with owning institution',
177-
'kind' => 'Access to files'
178-
}
179-
],
180-
'links' => [
181-
{
182-
'kind' => 'Download',
183-
'text' => 'Data',
184-
'url' => 'https://example.org/dz_f7regions_2016.zip'
185-
},
186-
{
187-
'kind' => 'Website',
188-
'text' => 'Website',
189-
'url' => 'https://example.org/gismit:dz_f7regions_2016'
190-
}
191-
],
192-
'provider' => 'Spelman'
193-
}
170+
'rights' => [
171+
{
172+
'description' => 'foo',
173+
'kind' => 'bar'
174+
},
175+
{
176+
'description' => 'unknown: check with owning institution',
177+
'kind' => 'Access to files'
178+
}
179+
],
180+
'links' => [
181+
{
182+
'kind' => 'Download',
183+
'text' => 'Data',
184+
'url' => 'https://example.org/dz_f7regions_2016.zip'
185+
},
186+
{
187+
'kind' => 'Website',
188+
'text' => 'Website',
189+
'url' => 'https://example.org/gismit:dz_f7regions_2016'
190+
}
191+
],
192+
'provider' => 'Spelman'
193+
}
194194
assert_equal 'https://example.org/gismit:dz_f7regions_2016', gis_access_link(access_elsewhere)
195195
end
196196

197197
test 'gis_access_link is data download URL for MIT records' do
198198
access_free = {
199-
'rights' => [
200-
{
201-
'description' => 'foo',
202-
'kind' => 'bar'
203-
},
204-
{
205-
'description' => 'no authentication required',
206-
'kind' => 'Access to files'
207-
}
208-
],
209-
'links' => [
210-
{
211-
'kind' => 'Download',
212-
'text' => 'Data',
213-
'url' => 'https://example.org/dz_f7regions_2016.zip'
214-
},
215-
{
216-
'kind' => 'Website',
217-
'text' => 'Website',
218-
'url' => 'https://example.org/gismit:dz_f7regions_2016'
219-
}
220-
]
221-
}
199+
'rights' => [
200+
{
201+
'description' => 'foo',
202+
'kind' => 'bar'
203+
},
204+
{
205+
'description' => 'no authentication required',
206+
'kind' => 'Access to files'
207+
}
208+
],
209+
'links' => [
210+
{
211+
'kind' => 'Download',
212+
'text' => 'Data',
213+
'url' => 'https://example.org/dz_f7regions_2016.zip'
214+
},
215+
{
216+
'kind' => 'Website',
217+
'text' => 'Website',
218+
'url' => 'https://example.org/gismit:dz_f7regions_2016'
219+
}
220+
]
221+
}
222222
access_auth = {
223-
'rights' => [
224-
{
225-
'description' => 'foo',
226-
'kind' => 'bar'
227-
},
228-
{
229-
'description' => 'MIT authentication required',
230-
'kind' => 'Access to files'
231-
}
232-
],
233-
'links' => [
234-
{
235-
'kind' => 'Download',
236-
'text' => 'Data',
237-
'url' => 'https://example.org/dz_f7regions_2016.zip'
238-
},
239-
{
240-
'kind' => 'Website',
241-
'text' => 'Website',
242-
'url' => 'https://example.org/gismit:dz_f7regions_2016'
243-
}
244-
]
245-
}
246-
assert_equal 'https://example.org/dz_f7regions_2016.zip', gis_access_link(access_free)
247-
assert_equal 'https://example.org/dz_f7regions_2016.zip', gis_access_link(access_auth)
223+
'rights' => [
224+
{
225+
'description' => 'foo',
226+
'kind' => 'bar'
227+
},
228+
{
229+
'description' => 'MIT authentication required',
230+
'kind' => 'Access to files'
231+
}
232+
],
233+
'links' => [
234+
{
235+
'kind' => 'Download',
236+
'text' => 'Data',
237+
'url' => 'https://example.org/dz_f7regions_2016.zip'
238+
},
239+
{
240+
'kind' => 'Website',
241+
'text' => 'Website',
242+
'url' => 'https://example.org/gismit:dz_f7regions_2016'
243+
}
244+
]
245+
}
246+
assert_equal 'https://example.org/dz_f7regions_2016.zip?timdexui=true', gis_access_link(access_free)
247+
assert_equal 'https://example.org/dz_f7regions_2016.zip?timdexui=true', gis_access_link(access_auth)
248+
end
249+
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))
248260
end
249261

250262
test 'source_metadata_available? returns true if source metadata link exists' do
@@ -272,7 +284,7 @@ class RecordHelperTest < ActionView::TestCase
272284

273285
test 'parse_nested_field returns nil for fields that are not nested' do
274286
string_field = 'string'
275-
array_of_strings_field = ['string', 'other_string']
287+
array_of_strings_field = %w[string other_string]
276288
assert_nil parse_nested_field(string_field)
277289
assert_nil parse_nested_field(array_of_strings_field)
278290
end
@@ -304,8 +316,8 @@ class RecordHelperTest < ActionView::TestCase
304316

305317
test 'deduplicate_subjects returns only unique subjects' do
306318
# within the same subject
307-
duplicative_subject = [{ 'kind' => 'foo', 'value' => ['bar', 'bar', 'baz']}]
308-
assert_equal [['bar', 'baz']], deduplicate_subjects(duplicative_subject)
319+
duplicative_subject = [{ 'kind' => 'foo', 'value' => %w[bar bar baz] }]
320+
assert_equal [%w[bar baz]], deduplicate_subjects(duplicative_subject)
309321

310322
# across multiple subjects
311323
multiple_duplicative_subjects = [{ 'kind' => 'foo', 'value' => ['bar'] },
@@ -315,7 +327,7 @@ class RecordHelperTest < ActionView::TestCase
315327

316328
test 'deduplicate_subjects ignores case' do
317329
# within the same subject
318-
duplicative_subject = [{ 'kind' => 'foo', 'value' => ['Bar', 'BAR', 'bar']}]
330+
duplicative_subject = [{ 'kind' => 'foo', 'value' => %w[Bar BAR bar] }]
319331
assert_equal [['Bar']], deduplicate_subjects(duplicative_subject)
320332

321333
# across multiple subjects

0 commit comments

Comments
 (0)