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 @@ -18,8 +18,8 @@ 'reception_date': '2020-05-18T13:48:27Z', 'status': 'done', 'status_detail': null, - 'swh_id': 'swh:1:dir:ef04a768', - 'swh_id_context': 'swh:1:dir:ef04a768;origin=https://w.s.o/c-d-1;visit=swh:1:snp:b234be1e;anchor=swh:1:rev:d24a75c9;path=/' + '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=/' }, { 'id': 613, @@ -27,8 +27,8 @@ 'reception_date': '2020-05-18T11:20:16Z', 'status': 'done', 'status_detail': null, - 'swh_id': 'swh:1:dir:181417fb', - 'swh_id_context': 'swh:1:dir:181417fb;origin=https://w.s.o/c-d-2;visit=swh:1:snp:8c32a2ef;anchor=swh:1:rev:3d1eba04;path=/' + '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=/' }, { 'id': 612, @@ -36,8 +36,8 @@ 'reception_date': '2020-05-18T11:20:16Z', 'status': 'rejected', 'status_detail': 'incomplete deposit!', - 'swh_id': null, - 'swh_id_context': null + 'swhid': null, + 'swhid_context': null } ]; // those are computed from the @@ -93,8 +93,8 @@ expect(deposit.external_id).to.be.equal(responseDeposit['external_id']); expect(deposit.status).to.be.equal(responseDeposit['status']); expect(deposit.status_detail).to.be.equal(responseDeposit['status_detail']); - expect(deposit.swh_id).to.be.equal(responseDeposit['swh_id']); - expect(deposit.swh_id_context).to.be.equal(responseDeposit['swh_id_context']); + expect(deposit.swhid).to.be.equal(responseDeposit['swhid']); + expect(deposit.swhid_context).to.be.equal(responseDeposit['swhid_context']); let expectedOrigin = expectedOrigins[deposit.id]; // ensure it's in the dom @@ -111,9 +111,9 @@ } // those are hidden by default - if (deposit.swh_id !== null) { - cy.contains(deposit.swh_id).should('not.be.visible'); - cy.contains(deposit.swh_id_context).should('not.be.visible'); + if (deposit.swhid !== null) { + cy.contains(deposit.swhid).should('not.be.visible'); + cy.contains(deposit.swhid_context).should('not.be.visible'); } }); @@ -139,9 +139,9 @@ } // those are hidden by default, so now they should be visible - if (deposit.swh_id !== null) { - cy.contains(deposit.swh_id).should('be.visible'); - cy.contains(deposit.swh_id_context).should('be.visible'); + if (deposit.swhid !== null) { + cy.contains(deposit.swhid).should('be.visible'); + cy.contains(deposit.swhid_context).should('be.visible'); } }); }); diff --git a/cypress/integration/origin-search.spec.js b/cypress/integration/origin-search.spec.js --- a/cypress/integration/origin-search.spec.js +++ b/cypress/integration/origin-search.spec.js @@ -105,8 +105,8 @@ cy.route({ method: 'GET', - url: `${this.Urls.api_1_resolve_swh_pid('').slice(0, -1)}**` - }).as('resolvePid'); + url: `${this.Urls.api_1_resolve_swhid('').slice(0, -1)}**` + }).as('resolveSWHID'); cy.route({ method: 'GET', @@ -120,7 +120,7 @@ cy.wait('@searchOrigin'); - cy.xhrShouldBeCalled('resolvePid', 0); + cy.xhrShouldBeCalled('resolveSWHID', 0); cy.xhrShouldBeCalled('searchOrigin', 1); }); @@ -341,43 +341,43 @@ }); }); - context('Test valid persistent ids', function() { + context('Test valid SWHIDs', function() { it('should resolve directory', function() { const redirectUrl = this.Urls.browse_directory(origin.content[0].directory); - const persistentId = `swh:1:dir:${origin.content[0].directory}`; + const swhid = `swh:1:dir:${origin.content[0].directory}`; - searchShouldRedirect(persistentId, redirectUrl); + searchShouldRedirect(swhid, redirectUrl); }); it('should resolve revision', function() { const redirectUrl = this.Urls.browse_revision(origin.revisions[0]); - const persistentId = `swh:1:rev:${origin.revisions[0]}`; + const swhid = `swh:1:rev:${origin.revisions[0]}`; - searchShouldRedirect(persistentId, redirectUrl); + searchShouldRedirect(swhid, redirectUrl); }); it('should resolve snapshot', function() { const redirectUrl = this.Urls.browse_snapshot_directory(origin.snapshot); - const persistentId = `swh:1:snp:${origin.snapshot}`; + const swhid = `swh:1:snp:${origin.snapshot}`; - searchShouldRedirect(persistentId, redirectUrl); + searchShouldRedirect(swhid, redirectUrl); }); it('should resolve content', function() { const redirectUrl = this.Urls.browse_content(`sha1_git:${origin.content[0].sha1git}`); - const persistentId = `swh:1:cnt:${origin.content[0].sha1git}`; + const swhid = `swh:1:cnt:${origin.content[0].sha1git}`; - searchShouldRedirect(persistentId, redirectUrl); + searchShouldRedirect(swhid, redirectUrl); }); it('should not send request to the search endpoint', function() { cy.server(); - const persistentId = `swh:1:rev:${origin.revisions[0]}`; + const swhid = `swh:1:rev:${origin.revisions[0]}`; cy.route({ method: 'GET', - url: this.Urls.api_1_resolve_swh_pid(persistentId) - }).as('resolvePid'); + url: this.Urls.api_1_resolve_swhid(swhid) + }).as('resolveSWHID'); cy.route({ method: 'GET', @@ -385,44 +385,44 @@ }).as('searchOrigin'); cy.get('#origins-url-patterns') - .type(persistentId); + .type(swhid); cy.get('.swh-search-icon') .click(); - cy.wait('@resolvePid'); + cy.wait('@resolveSWHID'); - cy.xhrShouldBeCalled('resolvePid', 1); + cy.xhrShouldBeCalled('resolveSWHID', 1); cy.xhrShouldBeCalled('searchOrigin', 0); }); }); - context('Test invalid persistent ids', function() { + context('Test invalid SWHIDs', function() { it('should show not found for directory', function() { - const persistentId = `swh:1:dir:${this.unarchivedRepo.rootDirectory}`; + const swhid = `swh:1:dir:${this.unarchivedRepo.rootDirectory}`; const msg = `Directory with sha1_git ${this.unarchivedRepo.rootDirectory} not found`; - searchShouldShowNotFound(persistentId, msg); + searchShouldShowNotFound(swhid, msg); }); it('should show not found for snapshot', function() { - const persistentId = `swh:1:snp:${this.unarchivedRepo.snapshot}`; + const swhid = `swh:1:snp:${this.unarchivedRepo.snapshot}`; const msg = `Snapshot with id ${this.unarchivedRepo.snapshot} not found!`; - searchShouldShowNotFound(persistentId, msg); + searchShouldShowNotFound(swhid, msg); }); it('should show not found for revision', function() { - const persistentId = `swh:1:rev:${this.unarchivedRepo.revision}`; + const swhid = `swh:1:rev:${this.unarchivedRepo.revision}`; const msg = `Revision with sha1_git ${this.unarchivedRepo.revision} not found.`; - searchShouldShowNotFound(persistentId, msg); + searchShouldShowNotFound(swhid, msg); }); it('should show not found for content', function() { - const persistentId = `swh:1:cnt:${this.unarchivedRepo.content[0].sha1git}`; + const swhid = `swh:1:cnt:${this.unarchivedRepo.content[0].sha1git}`; const msg = `Content with sha1_git checksum equals to ${this.unarchivedRepo.content[0].sha1git} not found!`; - searchShouldShowNotFound(persistentId, msg); + searchShouldShowNotFound(swhid, msg); }); }); diff --git a/cypress/integration/persistent-identifiers.spec.js b/cypress/integration/persistent-identifiers.spec.js --- a/cypress/integration/persistent-identifiers.spec.js +++ b/cypress/integration/persistent-identifiers.spec.js @@ -45,38 +45,38 @@ testsData = [ { 'objectType': 'content', - 'objectPids': [cntSWHIDWithContext, cntSWHID], + 'objectSWHIDs': [cntSWHIDWithContext, cntSWHID], 'badgeUrl': this.Urls.swh_badge('content', swhids.content.object_id), - 'badgePidUrl': this.Urls.swh_badge_pid(cntSWHID), - 'browseUrl': this.Urls.browse_swh_id(cntSWHIDWithContext) + 'badgeSWHIDUrl': this.Urls.swh_badge_swhid(cntSWHID), + 'browseUrl': this.Urls.browse_swhid(cntSWHIDWithContext) }, { 'objectType': 'directory', - 'objectPids': [dirSWHIDWithContext, dirSWHID], + 'objectSWHIDs': [dirSWHIDWithContext, dirSWHID], 'badgeUrl': this.Urls.swh_badge('directory', swhids.directory.object_id), - 'badgePidUrl': this.Urls.swh_badge_pid(dirSWHID), - 'browseUrl': this.Urls.browse_swh_id(dirSWHIDWithContext) + 'badgeSWHIDUrl': this.Urls.swh_badge_swhid(dirSWHID), + 'browseUrl': this.Urls.browse_swhid(dirSWHIDWithContext) }, { 'objectType': 'release', - 'objectPids': [relSWHIDWithContext, relSWHID], + 'objectSWHIDs': [relSWHIDWithContext, relSWHID], 'badgeUrl': this.Urls.swh_badge('release', swhids.release.object_id), - 'badgePidUrl': this.Urls.swh_badge_pid(relSWHID), - 'browseUrl': this.Urls.browse_swh_id(relSWHIDWithContext) + 'badgeSWHIDUrl': this.Urls.swh_badge_swhid(relSWHID), + 'browseUrl': this.Urls.browse_swhid(relSWHIDWithContext) }, { 'objectType': 'revision', - 'objectPids': [revSWHIDWithContext, revSWHID], + 'objectSWHIDs': [revSWHIDWithContext, revSWHID], 'badgeUrl': this.Urls.swh_badge('revision', swhids.revision.object_id), - 'badgePidUrl': this.Urls.swh_badge_pid(revSWHID), - 'browseUrl': this.Urls.browse_swh_id(revSWHIDWithContext) + 'badgeSWHIDUrl': this.Urls.swh_badge_swhid(revSWHID), + 'browseUrl': this.Urls.browse_swhid(revSWHIDWithContext) }, { 'objectType': 'snapshot', - 'objectPids': [snpSWHIDWithContext, snpSWHID], + 'objectSWHIDs': [snpSWHIDWithContext, snpSWHID], 'badgeUrl': this.Urls.swh_badge('snapshot', swhids.snapshot.object_id), - 'badgePidUrl': this.Urls.swh_badge_pid(snpSWHID), - 'browseUrl': this.Urls.browse_swh_id(snpSWHIDWithContext) + 'badgeSWHIDUrl': this.Urls.swh_badge_swhid(snpSWHID), + 'browseUrl': this.Urls.browse_swhid(snpSWHIDWithContext) } ]; @@ -110,15 +110,15 @@ .click(); for (let td of testsData) { - cy.get(`a[href="#swh-id-tab-${td.objectType}"]`) + cy.get(`a[href="#swhid-tab-${td.objectType}"]`) .click(); - cy.get(`#swh-id-tab-${td.objectType}`) + cy.get(`#swhid-tab-${td.objectType}`) .should('be.visible'); - cy.get(`#swh-id-tab-${td.objectType} .swh-id`) - .contains(td.objectPids[0]) - .should('have.attr', 'href', this.Urls.browse_swh_id(td.objectPids[0])); + cy.get(`#swhid-tab-${td.objectType} .swhid`) + .contains(td.objectSWHIDs[0]) + .should('have.attr', 'href', this.Urls.browse_swhid(td.objectSWHIDs[0])); } @@ -130,26 +130,26 @@ for (let td of testsData) { - cy.get(`a[href="#swh-id-tab-${td.objectType}"]`) + cy.get(`a[href="#swhid-tab-${td.objectType}"]`) .click(); - cy.get(`#swh-id-tab-${td.objectType} .swh-id`) - .contains(td.objectPids[0]) - .should('have.attr', 'href', this.Urls.browse_swh_id(td.objectPids[0])); + cy.get(`#swhid-tab-${td.objectType} .swhid`) + .contains(td.objectSWHIDs[0]) + .should('have.attr', 'href', this.Urls.browse_swhid(td.objectSWHIDs[0])); - cy.get(`#swh-id-tab-${td.objectType} .swh-id-option`) + cy.get(`#swhid-tab-${td.objectType} .swhid-option`) .click(); - cy.get(`#swh-id-tab-${td.objectType} .swh-id`) - .contains(td.objectPids[1]) - .should('have.attr', 'href', this.Urls.browse_swh_id(td.objectPids[1])); + cy.get(`#swhid-tab-${td.objectType} .swhid`) + .contains(td.objectSWHIDs[1]) + .should('have.attr', 'href', this.Urls.browse_swhid(td.objectSWHIDs[1])); - cy.get(`#swh-id-tab-${td.objectType} .swh-id-option`) + cy.get(`#swhid-tab-${td.objectType} .swhid-option`) .click(); - cy.get(`#swh-id-tab-${td.objectType} .swh-id`) - .contains(td.objectPids[0]) - .should('have.attr', 'href', this.Urls.browse_swh_id(td.objectPids[0])); + cy.get(`#swhid-tab-${td.objectType} .swhid`) + .contains(td.objectSWHIDs[0]) + .should('have.attr', 'href', this.Urls.browse_swhid(td.objectSWHIDs[0])); } }); @@ -161,13 +161,13 @@ const originBadgeUrl = this.Urls.swh_badge('origin', origin.url); for (let td of testsData) { - cy.get(`a[href="#swh-id-tab-${td.objectType}"]`) + cy.get(`a[href="#swhid-tab-${td.objectType}"]`) .click(); - cy.get(`#swh-id-tab-${td.objectType} .swh-badge-origin`) + cy.get(`#swhid-tab-${td.objectType} .swh-badge-origin`) .should('have.attr', 'src', originBadgeUrl); - cy.get(`#swh-id-tab-${td.objectType} .swh-badge-${td.objectType}`) + cy.get(`#swhid-tab-${td.objectType} .swh-badge-${td.objectType}`) .should('have.attr', 'src', td.badgeUrl); } @@ -180,10 +180,10 @@ .click(); for (let td of testsData) { - cy.get(`a[href="#swh-id-tab-${td.objectType}"]`) + cy.get(`a[href="#swhid-tab-${td.objectType}"]`) .click(); - cy.get(`#swh-id-tab-${td.objectType} .swh-badge-origin`) + cy.get(`#swhid-tab-${td.objectType} .swh-badge-origin`) .click() .wait(500); @@ -197,14 +197,14 @@ .click() .wait(500); - cy.get(`#swh-id-tab-${td.objectType} .swh-badge-${td.objectType}`) + cy.get(`#swhid-tab-${td.objectType} .swh-badge-${td.objectType}`) .click() .wait(500); for (let badgeType of ['html', 'md', 'rst']) { cy.get(`.modal .swh-badge-${badgeType}`) .contains(`${urlPrefix}${td.browseUrl}`) - .contains(`${urlPrefix}${td.badgePidUrl}`); + .contains(`${urlPrefix}${td.badgeSWHIDUrl}`); } cy.get('.modal.show .close') @@ -220,7 +220,7 @@ for (let testData of testsData) { assert.isTrue(swhIdsContext.hasOwnProperty(testData.objectType)); assert.equal(swhIdsContext[testData.objectType].swhid, - testData.objectPids.slice(-1)[0]); + testData.objectSWHIDs.slice(-1)[0]); } }); }); diff --git a/docs/developers-info.rst b/docs/developers-info.rst --- a/docs/developers-info.rst +++ b/docs/developers-info.rst @@ -117,7 +117,7 @@ * :mod:`swh.web.browse.views.content`: Implementation of endpoints for browsing contents. * :mod:`swh.web.browse.views.directory`: Implementation of endpoints for browsing directories. * :mod:`swh.web.browse.views.identifiers`: Implementation of endpoints for browsing objects - through persistent identifiers. + through :ref:`persistent-identifiers`. * :mod:`swh.web.browse.views.origin`: Implementation of endpoints for browsing origins. * :mod:`swh.web.browse.views.person`: Implementation of endpoints for browsing persons. * :mod:`swh.web.browse.views.release`: Implementation of endpoints for browsing releases. diff --git a/docs/uri-scheme-api-identifiers.rst b/docs/uri-scheme-api-identifiers.rst --- a/docs/uri-scheme-api-identifiers.rst +++ b/docs/uri-scheme-api-identifiers.rst @@ -1,7 +1,7 @@ Persistent identifiers ---------------------- -.. autosimple:: swh.web.api.views.identifiers.api_resolve_swh_pid +.. autosimple:: swh.web.api.views.identifiers.api_resolve_swhid -.. autosimple:: swh.web.api.views.identifiers.api_swh_pid_known +.. autosimple:: swh.web.api.views.identifiers.api_swhid_known diff --git a/docs/uri-scheme-identifiers.rst b/docs/uri-scheme-identifiers.rst --- a/docs/uri-scheme-identifiers.rst +++ b/docs/uri-scheme-identifiers.rst @@ -2,19 +2,18 @@ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A subset of Software Heritage objects (contents, directories, releases and -revisions) can be browsed using :ref:`SWHIDs `. Those +revisions) can be browsed using :ref:`persistent-identifiers`. Those identifiers are guaranteed to remain stable (persistent) over time. -.. http:get:: /(swh_id)/ +.. http:get:: /(swhid)/ - End point to browse Software Heritage objects using their persistent identifiers. + Endpoint to browse Software Heritage objects using their SWHIDs. A redirection to the adequate HTML view will be performed when reaching it. - :param string swh_id: a persistent identifier for a Software Heritage - object, or SWHID (see :ref:`persistent identifiers - ` to learn more about its syntax) + :param string swhid: a SoftWare Heritage persistent IDentifier + object, or SWHID (see :ref:`persistent-identifiers` to learn more about its syntax) :resheader Location: the redirection URL for browsing the Software Heritage object associated to the provided identifier :statuscode 302: no error 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 @@ -96,8 +96,8 @@ "reception_date": d["reception_date"], "status": d["status"], "status_detail": d["status_detail"], - "swh_id": d["swh_id"], - "swh_id_context": d["swh_id_context"], + "swhid": d["swh_id"], + "swhid_context": d["swh_id_context"], } for d in data ] diff --git a/swh/web/api/views/identifiers.py b/swh/web/api/views/identifiers.py --- a/swh/web/api/views/identifiers.py +++ b/swh/web/api/views/identifiers.py @@ -8,42 +8,38 @@ from swh.web.common import service from swh.web.common.exc import LargePayloadExc from swh.web.common.identifiers import ( - resolve_swh_persistent_id, - get_persistent_identifier, - group_swh_persistent_identifiers, + resolve_swhid, + get_swhid, + group_swhids, ) -@api_route(r"/resolve/(?P.*)/", "api-1-resolve-swh-pid") +@api_route(r"/resolve/(?P.*)/", "api-1-resolve-swhid") @api_doc("/resolve/") @format_docstring() -def api_resolve_swh_pid(request, swh_id): +def api_resolve_swhid(request, swhid): """ - .. http:get:: /api/1/resolve/(swh_id)/ + .. http:get:: /api/1/resolve/(swhid)/ - Resolve a Software Heritage persistent identifier. + Resolve :ref:`persistent-identifiers`. - Try to resolve a provided `persistent identifier - `_ - into an url for browsing the pointed archive object. If the provided - identifier is valid, the existence of the object in the archive - will also be checked. + Try to resolve a provided SWHID into an url for browsing the + pointed archive object. If the provided identifier is valid, + the existence of the object in the archive will also be checked. - :param string swh_id: a Software Heritage persistent identifier + :param string swhid: a SoftWare Heritage persistent IDentifier :>json string browse_url: the url for browsing the pointed object - :>json object metadata: object holding optional parts of the - persistent identifier - :>json string namespace: the persistent identifier namespace + :>json object metadata: object holding optional parts of the SWHID + :>json string namespace: the SWHID namespace :>json string object_id: the hash identifier of the pointed object :>json string object_type: the type of the pointed object - :>json number scheme_version: the scheme version of the persistent - identifier + :>json number scheme_version: the scheme version of the SWHID {common_headers} :statuscode 200: no error - :statuscode 400: an invalid persistent identifier has been provided + :statuscode 400: an invalid SWHID has been provided :statuscode 404: the pointed object does not exist in the archive **Example:** @@ -52,69 +48,65 @@ :swh_web_api:`resolve/swh:1:rev:96db9023b881d7cd9f379b0c154650d6c108e9a3;origin=https://github.com/openssl/openssl/` """ - # try to resolve the provided pid - swh_id_resolved = resolve_swh_persistent_id(swh_id) + # try to resolve the provided swhid + swhid_resolved = resolve_swhid(swhid) # id is well-formed, now check that the pointed # object is present in the archive, NotFoundExc # will be raised otherwise - swh_id_parsed = swh_id_resolved["swh_id_parsed"] - object_type = swh_id_parsed.object_type - object_id = swh_id_parsed.object_id + swhid_parsed = swhid_resolved["swhid_parsed"] + object_type = swhid_parsed.object_type + object_id = swhid_parsed.object_id service.lookup_object(object_type, object_id) # id is well-formed and the pointed object exists - swh_id_data = swh_id_parsed._asdict() - swh_id_data["browse_url"] = request.build_absolute_uri( - swh_id_resolved["browse_url"] - ) - return swh_id_data + swhid_data = swhid_parsed._asdict() + swhid_data["browse_url"] = request.build_absolute_uri(swhid_resolved["browse_url"]) + return swhid_data @api_route(r"/known/", "api-1-known", methods=["POST"]) @api_doc("/known/") @format_docstring() -def api_swh_pid_known(request): +def api_swhid_known(request): """ .. http:post:: /api/1/known/ Check if a list of objects are present in the Software Heritage archive. - The objects to check existence must be provided using Software Heritage - `persistent identifiers - `_. + The objects to check existence must be provided using + :ref:`persistent-identifiers`. - :json object : an object whose keys are input persistent - identifiers and values objects with the following keys: + :>json object : an object whose keys are input SWHIDs and values + objects with the following keys: * **known (bool)**: whether the object was found {common_headers} :statuscode 200: no error - :statuscode 400: an invalid persistent identifier was provided - :statuscode 413: the input array of persistent identifiers is too large + :statuscode 400: an invalid SWHID was provided + :statuscode 413: the input array of SWHIDs is too large """ limit = 1000 if len(request.data) > limit: raise LargePayloadExc( - "The maximum number of PIDs this endpoint can " "receive is %s" % limit + "The maximum number of SWHIDs this endpoint can receive is %s" % limit ) - persistent_ids = [get_persistent_identifier(pid) for pid in request.data] + swhids = [get_swhid(swhid) for swhid in request.data] - response = {str(pid): {"known": False} for pid in persistent_ids} + response = {str(swhid): {"known": False} for swhid in swhids} - # group pids by their type - pids_by_type = group_swh_persistent_identifiers(persistent_ids) + # group swhids by their type + swhids_by_type = group_swhids(swhids) # search for hashes not present in the storage - missing_hashes = service.lookup_missing_hashes(pids_by_type) + missing_hashes = service.lookup_missing_hashes(swhids_by_type) - for pid in persistent_ids: - if pid.object_id not in missing_hashes: - response[str(pid)]["known"] = True + for swhid in swhids: + if swhid.object_id not in missing_hashes: + response[str(swhid)]["known"] = True return response diff --git a/swh/web/assets/src/bundles/admin/deposit.js b/swh/web/assets/src/bundles/admin/deposit.js --- a/swh/web/assets/src/bundles/admin/deposit.js +++ b/swh/web/assets/src/bundles/admin/deposit.js @@ -8,7 +8,7 @@ function genSwhLink(data, type) { if (type === 'display') { if (data && data.startsWith('swh')) { - let browseUrl = Urls.browse_swh_id(data); + let browseUrl = Urls.browse_swhid(data); return `${data}`; } } @@ -51,8 +51,8 @@ name: 'id' }, { - data: 'swh_id_context', - name: 'swh_id_context', + data: 'swhid_context', + name: 'swhid_context', render: (data, type, row) => { if (data && type === 'display') { let originPattern = ';origin='; @@ -102,8 +102,8 @@ visible: false }, { - data: 'swh_id', - name: 'swh_id', + data: 'swhid', + name: 'swhid', render: (data, type, row) => { return genSwhLink(data, type); }, @@ -111,8 +111,8 @@ visible: false }, { - data: 'swh_id_context', - name: 'swh_id_context', + data: 'swhid_context', + name: 'swhid_context', render: (data, type, row) => { return genSwhLink(data, type); }, diff --git a/swh/web/assets/src/bundles/browse/index.js b/swh/web/assets/src/bundles/browse/index.js --- a/swh/web/assets/src/bundles/browse/index.js +++ b/swh/web/assets/src/bundles/browse/index.js @@ -15,4 +15,4 @@ export * from './snapshot-navigation'; export * from './origin-search'; export * from './browse-utils'; -export * from './swh-ids-utils'; +export * from './swhid-utils'; diff --git a/swh/web/assets/src/bundles/browse/origin-search.js b/swh/web/assets/src/bundles/browse/origin-search.js --- a/swh/web/assets/src/bundles/browse/origin-search.js +++ b/swh/web/assets/src/bundles/browse/origin-search.js @@ -156,18 +156,18 @@ inSearch = true; if (searchQueryText.startsWith('swh:')) { // searchQueryText may be a PID so sending search queries to PID resolve endpoint - let resolvePidUrl = Urls.api_1_resolve_swh_pid(searchQueryText); - fetch(resolvePidUrl) + let resolveSWHIDUrl = Urls.api_1_resolve_swhid(searchQueryText); + fetch(resolveSWHIDUrl) .then(handleFetchError) .then(response => response.json()) .then(data => { - // pid has been successfully resolved, + // SWHID has been successfully resolved, // so redirect to browse page window.location = data.browse_url; }) .catch(response => { // display a useful error message if the input - // looks like a swh pid + // looks like a SWHID response.json().then(data => { $('#swh-origin-search-results').hide(); $('.swh-search-pagination').hide(); diff --git a/swh/web/assets/src/bundles/browse/swh-ids-utils.js b/swh/web/assets/src/bundles/browse/swhid-utils.js rename from swh/web/assets/src/bundles/browse/swh-ids-utils.js rename to swh/web/assets/src/bundles/browse/swhid-utils.js --- a/swh/web/assets/src/bundles/browse/swh-ids-utils.js +++ b/swh/web/assets/src/bundles/browse/swhid-utils.js @@ -18,7 +18,7 @@ export function swhIdContextOptionToggled(event) { event.stopPropagation(); - let swhIdElt = $(event.target).closest('.swh-id-ui').find('.swh-id'); + let swhIdElt = $(event.target).closest('.swhid-ui').find('.swhid'); let swhIdWithContext = $(event.target).data('swhid-with-context'); let currentSwhId = swhIdElt.text(); if ($(event.target).prop('checked')) { @@ -36,7 +36,7 @@ } function addLinesInfo() { - let swhIdElt = $('#swh-id-tab-content').find('.swh-id'); + let swhIdElt = $('#swhid-tab-content').find('.swhid'); let currentSwhId = swhIdElt.text(); let lines = []; let linesPart = ';lines='; @@ -53,7 +53,7 @@ linesPart += '-' + lines[1]; } - if ($('#swh-id-context-option-content').prop('checked')) { + if ($('#swhid-context-option-content').prop('checked')) { currentSwhId = currentSwhId.replace(/;lines=\d+-*\d*/g, ''); if (lines.length > 0) { currentSwhId += linesPart; @@ -65,16 +65,16 @@ } $(document).ready(() => { - new ClipboardJS('.btn-swh-id-copy', { + new ClipboardJS('.btn-swhid-copy', { text: trigger => { - let swhId = $(trigger).closest('.swh-id-ui').find('.swh-id').text(); + let swhId = $(trigger).closest('.swhid-ui').find('.swhid').text(); return swhId; } }); - new ClipboardJS('.btn-swh-id-url-copy', { + new ClipboardJS('.btn-swhid-url-copy', { text: trigger => { - let swhId = $(trigger).closest('.swh-id-ui').find('.swh-id').text(); + let swhId = $(trigger).closest('.swhid-ui').find('.swhid').text(); return window.location.origin + '/' + swhId + '/'; } }); @@ -105,7 +105,7 @@ // set the tab visible once the close animation is terminated $('#swh-identifiers').css('display', 'block'); - $('.swh-id-context-option').trigger('click'); + $('.swhid-context-option').trigger('click'); // highlighted code lines changed $(window).on('hashchange', () => { diff --git a/swh/web/assets/src/bundles/webapp/badges.js b/swh/web/assets/src/bundles/webapp/badges.js --- a/swh/web/assets/src/bundles/webapp/badges.js +++ b/swh/web/assets/src/bundles/webapp/badges.js @@ -5,20 +5,20 @@ * See top-level LICENSE file for more information */ -export function showBadgeInfoModal(objectType, objectPid) { +export function showBadgeInfoModal(objectType, objectSWHID) { let badgeImageUrl; let badgeLinkUrl; if (objectType === 'origin') { - badgeImageUrl = Urls.swh_badge(objectType, objectPid); - badgeLinkUrl = `${Urls.browse_origin()}?origin_url=${objectPid}`; + badgeImageUrl = Urls.swh_badge(objectType, objectSWHID); + badgeLinkUrl = `${Urls.browse_origin()}?origin_url=${objectSWHID}`; } else { - const pos = objectPid.indexOf(';'); + const pos = objectSWHID.indexOf(';'); if (pos !== -1) { - badgeImageUrl = Urls.swh_badge_pid(objectPid.slice(0, pos)); + badgeImageUrl = Urls.swh_badge_swhid(objectSWHID.slice(0, pos)); } else { - badgeImageUrl = Urls.swh_badge_pid(objectPid); + badgeImageUrl = Urls.swh_badge_swhid(objectSWHID); } - badgeLinkUrl = Urls.browse_swh_id(objectPid); + badgeLinkUrl = Urls.browse_swhid(objectSWHID); } let urlPrefix = `${window.location.protocol}//${window.location.hostname}`; if (window.location.port) { diff --git a/swh/web/assets/src/bundles/webapp/webapp-utils.js b/swh/web/assets/src/bundles/webapp/webapp-utils.js --- a/swh/web/assets/src/bundles/webapp/webapp-utils.js +++ b/swh/web/assets/src/bundles/webapp/webapp-utils.js @@ -307,11 +307,11 @@ // SWHID metadata contain the following keys: // * object_type: type of archived object // * object_id: sha1 object identifier -// * swhid: SWH persistent identifier without contextual info -// * swhid_url: URL to resolve SWH persistent identifier without contextual info +// * swhid: SWHID without contextual info +// * swhid_url: URL to resolve SWHID without contextual info // * context: object describing SWHID context -// * swhid_with_context: SWH persistent identifier with contextual info -// * swhid_with_context_url: URL to resolve SWH persistent identifier with contextual info +// * swhid_with_context: SWHID with contextual info +// * swhid_with_context_url: URL to resolve SWHID with contextual info let swhidsContext_ = {}; export function setSwhIdsContext(swhidsContext) { diff --git a/swh/web/assets/src/bundles/webapp/webapp.css b/swh/web/assets/src/bundles/webapp/webapp.css --- a/swh/web/assets/src/bundles/webapp/webapp.css +++ b/swh/web/assets/src/bundles/webapp/webapp.css @@ -394,11 +394,11 @@ padding-top: 4px; } -.swh-id { +.swhid { white-space: pre-wrap; } -.swh-id .swh-id-option { +.swhid .swhid-option { display: inline-block; margin-right: 5px; line-height: 1rem; diff --git a/swh/web/browse/identifiers.py b/swh/web/browse/identifiers.py --- a/swh/web/browse/identifiers.py +++ b/swh/web/browse/identifiers.py @@ -5,20 +5,19 @@ from django.shortcuts import redirect -from swh.web.common.identifiers import resolve_swh_persistent_id +from swh.web.common.identifiers import resolve_swhid from swh.web.common.exc import handle_view_exception -def swh_id_browse(request, swh_id): +def swhid_browse(request, swhid): """ - Django view enabling to browse the archive using - :ref:`SWHIDs `. + Django view enabling to browse the archive using :ref:``. - The url that points to it is :http:get:`/(swh_id)/`. + The url that points to it is :http:get:`/(swhid)/`. """ try: - swh_id_resolved = resolve_swh_persistent_id(swh_id, query_params=request.GET) + swhid_resolved = resolve_swhid(swhid, query_params=request.GET) except Exception as exc: return handle_view_exception(request, exc) - return redirect(swh_id_resolved["browse_url"]) + return redirect(swhid_resolved["browse_url"]) diff --git a/swh/web/browse/snapshot_context.py b/swh/web/browse/snapshot_context.py --- a/swh/web/browse/snapshot_context.py +++ b/swh/web/browse/snapshot_context.py @@ -17,7 +17,7 @@ import sentry_sdk from swh.model.identifiers import ( - persistent_identifier, + swhid, snapshot_identifier, CONTENT, DIRECTORY, @@ -499,7 +499,7 @@ is_empty = sum(snapshot_sizes.values()) == 0 - swh_snp_id = persistent_identifier("snapshot", snapshot_id) + swh_snp_id = swhid("snapshot", snapshot_id) if visit_info: timestamp = format_utc_iso_date(visit_info["date"]) diff --git a/swh/web/browse/urls.py b/swh/web/browse/urls.py --- a/swh/web/browse/urls.py +++ b/swh/web/browse/urls.py @@ -14,7 +14,7 @@ import swh.web.browse.views.snapshot # noqa from swh.web.browse.browseurls import BrowseUrls -from swh.web.browse.identifiers import swh_id_browse +from swh.web.browse.identifiers import swhid_browse from swh.web.common.utils import reverse @@ -49,7 +49,7 @@ url(r"^vault/$", _browse_vault_view, name="browse-vault"), # for backward compatibility url(r"^origin/save/$", _browse_origin_save_view, name="browse-origin-save"), - url(r"^(?Pswh:[0-9]+:[a-z]+:[0-9a-f]+.*)/$", swh_id_browse), + url(r"^(?Pswh:[0-9]+:[a-z]+:[0-9a-f]+.*)/$", swhid_browse), ] urlpatterns += BrowseUrls.get_url_patterns() diff --git a/swh/web/browse/views/revision.py b/swh/web/browse/views/revision.py --- a/swh/web/browse/views/revision.py +++ b/swh/web/browse/views/revision.py @@ -13,7 +13,7 @@ from django.utils.safestring import mark_safe from swh.model.identifiers import ( - persistent_identifier, + swhid, CONTENT, DIRECTORY, REVISION, @@ -281,7 +281,7 @@ revision_log_data = format_log_entries(revision_log, per_page) - swh_rev_id = persistent_identifier("revision", sha1_git) + swh_rev_id = swhid("revision", sha1_git) return render( request, diff --git a/swh/web/common/exc.py b/swh/web/common/exc.py --- a/swh/web/common/exc.py +++ b/swh/web/common/exc.py @@ -50,8 +50,7 @@ class LargePayloadExc(Exception): """The input size is too large. - Example: Asking to resolve 10000 persistent identifier when the limit - is 1000. + Example: Asking to resolve 10000 SWHIDs when the limit is 1000. """ pass diff --git a/swh/web/common/identifiers.py b/swh/web/common/identifiers.py --- a/swh/web/common/identifiers.py +++ b/swh/web/common/identifiers.py @@ -4,7 +4,7 @@ # See top-level LICENSE file for more information from urllib.parse import quote -from typing import Any, Dict, Iterable, List, Optional +from typing import cast, Any, Dict, Iterable, List, Optional from typing_extensions import TypedDict from django.http import QueryDict @@ -12,15 +12,15 @@ from swh.model.exceptions import ValidationError from swh.model.hashutil import hash_to_bytes from swh.model.identifiers import ( - persistent_identifier, - parse_persistent_identifier, + swhid, + parse_swhid, CONTENT, DIRECTORY, ORIGIN, RELEASE, REVISION, SNAPSHOT, - PersistentId, + SWHID, ) from swh.web.common import service @@ -35,73 +35,72 @@ from swh.web.common.utils import reverse -def get_swh_persistent_id( +def gen_swhid( object_type: str, object_id: str, scheme_version: int = 1, metadata: SWHIDContext = {}, ) -> str: """ - Returns the persistent identifier for a swh object based on: + Returns the SoftWare Heritage persistent IDentifier for a swh object based on: * the object type * the object id - * the swh identifiers scheme version + * the SWHID scheme version Args: object_type: the swh object type (content/directory/release/revision/snapshot) object_id: the swh object id (hexadecimal representation of its hash value) - scheme_version: the scheme version of the swh - persistent identifiers + scheme_version: the scheme version of the SWHIDs Returns: - the swh object persistent identifier + the SWHID of the object Raises: BadInputExc: if the provided parameters do not enable to generate a valid identifier """ try: - swh_id = persistent_identifier(object_type, object_id, scheme_version, metadata) - except ValidationError as e: - raise BadInputExc( - "Invalid object (%s) for swh persistent id. %s" % (object_id, e) + obj_swhid = swhid( + object_type, object_id, scheme_version, cast(Dict[str, Any], metadata) ) + except ValidationError as e: + raise BadInputExc("Invalid object (%s) for SWHID. %s" % (object_id, e)) else: - return swh_id + return obj_swhid -class ResolvedPersistentId(TypedDict): +class ResolvedSWHID(TypedDict): """parsed SWHID with context""" - swh_id_parsed: PersistentId + swhid_parsed: SWHID """URL to browse object according to SWHID context""" browse_url: Optional[str] -def resolve_swh_persistent_id( - swh_id: str, query_params: Optional[QueryParameters] = None -) -> ResolvedPersistentId: +def resolve_swhid( + swhid: str, query_params: Optional[QueryParameters] = None +) -> ResolvedSWHID: """ - Try to resolve a Software Heritage persistent id into an url for + Try to resolve a SoftWare Heritage persistent IDentifier into an url for browsing the targeted object. Args: - swh_id: a Software Heritage persistent identifier + swhid: a SoftWare Heritage persistent IDentifier query_params: optional dict filled with query parameters to append to the browse url Returns: a dict with the following keys: - * **swh_id_parsed**: the parsed identifier + * **swhid_parsed**: the parsed identifier * **browse_url**: the url for browsing the targeted object """ - swh_id_parsed = get_persistent_identifier(swh_id) - object_type = swh_id_parsed.object_type - object_id = swh_id_parsed.object_id + swhid_parsed = get_swhid(swhid) + object_type = swhid_parsed.object_type + object_id = swhid_parsed.object_id browse_url = None url_args = {} query_dict = QueryDict("", mutable=True) @@ -113,16 +112,14 @@ for k in sorted(query_params.keys()): query_dict[k] = query_params[k] - if "origin" in swh_id_parsed.metadata: - query_dict["origin_url"] = swh_id_parsed.metadata["origin"] + if "origin" in swhid_parsed.metadata: + query_dict["origin_url"] = swhid_parsed.metadata["origin"] - if "anchor" in swh_id_parsed.metadata: - anchor_swhid_parsed = get_persistent_identifier( - swh_id_parsed.metadata["anchor"] - ) + if "anchor" in swhid_parsed.metadata: + anchor_swhid_parsed = get_swhid(swhid_parsed.metadata["anchor"]) - if "path" in swh_id_parsed.metadata and swh_id_parsed.metadata["path"] != "/": - query_dict["path"] = swh_id_parsed.metadata["path"] + if "path" in swhid_parsed.metadata and swhid_parsed.metadata["path"] != "/": + query_dict["path"] = swhid_parsed.metadata["path"] if anchor_swhid_parsed: directory = "" if anchor_swhid_parsed.object_type == DIRECTORY: @@ -136,7 +133,7 @@ revision = service.lookup_revision(release["target"]) directory = revision["directory"] if object_type == CONTENT: - if "origin" not in swh_id_parsed.metadata: + if "origin" not in swhid_parsed.metadata: # when no origin context, content objects need to have their # path prefixed by root directory id for proper breadcrumbs display query_dict["path"] = directory + query_dict["path"] @@ -149,9 +146,9 @@ query_dict["path"] = query_dict["path"][1:-1] # snapshot context - if "visit" in swh_id_parsed.metadata: + if "visit" in swhid_parsed.metadata: - snp_swhid_parsed = get_persistent_identifier(swh_id_parsed.metadata["visit"]) + snp_swhid_parsed = get_swhid(swhid_parsed.metadata["visit"]) if snp_swhid_parsed.object_type != SNAPSHOT: raise BadInputExc("Visit must be a snapshot SWHID.") query_dict["snapshot"] = snp_swhid_parsed.object_id @@ -202,14 +199,13 @@ elif object_type == ORIGIN: raise BadInputExc( ( - "Origin PIDs (Persistent Identifiers) are not " - "publicly resolvable because they are for " + "Origin SWHIDs are not publicly resolvable because they are for " "internal usage only" ) ) - if "lines" in swh_id_parsed.metadata and process_lines: - lines = swh_id_parsed.metadata["lines"].split("-") + if "lines" in swhid_parsed.metadata and process_lines: + lines = swhid_parsed.metadata["lines"].split("-") fragment += "#L" + lines[0] if len(lines) > 1: fragment += "-L" + lines[1] @@ -222,48 +218,44 @@ + fragment ) - return ResolvedPersistentId(swh_id_parsed=swh_id_parsed, browse_url=browse_url) + return ResolvedSWHID(swhid_parsed=swhid_parsed, browse_url=browse_url) -def get_persistent_identifier(persistent_id: str) -> PersistentId: - """Check if a persistent identifier is valid. +def get_swhid(swhid: str) -> SWHID: + """Check if a SWHID is valid and return it parsed. Args: - persistent_id: A string representing a Software Heritage - persistent identifier. + swhid: a SoftWare Heritage persistent IDentifier. Raises: - BadInputExc: if the provided persistent identifier can - not be parsed. + BadInputExc: if the provided SWHID can not be parsed. Return: - A persistent identifier object. + A parsed SWHID. """ try: - pid_object = parse_persistent_identifier(persistent_id) + swhid_parsed = parse_swhid(swhid) except ValidationError as ve: raise BadInputExc("Error when parsing identifier: %s" % " ".join(ve.messages)) else: - return pid_object + return swhid_parsed -def group_swh_persistent_identifiers( - persistent_ids: Iterable[PersistentId], -) -> Dict[str, List[bytes]]: +def group_swhids(swhids: Iterable[SWHID],) -> Dict[str, List[bytes]]: """ - Groups many Software Heritage persistent identifiers into a + Groups many SoftWare Heritage persistent IDentifiers into a dictionary depending on their type. Args: - persistent_ids: an iterable of Software Heritage persistent - identifier objects + swhids: an iterable of SoftWare Heritage persistent + IDentifier objects Returns: A dictionary with: - keys: persistent identifier types - values: persistent identifiers id + keys: object types + values: object hashes """ - pids_by_type: Dict[str, List[bytes]] = { + swhids_by_type: Dict[str, List[bytes]] = { CONTENT: [], DIRECTORY: [], REVISION: [], @@ -271,12 +263,12 @@ SNAPSHOT: [], } - for pid in persistent_ids: - obj_id = pid.object_id - obj_type = pid.object_type - pids_by_type[obj_type].append(hash_to_bytes(obj_id)) + for obj_swhid in swhids: + obj_id = obj_swhid.object_id + obj_type = obj_swhid.object_type + swhids_by_type[obj_type].append(hash_to_bytes(obj_id)) - return pids_by_type + return swhids_by_type def get_swhids_info( @@ -285,8 +277,7 @@ extra_context: Optional[Dict[str, Any]] = None, ) -> List[SWHIDInfo]: """ - Returns a list of dict containing info related to persistent - identifiers of swh objects. + Returns a list of dict containing info related to SWHIDs of objects. Args: swh_objects: an iterable of dict describing archived objects @@ -296,7 +287,7 @@ the objects Returns: - a list of dict containing persistent identifiers info + a list of dict containing SWHIDs info """ swhids_info = [] @@ -323,16 +314,16 @@ snapshot_context["origin_info"]["url"], safe="/?:@&" ) if object_type != SNAPSHOT: - swhid_context["visit"] = get_swh_persistent_id( + swhid_context["visit"] = gen_swhid( SNAPSHOT, snapshot_context["snapshot_id"] ) if object_type in (CONTENT, DIRECTORY): if snapshot_context["release_id"] is not None: - swhid_context["anchor"] = get_swh_persistent_id( + swhid_context["anchor"] = gen_swhid( RELEASE, snapshot_context["release_id"] ) elif snapshot_context["revision_id"] is not None: - swhid_context["anchor"] = get_swh_persistent_id( + swhid_context["anchor"] = gen_swhid( REVISION, snapshot_context["revision_id"] ) @@ -343,9 +334,7 @@ and extra_context["revision"] and "anchor" not in swhid_context ): - swhid_context["anchor"] = get_swh_persistent_id( - REVISION, extra_context["revision"] - ) + swhid_context["anchor"] = gen_swhid(REVISION, extra_context["revision"]) elif ( extra_context and "root_directory" in extra_context @@ -356,7 +345,7 @@ or extra_context["root_directory"] != object_id ) ): - swhid_context["anchor"] = get_swh_persistent_id( + swhid_context["anchor"] = gen_swhid( DIRECTORY, extra_context["root_directory"] ) path = None @@ -367,17 +356,17 @@ if path: swhid_context["path"] = quote(path, safe="/?:@&") - swhid = get_swh_persistent_id(object_type, object_id) - swhid_url = reverse("browse-swh-id", url_args={"swh_id": swhid}) + swhid = gen_swhid(object_type, object_id) + swhid_url = reverse("browse-swhid", url_args={"swhid": swhid}) swhid_with_context = None swhid_with_context_url = None if swhid_context: - swhid_with_context = get_swh_persistent_id( + swhid_with_context = gen_swhid( object_type, object_id, metadata=swhid_context ) swhid_with_context_url = reverse( - "browse-swh-id", url_args={"swh_id": swhid_with_context} + "browse-swhid", url_args={"swhid": swhid_with_context} ) swhids_info.append( diff --git a/swh/web/common/service.py b/swh/web/common/service.py --- a/swh/web/common/service.py +++ b/swh/web/common/service.py @@ -1286,20 +1286,20 @@ ) -def lookup_missing_hashes(grouped_pids: Dict[str, List[bytes]]) -> Set[str]: +def lookup_missing_hashes(grouped_swhids: Dict[str, List[bytes]]) -> Set[str]: """Lookup missing Software Heritage persistent identifier hash, using batch processing. Args: A dictionary with: - keys: persistent identifier type - values: list(bytes) persistent identifier hash + keys: object types + values: object hashes Returns: A set(hexadecimal) of the hashes not found in the storage """ missing_hashes = [] - for obj_type, obj_ids in grouped_pids.items(): + for obj_type, obj_ids in grouped_swhids.items(): if obj_type == CONTENT: missing_hashes.append(storage.content_missing_per_sha1_git(obj_ids)) elif obj_type == DIRECTORY: diff --git a/swh/web/misc/badges.py b/swh/web/misc/badges.py --- a/swh/web/misc/badges.py +++ b/swh/web/misc/badges.py @@ -14,8 +14,8 @@ from swh.model.exceptions import ValidationError from swh.model.identifiers import ( - persistent_identifier, - parse_persistent_identifier, + swhid, + parse_swhid, CONTENT, DIRECTORY, ORIGIN, @@ -25,7 +25,7 @@ ) from swh.web.common import service from swh.web.common.exc import BadInputExc, NotFoundExc -from swh.web.common.identifiers import resolve_swh_persistent_id +from swh.web.common.identifiers import resolve_swhid from swh.web.common.utils import reverse @@ -65,7 +65,7 @@ request: HttpRequest, object_type: str, object_id: str, - object_pid: Optional[str] = "", + object_swhid: Optional[str] = "", ) -> HttpResponse: """ Generate a Software Heritage badge for a given object type and id. @@ -77,8 +77,7 @@ or *snapshot* object_id: The id of the swh object, either an url for origin type or a *sha1* for other object types - object_pid: If provided, the object persistent - identifier will not be recomputed + object_swhid: If provided, the object SWHID will not be recomputed Returns: HTTP response with content type *image/svg+xml* containing the SVG @@ -98,21 +97,21 @@ "browse-origin", query_params={"origin_url": object_id} ) else: - # when pid is provided, object type and id will be parsed + # when SWHID is provided, object type and id will be parsed # from it - if object_pid: - parsed_pid = parse_persistent_identifier(object_pid) - object_type = parsed_pid.object_type - object_id = parsed_pid.object_id + if object_swhid: + parsed_swhid = parse_swhid(object_swhid) + object_type = parsed_swhid.object_type + object_id = parsed_swhid.object_id swh_object = service.lookup_object(object_type, object_id) - if object_pid: - right_text = object_pid + if object_swhid: + right_text = object_swhid else: - right_text = persistent_identifier(object_type, object_id) + right_text = swhid(object_type, object_id) - whole_link = resolve_swh_persistent_id(right_text)["browse_url"] - # remove pid metadata if any for badge text - if object_pid: + whole_link = resolve_swhid(right_text)["browse_url"] + # remove SWHID metadata if any for badge text + if object_swhid: right_text = right_text.split(";")[0] # use release name for badge text if object_type == RELEASE: @@ -138,21 +137,20 @@ return HttpResponse(badge_data, content_type="image/svg+xml") -def _swh_badge_pid(request: HttpRequest, object_pid: str) -> HttpResponse: +def _swh_badge_swhid(request: HttpRequest, object_swhid: str) -> HttpResponse: """ - Generate a Software Heritage badge for a given object persistent - identifier. + Generate a Software Heritage badge for a given object SWHID. Args: request (django.http.HttpRequest): input http request - object_pid (str): A swh object persistent identifier + object_swhid (str): a SWHID of an archived object Returns: django.http.HttpResponse: An http response with content type *image/svg+xml* containing the SVG badge data. If any error occurs, a status code of 400 will be returned. """ - return _swh_badge(request, "", "", object_pid) + return _swh_badge(request, "", "", object_swhid) urlpatterns = [ @@ -162,8 +160,8 @@ name="swh-badge", ), url( - r"^badge/(?Pswh:[0-9]+:[a-z]+:[0-9a-f]+.*)/$", - _swh_badge_pid, - name="swh-badge-pid", + r"^badge/(?Pswh:[0-9]+:[a-z]+:[0-9a-f]+.*)/$", + _swh_badge_swhid, + name="swh-badge-swhid", ), ] diff --git a/swh/web/templates/includes/origin-search-form.html b/swh/web/templates/includes/origin-search-form.html --- a/swh/web/templates/includes/origin-search-form.html +++ b/swh/web/templates/includes/origin-search-form.html @@ -7,26 +7,26 @@
- +
-
+
-
+
-
+