Skip to content

Commit

Permalink
Merge branch 'hotfix/23.16.4' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mfraezz committed Nov 30, 2023
2 parents 532da28 + b69ab65 commit 3d3bfdc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
3 changes: 3 additions & 0 deletions api/base/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,9 @@ def to_representation(self, value):
or related_class.view_name == 'registration-citation':
related_id = resolved_url.kwargs['node_id']
related_type = 'citation'
elif related_class.view_name == 'preprint-citation':
related_id = resolved_url.kwargs['preprint_id']
related_type = 'citation'
elif related_type in ('preprint_providers', 'preprint-providers', 'registration-providers'):
related_id = resolved_url.kwargs['provider_id']
elif related_type in ('registrations', 'draft_nodes'):
Expand Down
27 changes: 9 additions & 18 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5018,28 +5018,22 @@ class TestResolveGuid(OsfTestCase):
def setUp(self):
super(TestResolveGuid, self).setUp()

def test_preprint_provider_without_domain(self):
@mock.patch('website.views.use_ember_app')
def test_preprint_provider_without_domain(self, mock_use_ember_app):
provider = PreprintProviderFactory(domain='')
preprint = PreprintFactory(provider=provider)
url = web_url_for('resolve_guid', _guid=True, guid=preprint._id)
res = self.app.get(url)
assert_equal(res.status_code, 200)
assert_equal(
res.request.path,
'/{}/'.format(preprint._id)
)
mock_use_ember_app.assert_called_with()

def test_preprint_provider_with_domain_without_redirect(self):
@mock.patch('website.views.use_ember_app')
def test_preprint_provider_with_domain_without_redirect(self, mock_use_ember_app):
domain = 'https://test.com/'
provider = PreprintProviderFactory(_id='test', domain=domain, domain_redirect_enabled=False)
preprint = PreprintFactory(provider=provider)
url = web_url_for('resolve_guid', _guid=True, guid=preprint._id)
res = self.app.get(url)
assert_equal(res.status_code, 200)
assert_equal(
res.request.path,
'/{}/'.format(preprint._id)
)
mock_use_ember_app.assert_called_with()

def test_preprint_provider_with_domain_with_redirect(self):
domain = 'https://test.com/'
Expand All @@ -5062,16 +5056,13 @@ def test_preprint_provider_with_domain_with_redirect(self):



def test_preprint_provider_with_osf_domain(self):
@mock.patch('website.views.use_ember_app')
def test_preprint_provider_with_osf_domain(self, mock_use_ember_app):
provider = PreprintProviderFactory(_id='osf', domain='https://osf.io/')
preprint = PreprintFactory(provider=provider)
url = web_url_for('resolve_guid', _guid=True, guid=preprint._id)
res = self.app.get(url)
assert_equal(res.status_code, 200)
assert_equal(
res.request.path,
'/{}/'.format(preprint._id)
)
mock_use_ember_app.assert_called_with()


class TestConfirmationViewBlockBingPreview(OsfTestCase):
Expand Down
13 changes: 10 additions & 3 deletions website/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,16 @@ def ember_app(path=None):
for k in EXTERNAL_EMBER_APPS.keys():
if request.path.strip('/').startswith(k):
ember_app = EXTERNAL_EMBER_APPS[k]
if k == 'preprints' and request.path.rstrip('/').endswith('discover'):
# Route preprint discover pages to new search page in EOW
ember_app = EXTERNAL_EMBER_APPS.get('ember_osf_web', False) or ember_app
if k == 'preprints':
if request.path.rstrip('/').endswith('edit'):
# Route preprint edit pages to old preprint app
ember_app = EXTERNAL_EMBER_APPS.get('preprints', False) or ember_app
elif request.path.rstrip('/').endswith('submit'):
# Route preprint submit pages to old preprint app
ember_app = EXTERNAL_EMBER_APPS.get('preprints', False) or ember_app
else:
# Route other preprint pages to EOW
ember_app = EXTERNAL_EMBER_APPS.get('ember_osf_web', False) or ember_app
break

if not ember_app:
Expand Down
4 changes: 3 additions & 1 deletion website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,9 @@ def resolve_guid(guid, suffix=None):
if isinstance(resource, Preprint):
if resource.provider.domain_redirect_enabled:
return redirect(resource.absolute_url, http_status.HTTP_301_MOVED_PERMANENTLY)
return stream_emberapp(EXTERNAL_EMBER_APPS['preprints']['server'], preprints_dir)
if clean_suffix.endswith('edit'):
return stream_emberapp(EXTERNAL_EMBER_APPS['preprints']['server'], preprints_dir)
return use_ember_app()

elif isinstance(resource, Registration) and (clean_suffix in ('', 'comments', 'links', 'components', 'resources',)) and waffle.flag_is_active(request, features.EMBER_REGISTRIES_DETAIL_PAGE):
return use_ember_app()
Expand Down

0 comments on commit 3d3bfdc

Please sign in to comment.