From a76eb76119ef49f777045223ff9f8c3783e8e882 Mon Sep 17 00:00:00 2001 From: Chris Myers Date: Sat, 14 Dec 2024 14:20:11 -0700 Subject: [PATCH 1/2] Change share URI to be derived only from collection --- lib/app.js | 1 + lib/getUrisFromReq.js | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/app.js b/lib/app.js index fbfac9258..3d36b8382 100644 --- a/lib/app.js +++ b/lib/app.js @@ -414,6 +414,7 @@ function App () { app.post('/user/:userId/:collectionId/:displayId/:version/addOwner', requireUser, views.addOwner) app.post('/user/:userId/:collectionId/:displayId/:version/removeOwner/:username', requireUser, actions.removeOwner) app.get('/user/:userId/:collectionId/:displayId/:version/shareLink', requireUser, api.shareLink) + app.get('/user/:userId/:collectionId/:displayId/:version/:hash/share/shareLink', requirePublicLogin, api.shareLink) app.get('/user/:userId/:collectionId/:displayId/:version/:hash/share/addOwner', requirePublicLogin, views.addOwner) app.post('/user/:userId/:collectionId/:displayId/:version/:hash/share/addOwner', requirePublicLogin, views.addOwner) diff --git a/lib/getUrisFromReq.js b/lib/getUrisFromReq.js index 5092be55d..72c25ad68 100644 --- a/lib/getUrisFromReq.js +++ b/lib/getUrisFromReq.js @@ -17,6 +17,7 @@ function getUrisFromReq (req, res) { var share var baseUri var baseUrl + var collectionUri var edit = false if (req.params.userId) { @@ -28,11 +29,12 @@ function getUrisFromReq (req, res) { baseUrl = '/user/' + encodeURIComponent(req.params.userId) + '/' + req.params.collectionId baseUri = config.get('databasePrefix') + 'user/' + encodeURIComponent(req.params.userId) + '/' + req.params.collectionId uri = config.get('databasePrefix') + 'user/' + encodeURIComponent(req.params.userId) + '/' + designId + collectionUri = config.get('databasePrefix') + 'user/' + encodeURIComponent(req.params.userId) + '/' + req.params.collectionId var webOfRegistries = config.get('webOfRegistries') var prefix = config.get('databasePrefix') prefix = prefix.substring(0, prefix.length - 1) - share = config.get('databasePrefix') + 'user/' + encodeURIComponent(req.params.userId) + '/' + designId + '/' + sha1('synbiohub_' + sha1(uri) + config.get('shareLinkSalt')) + '/share' + share = config.get('databasePrefix') + 'user/' + encodeURIComponent(req.params.userId) + '/' + designId + '/' + sha1('synbiohub_' + sha1(collectionUri) + config.get('shareLinkSalt')) + '/share' if (webOfRegistries[prefix]) { share = share.replace(prefix, webOfRegistries[prefix]) } @@ -46,6 +48,9 @@ function getUrisFromReq (req, res) { if (sha1('synbiohub_' + sha1(uri) + config.get('shareLinkSalt')) === req.params.hash) { graphUri = config.get('databasePrefix') + util.createTriplestoreID(req.params.userId) url = share + } else if (sha1('synbiohub_' + sha1(collectionUri) + config.get('shareLinkSalt')) === req.params.hash) { + graphUri = config.get('databasePrefix') + util.createTriplestoreID(req.params.userId) + url = share } else if (sha1('synbiohub_' + sha1(uri + '/edit') + config.get('shareLinkSalt')) === req.params.hash) { graphUri = config.get('databasePrefix') + util.createTriplestoreID(req.params.userId) url = share From fd6d8b762275317b2bfd89c5264288c05d43d248 Mon Sep 17 00:00:00 2001 From: Chris Myers Date: Fri, 20 Dec 2024 13:17:47 -0700 Subject: [PATCH 2/2] Only use collectionUri to build share link for /shareLink endpoint to minimize impact on SBH1 --- lib/getUrisFromReq.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/getUrisFromReq.js b/lib/getUrisFromReq.js index 72c25ad68..67d353dbf 100644 --- a/lib/getUrisFromReq.js +++ b/lib/getUrisFromReq.js @@ -34,7 +34,11 @@ function getUrisFromReq (req, res) { var webOfRegistries = config.get('webOfRegistries') var prefix = config.get('databasePrefix') prefix = prefix.substring(0, prefix.length - 1) - share = config.get('databasePrefix') + 'user/' + encodeURIComponent(req.params.userId) + '/' + designId + '/' + sha1('synbiohub_' + sha1(collectionUri) + config.get('shareLinkSalt')) + '/share' + if (req.url.endsWith('/shareLink')) { + share = config.get('databasePrefix') + 'user/' + encodeURIComponent(req.params.userId) + '/' + designId + '/' + sha1('synbiohub_' + sha1(collectionUri) + config.get('shareLinkSalt')) + '/share' + } else { + share = config.get('databasePrefix') + 'user/' + encodeURIComponent(req.params.userId) + '/' + designId + '/' + sha1('synbiohub_' + sha1(uri) + config.get('shareLinkSalt')) + '/share' + } if (webOfRegistries[prefix]) { share = share.replace(prefix, webOfRegistries[prefix]) }