From 207de84f9b8a3361f62f2662ac7f5755f732793a Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Wed, 1 Nov 2023 10:46:01 -0400 Subject: [PATCH 1/2] Routing changes for Preprints Modernization - Phase 1 --- api/base/serializers.py | 3 +++ website/routes.py | 13 ++++++++++--- website/views.py | 4 +++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/api/base/serializers.py b/api/base/serializers.py index c21c76dc394..c8cdff04c7e 100644 --- a/api/base/serializers.py +++ b/api/base/serializers.py @@ -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'): diff --git a/website/routes.py b/website/routes.py index 6634c6a97f5..787fe2e367b 100644 --- a/website/routes.py +++ b/website/routes.py @@ -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: diff --git a/website/views.py b/website/views.py index c3051861791..a8f70421069 100644 --- a/website/views.py +++ b/website/views.py @@ -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() From b69ab6528810de5afe47aebafd53aed7a941b4f5 Mon Sep 17 00:00:00 2001 From: Matt Frazier Date: Thu, 30 Nov 2023 13:03:17 -0500 Subject: [PATCH 2/2] Fix ResolveGuid tests --- tests/test_views.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/tests/test_views.py b/tests/test_views.py index 920d46a0d07..f1a8c1966ce 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -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/' @@ -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):