Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change share URI to be derived only from collection #1590

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,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)
Expand Down
11 changes: 10 additions & 1 deletion lib/getUrisFromReq.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function getUrisFromReq (req, res) {
var share
var baseUri
var baseUrl
var collectionUri
var edit = false

if (req.params.userId) {
Expand All @@ -28,11 +29,16 @@ 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'
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])
}
Expand All @@ -46,6 +52,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
Expand Down
Loading