Skip to content

Commit

Permalink
do not flatten collection/global permissions themselves to true
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessioGr committed Nov 20, 2024
1 parent adadafc commit 260eb1c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
9 changes: 7 additions & 2 deletions packages/graphql/src/resolvers/collections/docAccess.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { Collection, CollectionPermission, GlobalPermission, PayloadRequest } from 'payload'
import type {
Collection,
PayloadRequest,
SanitizedCollectionPermission,
SanitizedGlobalPermission,
} from 'payload'

import { docAccessOperation, isolateObjectProperty } from 'payload'

Expand All @@ -12,7 +17,7 @@ export type Resolver = (
context: {
req: PayloadRequest
},
) => Promise<CollectionPermission | GlobalPermission>
) => Promise<SanitizedCollectionPermission | SanitizedGlobalPermission>

export function docAccessResolver(collection: Collection): Resolver {
async function resolver(_, args, context: Context) {
Expand Down
6 changes: 3 additions & 3 deletions packages/graphql/src/resolvers/globals/docAccess.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {
CollectionPermission,
GlobalPermission,
PayloadRequest,
SanitizedCollectionPermission,
SanitizedGlobalConfig,
SanitizedGlobalPermission,
} from 'payload'

import { docAccessOperationGlobal, isolateObjectProperty } from 'payload'
Expand All @@ -14,7 +14,7 @@ export type Resolver = (
context: {
req: PayloadRequest
},
) => Promise<CollectionPermission | GlobalPermission>
) => Promise<SanitizedCollectionPermission | SanitizedGlobalPermission>

export function docAccessResolver(global: SanitizedGlobalConfig): Resolver {
async function resolver(_, context: Context) {
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/views/Document/getDocumentPermissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const getDocumentPermissions = async (args: {
_status: 'published',
},
},
}).then((permissions) => (permissions === true ? permissions : permissions.update))
}).then((permissions) => permissions.update)
}
} catch (error) {
req.payload.logger.error(error)
Expand All @@ -84,7 +84,7 @@ export const getDocumentPermissions = async (args: {
_status: 'published',
},
},
}).then((permissions) => (permissions === true ? permissions : permissions.update))
}).then((permissions) => permissions.update)
}
} catch (error) {
req.payload.logger.error(error)
Expand Down
32 changes: 14 additions & 18 deletions packages/payload/src/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,14 @@ export type CollectionPermission = {
update: Permission
}

export type SanitizedCollectionPermission =
| {
create?: true
delete?: true
fields: SanitizedFieldsPermissions
read?: true
readVersions?: true
update?: true
}
| true
export type SanitizedCollectionPermission = {
create?: true
delete?: true
fields: SanitizedFieldsPermissions
read?: true
readVersions?: true
update?: true
}

export type GlobalPermission = {
fields: FieldsPermissions
Expand All @@ -89,14 +87,12 @@ export type GlobalPermission = {
update: Permission
}

export type SanitizedGlobalPermission =
| {
fields: SanitizedFieldsPermissions
read?: true
readVersions?: true
update?: true
}
| true
export type SanitizedGlobalPermission = {
fields: SanitizedFieldsPermissions
read?: true
readVersions?: true
update?: true
}

export type DocumentPermissions = CollectionPermission | GlobalPermission

Expand Down
2 changes: 0 additions & 2 deletions packages/payload/src/utilities/sanitizePermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ export function recursivelySanitizeCollections(obj: Permissions['collections']):
const [collectionSlug, collectionPermission] = entries[i]

if (areAllPermissionsTrue(collectionPermission)) {
;(obj[collectionSlug] as unknown as SanitizedCollectionPermission) = true
continue
}
}
Expand All @@ -197,7 +196,6 @@ export function recursivelySanitizeGlobals(obj: Permissions['globals']): void {
const [globalSlug, globalPermission] = entries[i]

if (areAllPermissionsTrue(globalPermission)) {
;(obj[globalSlug] as unknown as SanitizedGlobalPermission) = true
continue
}
}
Expand Down

0 comments on commit 260eb1c

Please sign in to comment.