jedireza / frame

:bulb: A user system API starter
https://jedireza.github.io/frame/
MIT License
740 stars 157 forks source link

Custom roles #138

Closed dmitrypo closed 8 years ago

dmitrypo commented 8 years ago

Hello, Looks like my understanding how to use frame is not right way. I read your note Roles about and it's still not clear in my mind Users, Roles & Groups. How can I create my custom role and assign it to user so that I can get response like below:

...
  "user": {
    "_id": "57c8b5bcbcb2ab001e238e6d",
    "username": "Bob",
    "email": "bobemail@domain.com",
    "roles": {
      "account": {
        "id": "57c8b5bcbcb2ab001e238e6e",
        "name": "bob ..."
      },
      "admin": {
        "id": "99c8b5bcbcb2ab001e238e6e",
        "name": "..."
      },
      "support": {
        "id": "12c8b5bcbcb2ab001e238e6e",
        "name": "..."
      }
    }
  }
...

In results Bob has three roles. Could you please give me some details about the I should use. Through API or custom code?

Could you please advise me?

Thanks, Dmitry

jedireza commented 8 years ago

Here are the link (PUT) and unlink (DELETE) endpoints defined for accounts. https://github.com/jedireza/frame/blob/984e5a8ac72d163a0dfc404f392b447878827d24/server/api/accounts.js#L228-L421

And here are the link (PUT) and unlink (DELETE) endpoints defined for admins. https://github.com/jedireza/frame/blob/984e5a8ac72d163a0dfc404f392b447878827d24/server/api/admins.js#L243-L442

You'll need to define these for your custom role too. The example role you showed support sounds more like it would be better defined as a group. I suggest reading these sections again:

You'll also need to extend the User model schema with your new role: https://github.com/jedireza/frame/blob/984e5a8ac72d163a0dfc404f392b447878827d24/server/models/user.js#L81-L90