-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Permissions / ACL #113
Permissions / ACL #113
Conversation
- Created Role model - Created Permission model - Linked Users->Roles with a belongsToMany relationship - Linked Permissions to Users and Roles with a belongsToMany relationship - Created permissions helper with functions for initializing and checking permissions (canThis) - Unit tests for lots of things
This is looking awesome, I've only taken a super quick glance, but a couple of points / questions: What made you opt to implement your own? Last time we talked you mentioned using enrolement I think... not that there is a problem with rolling our own, but I am very interested to hear what the story / learning was? The permissions.canThis(userModelOrId).edit.post() syntax is awesome. I think I understand that we can also do permissions.canThis(userModelOrId).edit.post(posModelOrId)? If so, how can we determine which users can edit which posts? This would usually be by the concept of ownership on the model, but not always. There's obviously no opposite nice syntax for creating permissions (completely understandably, not even sure that would be useful), but at first glance I didn't see a way to do this. |
The I rolled my own because, well, I got a little obsessed with the Object.defineProperty thing to build that dynamic chain of actions to objects. But, really I started looking at the entitlement code and it was really tiny so I kind of based this on it. You're right about this only being a useful api for checking permissions one way, but I could come up with a different set of helpers for granting permissions and listing them for maybe an admin page. Do we have any mockups for those kind of pages yet? We always have the raw models as well for attaching things because of the relations, there's an example in the permissions_spec test. |
This means that we will require an individual row in the permissions table for each item a person has access to? I'm thinking specifically of authors who can only edit the posts they authored. I imagined having a concept of ownership, but then I guess that requires the ACL to be more tightly tied to the models. |
Have manually merged this. |
refs TryGhost/Members#105 - It's a follow up to a series of refactorings in the module mostly discussed in refed PR - The sendEmailWithMagicLink and destroyStripeSubscriptions were exposed through members API so that Ghost could call it from the controller level
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Initial implementation of #29
checking permissions (canThis)
I think the
canThis(...)
stuff is probably the most complicated so here is a quick run down.permissions.init()
which will build the "actionsMap" that theCanThisResult
code uses to fill out the properties likeedit.post()
. TheGhost.init()
should be modified to also callpermissions.init()
. Any time permissions are updated/modified, we should callpermissions.refresh()
; I think we can do this with a global saving handler on the Permission model, but I'm not sure.require('./core/shared/permissions')
permissions.canThis(userModelOrId).edit.post()
returns a promise that will resolve or reject based on whether the user can do the action.canThis(...)
call is loading the users "effectivePermissions" meaning all the users permissions and any roles it has' permissions.