Page MenuHomeSoftware Heritage

D6640.diff
No OneTemporary

D6640.diff

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 `<button class="btn btn-default metadata">metadata</button>`;
+ }
+ }
+ return data;
+ }
+ },
{
data: 'status_detail',
name: 'status_detail',
@@ -137,10 +149,23 @@
</div>
</div>
`);
+
+ // 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 = $('<div/>').text(metadata).html();
+ swh.webapp.showModalHtml(`Metadata of deposit ${row.id}`,
+ `<pre style="max-height: 75vh;"><code class="xml">${escapedMetadata}</code></pre>`,
+ '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': '<foo>bar</foo>',
'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,21 @@
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})
+ .should('exist')
+ .click({force: true});
+ cy.get('#swh-web-modal-html code.xml').should('be.visible');
+
+ // Dismiss the modal
+ cy.get('body').wait(500).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
@@ -175,7 +193,7 @@
const expectedOrigin = expectedOrigins[deposit.id];
// ensure it's in the dom
- cy.contains(deposit.id).should('not.exist');
+ expect(row).to.not.contain(deposit.id);
if (deposit.status !== 'rejected') {
expect(row).to.not.contain(deposit.external_id);
expect(row).to.contain(expectedOrigin);
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,
@@ -120,10 +121,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 @@
<a class="toggle-col" href="#" data-column="2">uri</a> -
<a class="toggle-col" href="#" data-column="3">reception date</a> -
<a class="toggle-col" href="#" data-column="4">status</a> -
- <a class="toggle-col col-hidden" href="#" data-column="5">status detail</a> -
- <a class="toggle-col col-hidden" href="#" data-column="6">directory</a> -
- <a class="toggle-col col-hidden" href="#" data-column="7">directory with context</a>
+ <a class="toggle-col" href="#" data-column="5">metadata</a> -
+ <a class="toggle-col col-hidden" href="#" data-column="6">status detail</a> -
+ <a class="toggle-col col-hidden" href="#" data-column="7">directory</a> -
+ <a class="toggle-col col-hidden" href="#" data-column="8">directory with context</a>
</div>
<br/>
<table id="swh-admin-deposit-list" class="table swh-table swh-table-striped" width="100%">
@@ -47,6 +48,7 @@
<th>uri</th>
<th>reception date</th>
<th>status</th>
+ <th>metadata</th>
<th>status detail</th>
<th>directory</th>
<th>directory with context</th>

File Metadata

Mime Type
text/plain
Expires
Wed, Dec 18, 3:55 AM (23 h, 17 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3219182

Event Timeline