Skip to content

Commit

Permalink
Merge branch 'master' into fixRemoveOwner
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmyers authored Jan 16, 2025
2 parents 9bd5201 + 18cf095 commit c266fbe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
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
14 changes: 10 additions & 4 deletions lib/views/browse.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,22 @@ module.exports = function (req, res) {
user: req.user,
collections: collections
}

res.send(pug.renderFile('templates/views/browse.jade', locals))
if (!req.accepts('text/html')) {
return res.status(200).header('content-type', 'application/json').send(JSON.stringify(collections))
} else {
res.send(pug.renderFile('templates/views/browse.jade', locals))
}
}).catch((err) => {
var locals = {
config: config.get(),
section: 'errors',
user: req.user,
errors: [err.stack]
}

res.send(pug.renderFile('templates/views/errors/errors.jade', locals))
if (!req.accepts('text/html')) {
return res.status(500).send('Error getting root collections')
} else {
res.send(pug.renderFile('templates/views/errors/errors.jade', locals))
}
})
}

0 comments on commit c266fbe

Please sign in to comment.