RBAC custom condition with relation in V4

Leave this here for everyone who has a similar problem:

The RBAC API is considered unstable for now, see: Role-Based Access Control (RBAC) - Strapi Developer Docs.
I missed this the last time I’ve read the docs and it indicates there are changes coming!

My solution:
Changing the handler to be a function. It was at simple as that.

In my example:

const conditions = [
  {
    displayName: "Filter-Company-A",
    name: "filter-company-a",
    handler: {
      "Company.Name": { $eq: "CompanyA" },
    },
  },
];

becomes

const conditions = [
  {
    displayName: "Filter-Company-A",
    name: "filter-company-a",
    handler() {
          return { "Company.Name": { $eq: "CompanyA" } };
        },
  },
];

In my tests the handler property has to be a function no matter what value the query aims for (nested or not nested). This surely will be fixed in an upcoming release. Gonna have a look into that making an PR for the docs later if there isn’t already one.

1 Like