Giter Site home page Giter Site logo

marciobarrientos / directus-extension-role-chooser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from u12206050/directus-extension-role-chooser

0.0 0.0 0.0 488 KB

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

License: MIT License

TypeScript 18.64% Vue 81.36%

directus-extension-role-chooser's Introduction

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):

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

  • - 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.

directus-extension-role-chooser's People

Contributors

u12206050 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.