Skip to content

u12206050/directus-extension-role-chooser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Directus role chooser

Allow your users to have multiple roles and switch between them.

The idea is for every user you can assign which roles they can pick from. You would still need to set their initial role, and make sure that permissions will allow them to switch.

Setup

This module is only the graphical interface to allow users to switch their role.

In order for it to work you need to setup the following (read first then do):

Install extension

npm i directus-extension-role-chooser

Create required fields

  • On the directus_users collection create a m2m to directus_roles with the following setup
    junction: user_roles
    user: FK(directus_users, id)
    role: FK(directus_roles, id)
    
  • Check the Add M2M to "directes_roles" checkbox under Corresponding Field and enter has_role as the field name.

Setup required permissions

Add the following permissions to the specified collections for every role This is too allow users to actually view the roles they can choose from, and ensure a user can only update their role to one that they have been assigned.

  • - collection: user_roles
    - action: read
      fields: '*'
      permissions:
        has_role:
          user:
            _eq: $CURRENT_USER
    
  • - collection: directus_users
    - action: update
      fields:
        - role
      permissions:
        id:
          _eq: $CURRENT_USER
      validation:
        role:
          _in: $CURRENT_USER.roles.role
    
  • - collection: directus_roles
    - action: read
      fields: '*'
      permissions:
        has_role:
          user:
            _eq: $CURRENT_USER
    

After this you should now be able to add the roles to each user that you want them to be able to switch between.

About

Custom Directus module to support multiple roles and allow users to choose their active role

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors