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

fix(authsome-mode): Refactor

parent 3ce7b789
No related branches found
No related tags found
3 merge requests!222Sprint #26,!217Sprint #26,!195feat(authsome-mode): Added rule for PATCH collection
......@@ -65,10 +65,8 @@ function unauthenticatedUser(operation, object, userId) {
return false
}
const filterDraftCollections = c => get(c, 'status', 'draft') !== 'draft'
const filterTechnicalChecksCollections = c =>
get(c, 'status', 'draft') !== 'technicalChecks'
const isCollectionInStatuses = (c, statuses) =>
statuses.includes(get(c, 'status', 'draft'))
const filterNoFragmentCollections = c => c.fragments.length !== 0
......@@ -81,11 +79,11 @@ async function applyAuthenticatedUserPolicy(user, operation, object, context) {
}
if (get(object, 'type') === 'collection') {
if (
!filterDraftCollections(object) ||
!filterTechnicalChecksCollections(object)
)
return false
if (isCollectionInStatuses(object, ['draft', 'technicalChecks'])) {
if (!helpers.isOwner({ user, object })) {
return false
}
}
return {
filter: async collection => {
const userPermissions = await helpers.getUserPermissions({
......@@ -347,10 +345,7 @@ async function applyAdminPolicy(user, operation, object, context) {
async function applyEditorInChiefPolicy(user, operation, object, context) {
if (operation === 'GET') {
if (get(object, 'type') === 'collection') {
if (
!filterDraftCollections(object) ||
!filterTechnicalChecksCollections(object)
)
if (isCollectionInStatuses(object, ['draft', 'technicalChecks']))
return false
return {
filter: collection => ({
......@@ -367,10 +362,7 @@ async function applyEditorInChiefPolicy(user, operation, object, context) {
const collection = await context.models.Collection.find(
get(object, 'collectionId'),
)
if (
!filterDraftCollections(collection) ||
!filterTechnicalChecksCollections(collection)
)
if (isCollectionInStatuses(collection, ['draft', 'technicalChecks']))
return false
}
......@@ -386,8 +378,7 @@ async function applyEditorInChiefPolicy(user, operation, object, context) {
const collections = await context.models.Collection.all()
return Promise.all(
collections
.filter(filterDraftCollections)
.filter(filterTechnicalChecksCollections)
.filter(c => !isCollectionInStatuses(c, ['draft', 'technicalChecks']))
.filter(filterNoFragmentCollections)
.map(async coll => {
const latestFragmentId = coll.fragments[coll.fragments.length - 1]
......
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