Skip to content
Snippets Groups Projects
Commit 44f12bb5 authored by Mihail Hagiu's avatar Mihail Hagiu
Browse files

fix(authsome-mode): Check for last fragment on back-end when editing metadata

parent a6b28ce8
No related branches found
No related tags found
3 merge requests!222Sprint #26,!217Sprint #26,!195feat(authsome-mode): Added rule for PATCH collection
...@@ -37,6 +37,9 @@ const isOwner = ({ user: { id }, object }) => { ...@@ -37,6 +37,9 @@ const isOwner = ({ user: { id }, object }) => {
return !!object.owners.find(own => own.id === id) return !!object.owners.find(own => own.id === id)
} }
const isLastFragment = (collection, fragment) =>
get(fragment, 'id', '') === last(get(collection, 'fragments', []))
const hasPermissionForObject = async ({ user, object, Team, roles = [] }) => { const hasPermissionForObject = async ({ user, object, Team, roles = [] }) => {
const userPermissions = await getUserPermissions({ const userPermissions = await getUserPermissions({
user, user,
...@@ -333,6 +336,7 @@ module.exports = { ...@@ -333,6 +336,7 @@ module.exports = {
parseUser, parseUser,
getUsersList, getUsersList,
getCollections, getCollections,
isLastFragment,
isHandlingEditor, isHandlingEditor,
getUserPermissions, getUserPermissions,
setCollectionStatus, setCollectionStatus,
......
...@@ -325,6 +325,15 @@ async function applyAdminPolicy(user, operation, object, context) { ...@@ -325,6 +325,15 @@ async function applyAdminPolicy(user, operation, object, context) {
) )
} }
} }
if (operation === 'PATCH') {
if (get(object, 'current.type') === 'fragment') {
const collection = await context.models.Collection.find(
get(object, 'current.collectionId'),
)
const isLast = helpers.isLastFragment(collection, get(object, 'current'))
return isLast
}
}
return true return true
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment