Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed models #60

Open
kwame101 opened this issue Apr 25, 2018 · 1 comment
Open

Embed models #60

kwame101 opened this issue Apr 25, 2018 · 1 comment

Comments

@kwame101
Copy link

kwame101 commented Apr 25, 2018

Detailed description

Hi, I want to make changes to this package or if its possible to do so without changes. Is it possible to have embedded models because we are using mongo db here we can eliminate having 2 collections to perform role / permission tasks. Example Role embeds many permissions etc..

Thanks for this package, I really like it

Context

In my use case, I want to embed permissions into a role and roles into a user. In a simple form we will have something like User > roles > permissions. If you help me on this I'll be very grateful because I've been struggling to get this to work.

This will limit the need of having 2 collections which could just be embed and still perform same task

Possible implementation

I haven't really digged into your package src yet but from my understanding it would be editing the model logic for permission model to be embedded into role model eg:

class Role{
  function permissions() {
    $this->embedsMany('Permission');
  }
}

In my use case, I want to embed Roles and Permissions into User model instead of it using have role_ids field e.g. if I was to fetch user assigned to one role I would get the following

name: "tester tester",
email: "test@test.com",
roles: {
   "name": "test",
    "permissions": {
                  "name": "test",
   }
}

I hope you can help me out here and if you don't understand anything i could explain further. Thanks

@mostafamaklad
Copy link
Owner

Thanks for your suggestion,
We will add this to next major version.
I think this will help to revoke permission from a user in a role like

name: "tester tester",
email: "test@test.com",
roles: {
   "name": "admin",
    "permissions": {
       "name": "create_articles",
       "name": "update_articles",
       "name": "delete_articles"
   }
},
"permissions": {
  "name": "create_users"
},
"revoked_permissions": {
  "name": "delete_articles"
}

So the test user has all admin rules but we revoked from him the delete_articles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants