RocReadaR : How to Work with Loopback Roles

Roles are used to grant users permission to do and see things in the system. In our implementation, a user can only be added to a single role. When testing, it may be useful to create users of different roles to see how different users would view the application.

Information of Note:

  • The "RoleMapping" model represents a foreign key relation, linking the id of a principal to the id of a role

Steps to Map a new User to a Role:

  1. Create a User
    1. Upon successful creation, the response should indicate the users id.
  2. Create / Find a Role
    1. Create
      1. Upon successful creation, the response should indicate the role id.
    2. Find
      1. List all the Roles (GET /Roles)
      2. Note the id of the role you will be assigning
  3. Map the user to the Role.
    1. Create the RoleMapping
      1. principalType is "USER" which is case-sensitive
      2. the principalId is the user id from step 1
      3. the roleId is the role id from step 2
  4. Success
    1. Response will show the provided information with an id for the mapping