diff --git a/plugins/catalog-backend/src/permissions/rules/createPropertyRule.ts b/plugins/catalog-backend/src/permissions/rules/createPropertyRule.ts index 5662b27d48..29ce67ad53 100644 --- a/plugins/catalog-backend/src/permissions/rules/createPropertyRule.ts +++ b/plugins/catalog-backend/src/permissions/rules/createPropertyRule.ts @@ -20,10 +20,7 @@ import { createCatalogPermissionRule } from './util'; import { z } from 'zod'; export const createPropertyRule = (propertyType: 'metadata' | 'spec') => - createCatalogPermissionRule<{ - key: string; - value?: string; - }>({ + createCatalogPermissionRule({ name: `HAS_${propertyType.toUpperCase()}`, description: `Allow entities which have the specified ${propertyType} subfield.`, resourceType: RESOURCE_TYPE_CATALOG_ENTITY, diff --git a/plugins/catalog-backend/src/permissions/rules/hasAnnotation.ts b/plugins/catalog-backend/src/permissions/rules/hasAnnotation.ts index 0d80977c09..c8450f3d08 100644 --- a/plugins/catalog-backend/src/permissions/rules/hasAnnotation.ts +++ b/plugins/catalog-backend/src/permissions/rules/hasAnnotation.ts @@ -26,10 +26,7 @@ import { createCatalogPermissionRule } from './util'; * * @alpha */ -export const hasAnnotation = createCatalogPermissionRule<{ - annotation: string; - value?: string; -}>({ +export const hasAnnotation = createCatalogPermissionRule({ name: 'HAS_ANNOTATION', description: 'Allow entities which are annotated with the specified annotation', diff --git a/plugins/permission-node/src/types.ts b/plugins/permission-node/src/types.ts index e69c1f3d78..6d39d7f922 100644 --- a/plugins/permission-node/src/types.ts +++ b/plugins/permission-node/src/types.ts @@ -46,6 +46,15 @@ export type PermissionRule< TQuery, TResourceType extends string, TParams extends Record = Record, + TSchema extends z.ZodType = z.ZodObject<{ + // Parameters can be optional, however we we want to make sure that the + // parameters are always present in the schema, even if they are undefined. + // We remove the optional flag from the schema, and then add it back in + // with an optional zod type. + [P in keyof TParams]-?: TParams[P] extends undefined + ? z.ZodOptionalType> + : z.ZodType; + }>, > = { name: string; description: string; @@ -54,27 +63,19 @@ export type PermissionRule< /** * A ZodSchema that documents the parameters that this rule accepts. */ - schema: z.ZodObject<{ - // Parameters can be optional, however we we want to make sure that the - // parameters are always present in the schema, even if they are undefined. - // We remove the optional flag from the schema, and then add it back in - // with an optional zod type. - [P in keyof TParams]-?: TParams[P] extends undefined - ? z.ZodOptionalType> - : z.ZodType; - }>; + schema: TSchema; /** * Apply this rule to a resource already loaded from a backing data source. The params are * arguments supplied for the rule; for example, a rule could be `isOwner` with entityRefs as the * params. */ - apply(resource: TResource, params: NoInfer): boolean; + apply(resource: TResource, params: NoInfer>): boolean; /** * Translate this rule to criteria suitable for use in querying a backing data store. The criteria * can be used for loading a collection of resources efficiently with conditional criteria already * applied. */ - toQuery(params: NoInfer): PermissionCriteria; + toQuery(params: NoInfer>): PermissionCriteria; }; diff --git a/plugins/playlist-backend/src/permissions/rules.ts b/plugins/playlist-backend/src/permissions/rules.ts index 79214b050d..bebb7905b4 100644 --- a/plugins/playlist-backend/src/permissions/rules.ts +++ b/plugins/playlist-backend/src/permissions/rules.ts @@ -29,9 +29,7 @@ const createPlaylistPermissionRule = makeCreatePermissionRule< typeof PLAYLIST_LIST_RESOURCE_TYPE >(); -const isOwner = createPlaylistPermissionRule<{ - owners: string[]; -}>({ +const isOwner = createPlaylistPermissionRule({ name: 'IS_OWNER', description: 'Should allow only if the playlist belongs to the user', resourceType: PLAYLIST_LIST_RESOURCE_TYPE,