Skip to content

Commit

Permalink
Fix issue with remove owner having the wrong link
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmyers committed Dec 23, 2024
1 parent d2a025c commit 9d99081
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
44 changes: 25 additions & 19 deletions lib/actions/removeOwnedBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ module.exports = function (req, res) {

return getOwnedBy(uri, graphUri).then((ownedBy) => {
if (ownedBy.indexOf(config.get('databasePrefix') + 'user/' + req.user.username) === -1) {
res.status(401).send('not authorized to remove an owner')
return res.status(401).send('Not authorized to remove an owner')
}

return retrieveUris(uri, graphUri).then(uris => {
return retrieveUris(uri, graphUri).then((uris) => {
let chunks = []
let offset = config.get('resolveBatch')

for (let i = 0; i < uris.length; i += offset) {
let end = i + offset < uris.length ? i + offset : uris.length

chunks.push(uris.slice(i, end))
}

Expand All @@ -30,22 +29,29 @@ module.exports = function (req, res) {

console.log(sharedRemovalQuery)

return sparql.updateQuery(sharedRemovalQuery, req.body.userUri).then(result => {
return Promise.all(chunks.map(chunk => {
let uris = chunk.map(uri => {
return '<' + uri + '> sbh:ownedBy <' + req.body.userUri + '>'
}).join(' . \n')

const updateQuery = loadTemplate('./sparql/RemoveOwnedBy.sparql', {
uris: uris
})
console.log(updateQuery)

return sparql.updateQuery(updateQuery, graphUri).then(() => {
res.redirect(share)
})
}))
})
return sparql.updateQuery(sharedRemovalQuery, req.body.userUri)
.then(() => {
return Promise.all(
chunks.map((chunk) => {
let uris = chunk
.map((uri) => `<${uri}> sbh:ownedBy <${req.body.userUri}>`)
.join(' . \n')

const updateQuery = loadTemplate('./sparql/RemoveOwnedBy.sparql', { uris })
console.log(updateQuery)

return sparql.updateQuery(updateQuery, graphUri)
})
)
})
.then(() => {
// Redirect only once after all promises resolve
res.redirect(share)
})
.catch((err) => {
console.error('Error:', err)
res.status(500).send(`Error removing ownership: ${err.message}`)
})
})
})
}
2 changes: 1 addition & 1 deletion templates/layouts/identified.jade
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ block content
span.fa.fa-search
if(meta.canEdit && annotation.removeOwner)
form.form-inline(style="display: inline" method='POST', action=annotation.removeOwner)
input(type='hidden' name='userUri' value=config.databasePrefix + 'user/' + annotation.value)
input(type='hidden' name='userUri' value=config.databasePrefix + annotation.value)
button.fakelink(type='submit')
| &nbsp;
span.fa.fa-trash
Expand Down

0 comments on commit 9d99081

Please sign in to comment.