From c828bfa4a54570da67ae44d05cccce349a20b049 Mon Sep 17 00:00:00 2001 From: Martin Beracochea Date: Wed, 19 Jan 2022 12:00:13 +0000 Subject: [PATCH] Legacy assembly redirection See https://github.com/EBI-Metagenomics/emgapi/pull/236/commits for the explanation --- ci/emg_sql_fixtures/emg_LEGACY_ASSEMBLIES.sql | 1 + cypress/integration/assembly.js | 10 ++++++++++ src/assembly.html | 19 ++++++++++++++++--- src/js/modules/assembly.js | 16 +++++++++++++++- 4 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 ci/emg_sql_fixtures/emg_LEGACY_ASSEMBLIES.sql diff --git a/ci/emg_sql_fixtures/emg_LEGACY_ASSEMBLIES.sql b/ci/emg_sql_fixtures/emg_LEGACY_ASSEMBLIES.sql new file mode 100644 index 00000000..e28de63b --- /dev/null +++ b/ci/emg_sql_fixtures/emg_LEGACY_ASSEMBLIES.sql @@ -0,0 +1 @@ +INSERT INTO `LEGACY_ASSEMBLY` (`id`, `LEGACY_ACCESSION`, `NEW_ACCESSION`) VALUES (1,'ERZ1111','ERZ477708'); diff --git a/cypress/integration/assembly.js b/cypress/integration/assembly.js index fd4a4ba1..7dd5819d 100644 --- a/cypress/integration/assembly.js +++ b/cypress/integration/assembly.js @@ -139,4 +139,14 @@ describe('Assembly page', function() { .should('not.exist'); }); }); + context('Legacy assemblies redirection', function() { + const legacyAccession = 'ERZ1111'; + const redirectUrl = 'assemblies/' + legacyAccession; + + it('Should refresh the url and add a callout', function() { + openPage(redirectUrl); + cy.contains('Assembly ' + accession).should('be.visible'); + cy.get(".callout").contains("The assembly " + legacyAccession + " has been re-assigned the accession " + accession); + }); + }); }); diff --git a/src/assembly.html b/src/assembly.html index 4807ca3b..db0e7176 100644 --- a/src/assembly.html +++ b/src/assembly.html @@ -23,11 +23,15 @@

Assembly <%= assembly_id %>

+ <% if (legacy_redirection) { %> +
+
+

+ The assembly <%= legacy_redirection_accession %> has been re-assigned the accession <%= assembly_id %>. +

+
+
+ <% } %>
diff --git a/src/js/modules/assembly.js b/src/js/modules/assembly.js index 477651cb..2a5726fb 100644 --- a/src/js/modules/assembly.js +++ b/src/js/modules/assembly.js @@ -27,6 +27,20 @@ let AssemblyView = Backbone.View.extend({ data: {}, success(data) { const attr = data.attributes; + /** + * Handle legacy assemblies redirection. + * Legacy assemblies were given new accessions, the api returns a 302 for those. + * This code handles that case, and shows the user a warning message as the url changes. + */ + that.model.set({legacy_redirection: false}); + if (accession !== attr["assembly_id"]) { + that.model.set({ + legacy_redirection: true, + legacy_redirection_accession: accession + }); + accession = attr["assembly_id"]; + window.history.replaceState("", `${objType}: ${accession}`, attr["analysis_url"]); + } that.render(attr).then(() => { deferred.resolve(); }); @@ -141,9 +155,9 @@ let AssemblyAnalysesView = util.GenericTableView.extend({ let assembly = new api.Assembly({id: accession}); let assemblyView = new AssemblyView({model: assembly}); -let assemblyAnalyses = new api.AssemblyAnalyses({id: accession}); assemblyView.init() .then(() => { + let assemblyAnalyses = new api.AssemblyAnalyses({id: accession}); return new AssemblyAnalysesView({collection: assemblyAnalyses}); }).then(() => { util.attachExpandButtonCallback();