0

I’m using strapi v4.20.0 . And i have a couple of collections in there . I have 2 roles 1 admin and moderator .

i don’t know if this is possible . but I want to assign a record in products collection to a moderator so he can have access to it .

i have set up a relation between products and users . product has many users .

in the RBAC I set that he can see and update if he is the creator … but I want to make him see the record and update it if he’s in relation with a product …

any idea how can this be done ? or is it even possible in strapi ?

1 Answer 1

2

Yes it's possible to achieve that. You will have to create a custom condition for that. Here is the documentation: https://docs.strapi.io/dev-docs/configurations/rbac

In my case, I created a many-way relation between Products and Admin Users. The key is "Shared_with" - so updated it accordingly to your needs.

Then, you will have to create the custom condition.

    await strapi.admin.services.permission.conditionProvider.register({
      displayName: 'Shared with',
      name: 'shared-with',
      plugin: 'admin',
      handler: async (user) => {
        return  {
          "Shared_with": {
            $elemMatch: {
              id: user.id
            }
          }
        }
      },
    });
  },

Once it's created, you will have to apply it to your Collection Type.

And voilà.

Here is a video to help you going though that: https://www.loom.com/share/2490ed5def6e46fb8adacabbc80f1d2d?sid=ec166e58-7536-4ee2-85fc-afee79614834

Hope it helps

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you Jim. is there any way I can change the entry title to use email instead of id? i tried changing it but had no luck still shows the id of the users .. its kinda of useless to use IDs I cant even see the IDs of admin users in the panel
I can see the id in the API response in SETTINGS / ADMINSITRATION PANEL / Users . but it's not displayed on table . is there a way to display it ?
Hello 👋 While testing it for the video, I spotted that issue too. Related to that one: github.com/strapi/strapi/issues/18072 I shared that with the team, will see when we are able to prio it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.