Skip to content

Commit

Permalink
fix: Check Asset labelIds for invalid values (NUWCDIVNPT#1154)
Browse files Browse the repository at this point in the history
* check that labelId is associated with specified collection

* throw specific error when invalid labelId is supplied

* used wrong collectionId

* use label projection in existing getCollection call, rather than specifically calling another service method to look for label

* tests for invalid asset labels
  • Loading branch information
cd-rite authored Nov 22, 2023
1 parent c679109 commit 1f7fe2b
Show file tree
Hide file tree
Showing 3 changed files with 563 additions and 4 deletions.
7 changes: 6 additions & 1 deletion api/source/controllers/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,12 @@ module.exports.putAssetsByCollectionLabelId = async function (req, res, next) {
const collectionId = getCollectionIdAndCheckPermission(req)
const labelId = req.params.labelId
const assetIds = req.body
let collection = await CollectionService.getCollection( collectionId, ['assets'], false, req.userObject)
let collection = await CollectionService.getCollection( collectionId, ['assets','labels'], false, req.userObject)

if (!collection.labels.find( l => l.labelId === labelId)) {
throw new SmError.PrivilegeError('The labelId is not associated with this Collection.')
}

let collectionAssets = collection.assets.map( a => a.assetId)
if (assetIds.every( a => collectionAssets.includes(a))) {
await CollectionService.putAssetsByCollectionLabelId( collectionId, labelId, assetIds, res.svcStatus )
Expand Down
4 changes: 2 additions & 2 deletions api/source/service/mysql/AssetService.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ exports.addOrUpdateAsset = async function ( {writeAction, assetId, body, project
FROM
collection_label
WHERE
uuid IN (?)`
await connection.query(sqlInsertLabels, [assetId, uuidBinds])
uuid IN (?) and collectionId = ?`
await connection.query(sqlInsertLabels, [assetId, uuidBinds, assetFields.collectionId])
}
}

Expand Down
Loading

0 comments on commit 1f7fe2b

Please sign in to comment.