documentation icon indicating copy to clipboard operation
documentation copied to clipboard

Instructions on creating a middleware mention read but it probably should be find

Open ri5h opened this issue 1 year ago • 0 comments
trafficstars

Link to the documentation page or resource

https://docs.strapi.io/dev-docs/backend-customization/middlewares#restricting-content-access-with-an-is-owner-policy

Describe the bug

In step 7 of documentation link above, under title: Restricting content access with an "is-owner policy", the steps to ensuring the methods to which middleware should apply is probably wrong.

After failing to see a log after adding a method read, I went to typescript types and tried find which worked.

I added some additional context and suggested fixes. let me know if you need further information.

ps. I am probably using @strapi/[email protected]

Additional context

The route config I used to find this information was in node modules. I tried finding it in github but I don't think I can find a generated type in the monorepo, only relevant file was in a commit which may have been moved/renamed/etc. https://github.com/strapi/strapi/blob/9c79921d22142a5de77ea26151550a14e4b12669/packages/core/types/src/types/core-api/router.ts#L29

Below is how it looks in my node modules.

export interface SingleTypeRouterConfig extends Generic {
  find?: HandlerConfig;
  update?: HandlerConfig;
  delete?: HandlerConfig;
}

export interface CollectionTypeRouterConfig extends Generic {
  find?: HandlerConfig;
  findOne?: HandlerConfig;
  create?: HandlerConfig;
  update?: HandlerConfig;
  delete?: HandlerConfig;
}

Suggested improvements or fixes

Either there was a change in another version which I am not using, maybe later versions use read instead of find, in which case, I am not sure how this could be solved, maybe a version switcher (example: https://laravel.com/docs/11.x/readme) at top is too big of a topic.

If not, just updating it should solve the issue I faced.

Related issue(s)/PR(s)

No response

ri5h avatar May 05 '24 17:05 ri5h

@JensAstrup I'm not able to reproduce this with the following:

  • oclif generate gh-1060 --yes
  • copy example into src/commands/hello/index.ts
  • bin/dev.js --name oclif

Is there anything I'm missing? Also you can get additional logs if you set the DEBUG=* in your environment

mdonnalley avatar Apr 19 '24 17:04 mdonnalley

Nope, not missing anything 🤔 I used DEBUG, just felt wanting of more detail. Here's what I have using oclif/4.5.0 darwin-arm64 node-v21.7.1

Apologies if this is just me, my copy/paste job made it seem like an oclif issue - now I've got that sneaking feeling that I've overlooked something minor that'll have me 🤦

] +6ms
  config:espresso (import) /Users/jens/projects/espresso/src/commands/github/pending-review.ts +2s
Warning: Error
    at Plugin.warn (/Users/jens/projects/espresso/node_modules/@oclif/core/lib/config/plugin.js:372:17)
    at /Users/jens/projects/espresso/node_modules/@oclif/core/lib/config/plugin.js:276:30
    at async Promise.all (index 4)
    at async Plugin._manifest (/Users/jens/projects/espresso/node_modules/@oclif/core/lib/config/plugin.js:257:24)
    at async Plugin.load (/Users/jens/projects/espresso/node_modules/@oclif/core/lib/config/plugin.js:208:25)
    at async PluginLoader.loadRoot (/Users/jens/projects/espresso/node_modules/@oclif/core/lib/config/plugin-loader.js:67:13)
    at async Config.load (/Users/jens/projects/espresso/node_modules/@oclif/core/lib/config/config.js:267:27)
    at async Function.load (/Users/jens/projects/espresso/node_modules/@oclif/core/lib/config/config.js:157:9)
    at async run (/Users/jens/projects/espresso/node_modules/@oclif/core/lib/main.js:59:20)
    at async file:///Users/jens/projects/espresso/bin/dev.js:5:1
module: @oclif/[email protected]
task: findCommand (hello:hello)
plugin: espresso
root: /Users/jens/projects/espresso
See more details with DEBUG=*
Warning: Error
    at Plugin.warn (/Users/jens/projects/espresso/node_modules/@oclif/core/lib/config/plugin.js:372:17)
    at /Users/jens/projects/espresso/node_modules/@oclif/core/lib/config/plugin.js:276:30
    at async Promise.all (index 4)
    at async Plugin._manifest (/Users/jens/projects/espresso/node_modules/@oclif/core/lib/config/plugin.js:257:24)
    at async Plugin.load (/Users/jens/projects/espresso/node_modules/@oclif/core/lib/config/plugin.js:208:25)
    at async PluginLoader.loadRoot (/Users/jens/projects/espresso/node_modules/@oclif/core/lib/config/plugin-loader.js:67:13)
    at async Config.load (/Users/jens/projects/espresso/node_modules/@oclif/core/lib/config/config.js:267:27)
    at async Function.load (/Users/jens/projects/espresso/node_modules/@oclif/core/lib/config/config.js:157:9)
    at async run (/Users/jens/projects/espresso/node_modules/@oclif/core/lib/main.js:59:20)
    at async file:///Users/jens/projects/espresso/bin/dev.js:5:1
module: @oclif/[email protected]
task: findCommand (hello:hello)
plugin: espresso
root: /Users/jens/projects/espresso
See more details with DEBUG=*
  config:espresso (import) /Users/jens/projects/espresso/src/commands/shortcut/at-risk.ts +132ms
  config:espresso (import) /Users/jens/projects/espresso/src/commands/shortcut/missing-points.ts +0ms
  config:espresso (import) /Users/jens/projects/espresso/src/commands/shortcut/stalled-in-dev.ts +0ms

JensAstrup avatar Apr 19 '24 19:04 JensAstrup

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar May 20 '24 02:05 github-actions[bot]