Skip to content

Commit c1988ee

Browse files
committed
Merge branch 'hotfix/0.106.17'
2 parents 959ba0c + b3f8755 commit c1988ee

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

osf_tests/test_guid.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import urllib
44
from django.core.exceptions import MultipleObjectsReturned
55

6-
from framework.auth import Auth
76
from osf.models import Guid, NodeLicenseRecord, OSFUser
87
from osf.modm_compat import Q
9-
from osf_tests.factories import AuthUserFactory, UserFactory, NodeFactory, NodeLicenseRecordFactory, RegistrationFactory, PreprintFactory
8+
from osf_tests.factories import AuthUserFactory, UserFactory, NodeFactory, NodeLicenseRecordFactory, \
9+
RegistrationFactory, PreprintFactory, PreprintProviderFactory
1010
from tests.base import OsfTestCase
1111
from tests.test_websitefiles import TestFile
1212
from website.settings import MFR_SERVER_URL, WATERBUTLER_URL
@@ -170,7 +170,7 @@ def test_resolve_guid_download_file(self):
170170

171171
res = self.app.get(pp.url + 'download')
172172
assert res.status_code == 302
173-
assert '/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(pp.node._id, pp.primary_file.provider, pp.primary_file.path) in res.location
173+
assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp.node._id, pp.primary_file.provider, pp.primary_file.path) in res.location
174174

175175
res = self.app.get(pp.url + 'download/')
176176
assert res.status_code == 302
@@ -200,6 +200,26 @@ def test_resolve_guid_download_file(self):
200200
assert res.status_code == 302
201201
assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, unpub_pp.node._id, unpub_pp.primary_file.provider, unpub_pp.primary_file.path) in res.location
202202

203+
@mock.patch('website.settings.USE_EXTERNAL_EMBER', True)
204+
@mock.patch('website.settings.EXTERNAL_EMBER_APPS', {
205+
'preprints': {
206+
'url': '/preprints/',
207+
'server': 'http://localhost:4200',
208+
'path': '/preprints/'
209+
},
210+
})
211+
def test_resolve_guid_download_file_from_emberapp_preprints(self):
212+
provider = PreprintProviderFactory(name='Sockarxiv')
213+
pp = PreprintFactory(finish=True, provider=provider)
214+
215+
res = self.app.get('/preprints/sockarxiv' + pp.url + 'download')
216+
assert res.status_code == 302
217+
assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp.node._id, pp.primary_file.provider, pp.primary_file.path) in res.location
218+
219+
res = self.app.get('/preprints/sockarxiv' + pp.url + 'download/')
220+
assert res.status_code == 302
221+
assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp.node._id, pp.primary_file.provider, pp.primary_file.path) in res.location
222+
203223
def test_resolve_guid_download_file_export(self):
204224
pp = PreprintFactory(finish=True)
205225

website/routes.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,17 +269,35 @@ def make_url_map(app):
269269
Rule('/sitemaps/<path>', 'get', sitemap_file, json_renderer),
270270
])
271271

272+
# Ember Applications
272273
if settings.USE_EXTERNAL_EMBER:
273274
# Routes that serve up the Ember application. Hide behind feature flag.
274-
rules = []
275275
for prefix in settings.EXTERNAL_EMBER_APPS.keys():
276-
rules += [
277-
'/{}/'.format(prefix),
278-
'/{}/<path:path>'.format(prefix),
279-
]
280-
process_rules(app, [
281-
Rule(rules, 'get', ember_app, json_renderer),
282-
])
276+
process_rules(app, [
277+
Rule(
278+
[
279+
'/<provider>/<guid>/download',
280+
'/<provider>/<guid>/download/',
281+
],
282+
['get', 'post', 'put', 'patch', 'delete'],
283+
website_views.resolve_guid_download,
284+
notemplate,
285+
endpoint_suffix='__' + prefix
286+
),
287+
], prefix='/' + prefix)
288+
289+
process_rules(app, [
290+
Rule(
291+
[
292+
'/',
293+
'/<path:path>',
294+
],
295+
'get',
296+
ember_app,
297+
json_renderer,
298+
endpoint_suffix='__' + prefix
299+
),
300+
], prefix='/' + prefix)
283301

284302
### Base ###
285303

website/views.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ def _build_guid_url(base, suffix=None):
208208
return u'/{0}/'.format(url)
209209

210210

211+
def resolve_guid_download(guid, suffix=None, provider=None):
212+
return resolve_guid(guid, suffix='download')
213+
214+
211215
def resolve_guid(guid, suffix=None):
212216
"""Load GUID by primary key, look up the corresponding view function in the
213217
routing table, and return the return value of the view function without

0 commit comments

Comments
 (0)