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) { ...@@ -65,10 +65,8 @@ function unauthenticatedUser(operation, object, userId) {
return false return false
} }
const filterDraftCollections = c => get(c, 'status', 'draft') !== 'draft' const isCollectionInStatuses = (c, statuses) =>
statuses.includes(get(c, 'status', 'draft'))
const filterTechnicalChecksCollections = c =>
get(c, 'status', 'draft') !== 'technicalChecks'
const filterNoFragmentCollections = c => c.fragments.length !== 0 const filterNoFragmentCollections = c => c.fragments.length !== 0
...@@ -81,11 +79,11 @@ async function applyAuthenticatedUserPolicy(user, operation, object, context) { ...@@ -81,11 +79,11 @@ async function applyAuthenticatedUserPolicy(user, operation, object, context) {
} }
if (get(object, 'type') === 'collection') { if (get(object, 'type') === 'collection') {
if ( if (isCollectionInStatuses(object, ['draft', 'technicalChecks'])) {
!filterDraftCollections(object) || if (!helpers.isOwner({ user, object })) {
!filterTechnicalChecksCollections(object) return false
) }
return false }
return { return {
filter: async collection => { filter: async collection => {
const userPermissions = await helpers.getUserPermissions({ const userPermissions = await helpers.getUserPermissions({
...@@ -347,10 +345,7 @@ async function applyAdminPolicy(user, operation, object, context) { ...@@ -347,10 +345,7 @@ async function applyAdminPolicy(user, operation, object, context) {
async function applyEditorInChiefPolicy(user, operation, object, context) { async function applyEditorInChiefPolicy(user, operation, object, context) {
if (operation === 'GET') { if (operation === 'GET') {
if (get(object, 'type') === 'collection') { if (get(object, 'type') === 'collection') {
if ( if (isCollectionInStatuses(object, ['draft', 'technicalChecks']))
!filterDraftCollections(object) ||
!filterTechnicalChecksCollections(object)
)
return false return false
return { return {
filter: collection => ({ filter: collection => ({
...@@ -367,10 +362,7 @@ async function applyEditorInChiefPolicy(user, operation, object, context) { ...@@ -367,10 +362,7 @@ async function applyEditorInChiefPolicy(user, operation, object, context) {
const collection = await context.models.Collection.find( const collection = await context.models.Collection.find(
get(object, 'collectionId'), get(object, 'collectionId'),
) )
if ( if (isCollectionInStatuses(collection, ['draft', 'technicalChecks']))
!filterDraftCollections(collection) ||
!filterTechnicalChecksCollections(collection)
)
return false return false
} }
...@@ -386,8 +378,7 @@ async function applyEditorInChiefPolicy(user, operation, object, context) { ...@@ -386,8 +378,7 @@ async function applyEditorInChiefPolicy(user, operation, object, context) {
const collections = await context.models.Collection.all() const collections = await context.models.Collection.all()
return Promise.all( return Promise.all(
collections collections
.filter(filterDraftCollections) .filter(c => !isCollectionInStatuses(c, ['draft', 'technicalChecks']))
.filter(filterTechnicalChecksCollections)
.filter(filterNoFragmentCollections) .filter(filterNoFragmentCollections)
.map(async coll => { .map(async coll => {
const latestFragmentId = coll.fragments[coll.fragments.length - 1] 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