Repository navigation
Conversation
|
Interesting approach, I hadn't heard of these plugins before. I do not have enough time to look at this right now but I would like to soon. |
|
@Zeigren are you able to fix the conflicts with master here so I can have a look at what you've done? Cheers |
|
Yep can do! |
|
It's been a minute since I've worked on it but I want to say object permissions can only be assigned in the admin panel currently. I think permission checks work for most of the UI and in views. It's worth checking out DjangoObjectPermissions for the rest framework as well. |
|
Still lots to do but I've made some minor changes/fixes. Most of the tables should actually be filtered now. I've been trying to figure out the "best" way to actually assign the permissions since there's a number of ways to do it and I'd like to keep it simple. One way would be to handle it in the view or it could be done inside a signal. To Do:
|
|
Hey @Zeigren I'm trying to assess what is going on here - but as i haven't used the "permissions" system in django before I'm a little lost. I've pulled your branch, but the default (non-staff) account can still perform every available action. I had assumed that most actions would be prevented by default? Is there something I am missing here? Cheers |
|
That would make sense, the per object permissions weren't being assigned so it should have defaulted to checking the regular Django model permissions. This commit adds in a very simple automatic object permissions assignment that should be a better representation. I've added a bunch of post_save signals to If you want to test the anonymous user add If it still isn't working correctly for normal users try changing |
|
@Zeigren This draft is little out of date now, any chance you can bring it up-to-date? I'm interested to have a look, this could be handy for our company too. |
|
@Zeigren I would also be quite keen to see this updated to the latest InvenTree codebase. I would like to start looking seriously to integrate a permissions architecture. And your approach looks very sensible. Do you have the time to look at fixing the conflicts? |
|
@SchrodingersGat For the permission architecture, I would like to introduce fine control at the Part, Stock, Build, etc. level to decide which role and users have write access on those. So that for instance, EEs should have full control over Parts/Build/Stock, PMs on Stock/Sales/Purchase orders, manufacturing people on Stock/Build, etc. Does that make sense? I think this implementation is slowly becoming higher priority at our company so I'm happy to take a look and send out a proposal, what's your take on this? |
|
@eeintech I agree completely with your approach - this is how I want to use it at my company also. Fine-grained control is great, then the admin user can create their own groups which contain the correct permissions. For example you could have a group that can view part pages but not edit them. |
|
Started to work on the framework for this here - #1010 |
|
@SchrodingersGat Great, I did some reading too and am going to start implementing the group/roles in the admin interface so that we can add, edit, remove roles and have "fine" control what role has write access to Parts, Stocks, Build, Companies, etc. Then we can have a one-to-one user to role relationship and the user's role would drive the write access to InvenTree. I'm thinking to bring django-role-permissions to the mix, but I wonder how it handles dynamically created roles, maybe building on top of the Django Authentication System would be better. |
|
The django-role-permissions integration looks really nice, I like the idea of "roles" rather than "groups". Advantages
Disadvantages
|
|
@SchrodingersGat I agree that InvenTree should support dynamic role management in the admin interface and not at the |
|
I was not very familiar with the Django users and permissions system but here are my today's findings (mostly notes for myself but feel free to comment/react). Django Authentication SystemWhen I started to look into it, I discovered that Conclusion: we definitely need a role-based system! django-role-permissionsI was not able to figure out how to define will create a new Conclusion: we need to extend the User model to define custom roles. Extending User Model with One-to-One relationshipI started naively looking into the Django docs and the implementation from this section. I started "playing" with one-to-one user-to-role relationships but when I added a model called Conclusion: we need a custom User model to define roles. Custom User Model using AbstractUserMy last attempt of the day which quickly concluded when I saw how many errors pointing to a new Conclusion: Adding a Custom User model pushes for a new database structure, I'm not sure to which extent... |
|
I actually think the fine-grained controls of the existing user / group permissions are what we want here. Any higher-level permission roles that we decide to create here might not match a particular use case. For example, let's say we create a role "engineer" which can edit parts etc but cannot edit or create sales orders (or see sales pricing). This role might work for your company but not someone else's? I would suggest that we allow very fine-grained control of the permissions, as this allows the system to be quite flexible. What I would also suggest is that we create a set of "default" or "example" groups, which have a set of model permissions that make general sense. Then end-users can edit these groups, or duplicate them, to match their particular requirements. But the available groups would be pretty generic and cover most use cases... |
|
@SchrodingersGat I had this brief moment of thinking InvenTree could have "template groups", I guess this is what you had in mind. Maybe this is me being over-the-top here, I envisioned some easy to customize table that will be defined for each role. Each check will add/remove group of permissions for related objects. And this is without knowing what It's possible the django-guardian library can help with this implementation (eg. grouping view/add/change/delete of multiple objects and to add/remove group of permissions with each checkmark). If some users wants more "fine-control", in this case they would have to edit the Django Groups manually. Is that too much you think? |
|
If we can make a simplified table like you mocked up, with names like "build" rather than actual table names, I'm all for it. Each column represents a "proxy" for a set of permissions. If an admin wants a more fine-grained control of the groups then that is possible too! Not sure how to: a) Create the "table" view in the admin interface (or maybe we put it in the "settings" tab rather than the admin interface?) |
I'm thinking it would be inherent to InvenTree so maybe in the "settings" tab would make more sense (reserved only for superusers and staff). I will investigate both to see what makes more sense and is more convenient.
I will take a look as well. I am hoping to get something as simple as (or similar) |
Already you can use the following code in templates: |
Yes you're right, my example was a little silly... I was trying to show a "user role-based" check vs "model-based" check. Now I realize I'm still uncovering ground at this point, I may be leading myself in wrong directions... I'll do some more research and reading! |
|
My thoughts depicted above are put into action through the draft PR #1016 |




In order to allow anonymous viewing (see #596), I've been implementing a permissions system using django-guardian, which handles per object permissions and has a built-in AnonymousUser (that can be assigned permissions).
It's a WIP but here's what I have so far and my plans.
Done:
In Progress:
Planned: