diff --git a/assets/src/bundles/admin/deposit.js b/assets/src/bundles/admin/deposit.js --- a/assets/src/bundles/admin/deposit.js +++ b/assets/src/bundles/admin/deposit.js @@ -82,6 +82,18 @@ data: 'status', name: 'status' }, + { + data: 'raw_metadata', + name: 'raw_metadata', + render: (data, type, row) => { + if (type === 'display') { + if (row.raw_metadata) { + return ``; + } + } + return data; + } + }, { data: 'status_detail', name: 'status_detail', @@ -137,10 +149,23 @@ `); + + // Show a modal when the "metadata" button is clicked + $('#swh-admin-deposit-list tbody').on('click', 'tr button.metadata', function() { + var row = depositsTable.row(this.parentNode.parentNode).data(); + var metadata = row.raw_metadata; + var escapedMetadata = $('
').text(metadata).html(); + swh.webapp.showModalHtml(`Metadata of deposit ${row.id}`, + `
${escapedMetadata}
`, + '90%'); + swh.webapp.highlightCode(); + }); + // Adding exclusion pattern update behavior, when typing, update search $('#swh-admin-deposit-list-exclude-filter').keyup(function() { depositsTable.draw(); }); + // at last draw the table depositsTable.draw(); }); diff --git a/cypress/integration/deposit-admin.spec.js b/cypress/integration/deposit-admin.spec.js --- a/cypress/integration/deposit-admin.spec.js +++ b/cypress/integration/deposit-admin.spec.js @@ -66,6 +66,7 @@ 'status_detail': null, 'swhid': 'swh:1:dir:ef04a768', 'swhid_context': 'swh:1:dir:ef04a768;origin=https://w.s.o/c-d-1;visit=swh:1:snp:b234be1e;anchor=swh:1:rev:d24a75c9;path=/', + 'raw_metadata': 'bar', 'uri': 'https://w.s.o/c-d-1' }, { @@ -77,6 +78,7 @@ 'status_detail': null, 'swhid': 'swh:1:dir:181417fb', 'swhid_context': 'swh:1:dir:181417fb;origin=https://w.s.o/c-d-2;visit=swh:1:snp:8c32a2ef;anchor=swh:1:rev:3d1eba04;path=/', + 'raw_metadata': null, 'uri': 'https://w.s.o/c-d-2' }, { @@ -88,6 +90,7 @@ 'status_detail': 'incomplete deposit!', 'swhid': null, 'swhid_context': null, + 'raw_metadata': null, 'uri': null } ]; @@ -100,7 +103,7 @@ }); - it('Should display properly entries', function() { + it('Should properly display entries', function() { cy.adminLogin(); const testDeposits = responseDeposits; @@ -164,6 +167,19 @@ cy.contains(deposit.swhid).should('not.exist'); cy.contains(deposit.swhid_context).should('not.exist'); } + + if (deposit.raw_metadata !== null) { + cy.get('button.metadata', {withinSubject: row}).click(); + cy.get('#swh-web-modal-html code.xml').should('be.visible'); + + // Dismiss the modal + cy.get('body').type('{esc}'); + cy.get('#swh-web-modal-html code.xml').should('not.be.visible'); + } else { + cy.get('button.metadata', {withinSubject: row}).should('not.exist'); + cy.get('#swh-web-modal-html code.xml').should('not.be.visible'); + } + }); // toggling all links and ensure, the previous checks are inverted diff --git a/swh/web/admin/deposit.py b/swh/web/admin/deposit.py --- a/swh/web/admin/deposit.py +++ b/swh/web/admin/deposit.py @@ -14,6 +14,7 @@ from swh.web.admin.adminurls import admin_route from swh.web.auth.utils import ADMIN_LIST_DEPOSIT_PERMISSION from swh.web.common.utils import ( + get_deposit_raw_metadata, get_deposits_list, parse_swh_deposit_origin, parse_swh_metadata_provenance, @@ -115,10 +116,15 @@ table_data["data"] = data_list + for row in table_data["data"]: + metadata = get_deposit_raw_metadata(row["id"]) + if metadata: + row["raw_metadata"] = metadata[-1] + else: + row["raw_metadata"] = None + except Exception as exc: sentry_sdk.capture_exception(exc) - table_data[ - "error" - ] = "An error occurred while retrieving the list of deposits !" + table_data["error"] = f"Could not retrieve deposits: {exc!r}" return JsonResponse(table_data) diff --git a/swh/web/common/utils.py b/swh/web/common/utils.py --- a/swh/web/common/utils.py +++ b/swh/web/common/utils.py @@ -426,7 +426,8 @@ deposits_list_url, auth=deposits_list_auth, timeout=30 ).json()["count"] - deposits_data = cache.get(f"swh-deposit-list-{username}") + cache_key = f"swh-deposit-list-{username}" + deposits_data = cache.get(cache_key) if not deposits_data or deposits_data["count"] != nb_deposits: deposits_list_url = _deposits_list_url( deposits_list_base_url, page_size=nb_deposits, username=username @@ -434,11 +435,24 @@ deposits_data = requests.get( deposits_list_url, auth=deposits_list_auth, timeout=30, ).json() - cache.set(f"swh-deposit-list-{username}", deposits_data) + cache.set(cache_key, deposits_data) return deposits_data["results"] +def get_deposit_raw_metadata(deposit_id: int) -> Optional[str]: + cache_key = f"swh-deposit-raw-metadata-{deposit_id}" + metadata = cache.get(cache_key) + if metadata is None: + config = get_config()["deposit"] + + url = f"{config['private_api_url']}/{deposit_id}/meta" + metadata = requests.get(url).json()["metadata_raw"] + cache.set(cache_key, metadata) + + return metadata + + def origin_visit_types() -> List[str]: """Return the exhaustive list of visit types for origins ingested into the archive. diff --git a/swh/web/templates/admin/deposit.html b/swh/web/templates/admin/deposit.html --- a/swh/web/templates/admin/deposit.html +++ b/swh/web/templates/admin/deposit.html @@ -34,9 +34,10 @@ uri - reception date - status - - status detail - - directory - - directory with context + metadata - + status detail - + directory - + directory with context

@@ -47,6 +48,7 @@ +
uri reception date statusmetadata status detail directory directory with context