Skip to content

[v4] Filters in findOne controller doesn't work #12208

@abdonrd

Description

@abdonrd

Bug report

Describe the bug

Filters in findOne controller doesn't work.

Steps to reproduce the behavior

  1. Create a controller like this:
async findOne(ctx) {
  // Filter by the current user as the author
  ctx.query = {
    ...ctx.query,
    filters: {
      author: {
        id: ctx.state.user.id
      }
    },
  };

  const response = await super.findOne(ctx);

  return response;
},
  1. Run the REST GET /content-type/:id
  2. It shows the entry, even if the user is not the author

Expected behavior

The custom filter working

System

  • Node.js version: v14
  • NPM version: v8
  • Strapi version: v4.0.4
  • Database: SQLite
  • Operating system: macOS

Additional context

Debugging a bit...

After this:

findOne(entityId, params = {}) {
return strapi.entityService.findOne(uid, entityId, this.getFetchParams(params));
},

I see that this line removes the custom params:

const query = transformParamsToQuery(uid, pickSelectionParams(wrappedParams));

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: enhancementIssue suggesting an enhancement to an existing featuresource: core:strapiSource is core/strapi package

    Type

    No type

    Projects

    Status

    Archive

    Status

    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions