diff --git a/packages/core/content-manager/server/src/policies/__tests__/has-draft-and-publish.test.ts b/packages/core/content-manager/server/src/policies/__tests__/has-draft-and-publish.test.ts index 4f8b936c35..72027ea268 100644 --- a/packages/core/content-manager/server/src/policies/__tests__/has-draft-and-publish.test.ts +++ b/packages/core/content-manager/server/src/policies/__tests__/has-draft-and-publish.test.ts @@ -26,28 +26,28 @@ describe('hasDraftAndPublish policy', () => { }); test('It should succeed when the model has draft & publish enabled', () => { - const ctx = { params: { model: 'foo' } }; + const ctx = { params: { model: 'foo' } } as any; const res = hasDraftAndPublish(ctx, {}, { strapi: global.strapi }); expect(res).toBe(true); }); test(`It should fail when the model has draft & publish disabled`, () => { - const ctx = { params: { model: 'bar' } }; + const ctx = { params: { model: 'bar' } } as any; const res = hasDraftAndPublish(ctx, {}, { strapi: global.strapi }); expect(res).toBe(false); }); test(`It should fail when the model doesn't exists`, () => { - const ctx = { params: { model: 'foobar' } }; + const ctx = { params: { model: 'foobar' } } as any; const res = hasDraftAndPublish(ctx, {}, { strapi: global.strapi }); expect(res).toBe(false); }); test(`It should fail when params.model isn't provided`, () => { - const ctx = { params: {} }; + const ctx = { params: {} } as any; const res = hasDraftAndPublish(ctx, {}, { strapi: global.strapi }); expect(res).toBe(false); diff --git a/packages/core/content-manager/server/src/policies/has-draft-and-publish.ts b/packages/core/content-manager/server/src/policies/has-draft-and-publish.ts index 37afb02237..b022006e7d 100644 --- a/packages/core/content-manager/server/src/policies/has-draft-and-publish.ts +++ b/packages/core/content-manager/server/src/policies/has-draft-and-publish.ts @@ -1,9 +1,11 @@ +import type { Context } from 'koa'; import { contentTypes } from '@strapi/utils'; +import { Strapi, UID } from '@strapi/types'; const { hasDraftAndPublish } = contentTypes; -export default (ctx: any, config: any, { strapi }: any) => { - const { model: modelUID } = ctx.params; +export default (ctx: Context, config: any, { strapi }: { strapi: Strapi }) => { + const { model: modelUID }: { model: UID.ContentType } = ctx.params; const model = strapi.contentTypes[modelUID]; diff --git a/packages/core/content-manager/server/src/policies/hasPermissions.ts b/packages/core/content-manager/server/src/policies/hasPermissions.ts index 62d697466e..33841decef 100644 --- a/packages/core/content-manager/server/src/policies/hasPermissions.ts +++ b/packages/core/content-manager/server/src/policies/hasPermissions.ts @@ -1,3 +1,4 @@ +import type { Context } from 'koa'; import { policy } from '@strapi/utils'; import { validateHasPermissionsInput } from '../validation/policies/hasPermissions'; @@ -6,17 +7,16 @@ const { createPolicy } = policy; export default createPolicy({ name: 'plugin::content-manager.hasPermissions', validator: validateHasPermissionsInput, - handler(ctx, config = {}) { - const { actions = [], hasAtLeastOne = false } = config; + handler(ctx: Context, config = {}) { + const { actions = [], hasAtLeastOne = false }: { actions: string[]; hasAtLeastOne: boolean } = + config; - const { - state: { userAbility }, - params: { model }, - } = ctx; + const { userAbility } = ctx.state; + const { model }: { model: string } = ctx.params; const isAuthorized = hasAtLeastOne - ? actions.some((action: any) => userAbility.can(action, model)) - : actions.every((action: any) => userAbility.can(action, model)); + ? actions.some((action) => userAbility.can(action, model)) + : actions.every((action) => userAbility.can(action, model)); return isAuthorized; },