[BUG] :checkered_flag: Stock item ownership results in stock item being read-only

This issue has been tracked since 2023-01-18.

Please verify that this bug has NOT been raised before.

  • I checked and didn't find similar issue

Describe the bug*

This is a followup for #4228.

When a user is a member of more than one group, stock items owned by one of these groups are read-only despite the group having VACD rights on stock items.

Steps to Reproduce

  1. Create two groups with VACD rights on stock items.
  2. Add a normal (non-admin) user account to both groups.
  3. Have a stock item being owned by one of these groups.
  4. Notice how the stock item is read-only when logged in as said user.

UPDATE 2022-01-20

After further investigation it seems stock item ownership is broken in general. Even when the stock item is owned by the current user it appears read-only.

Expected behavior

The stock item is modifiable by the user.

Deployment Method

  • Docker
  • Bare metal

Version Information

Version Information:

InvenTree-Version: 0.10.0 dev
Django Version: 3.2.16
Commit Hash: 28ec6b9
Commit Date: 2022-12-25
Database: postgresql
Debug-Mode: False
Deployed using Docker: False
Active plugins: [{'name': 'InvenTreeBarcode', 'slug': 'inventreebarcode', 'version': '2.0.0'}]

eeintech wrote this answer on 2023-01-23

@sur5r I actually think you don't even need to belong to two groups for this bug to happen, when I reproduced it my user belonged to one group only but my user did not have write access to stock items owned by his own group...

matmair wrote this answer on 2023-01-23

Can reproduce. @sur5r thanks for reporting it.

In general:
Fixing this should solely focus on getting documented behaviour up and running again. Permissions are due for a rework as described in #2323. That is a more significant conceptual change that should be discussed on a process level before changing the core mechanism.

eeintech wrote this answer on 2023-01-23

@matmair Why wait 0.10.0? This should go into 0.9.x for bug fixing, no?

matmair wrote this answer on 2023-01-23

My understanding is that we are rolling 0.10.0 once Oliver is back so I tagged it for 0.10.0 - we can change it to 0.9.x but I do not think it will change anything

sur5r wrote this answer on 2023-01-23

I just noticed I even get "read only" on stock items owned by my user directly. Something must be completely off here.

eeintech wrote this answer on 2023-01-23

I just noticed I even get "read only" on stock items owned by my user directly. Something must be completely off here.

I guess that part was broken at some point... mind updating the title and comment of this issue to reflect your findings?

sur5r wrote this answer on 2023-01-23

I just bisected on the stable branch and found 9841f47 to be the first bad commit.

matmair wrote this answer on 2023-01-23

Great pointer. Do you want to work on this or should I try to fix it?

sur5r wrote this answer on 2023-01-23

As I haven't really looked into how the permission system works yet I think it's best if you do it.

matmair wrote this answer on 2023-01-23

Ok, I finally found the error and I am amazed we did not notice this earlier. All owner checks are returning false if you are not a superuser.

And it is kind of obvious once you discover it. We are comparing user objects with owner objects. That can only be false. Seems like most users (I too) deploy a lot of users as superusers.

return user in owner.get_related_owners(include_group=True)
matmair wrote this answer on 2023-01-23

@sur5r there is a fix in #4244 - it would be great if you could test that.
I think the current behaviour is kind of unintuitive - that should probably be addressed in #2323

sur5r wrote this answer on 2023-01-23

It seems to work partially. Group membership for ownership works, but the permission bits are not respected at all. If I remove the ACD permissions for Stock Items and Stock Locations from the group, my user can still perform stock take actions. But maybe this is part of #2323. While it doesn't seem like a complete fix, it works for my use case.

matmair wrote this answer on 2023-01-23

@sur5r is your user a superuser or has ACD permissions for stock? Both should allow users to edit (at least that was the case in the original implementation).

sur5r wrote this answer on 2023-01-24

My user is a regular user. The superuser could always perform any actions. Am I missing something regarding user permissions? I can only set permission bits for groups.

matmair wrote this answer on 2023-01-24

@sur5r you can also set permissions for users but that is a bit hidden. I will look into it again

sur5r wrote this answer on 2023-01-24

Where is that? I didn't find anything in Django Admin.

matmair wrote this answer on 2023-01-24

@sur5r not in the admin interface, you can still set them on the objects themselves (via debugging, plugins, etc).

sur5r wrote this answer on 2023-01-24

Ok, I'm pretty sure I didn't do that. But for completeness' sake: How can I inspect them? I tried this:

>>> um=InvenTree.models.User
>>> u=um.objects.get(username='jh')
>>> u.get_user_permissions()
set()
>>>
More Details About Repo
Owner Name inventree
Repo Name InvenTree
Full Name inventree/InvenTree
Language Python
Created Date 2017-03-23
Updated Date 2023-03-31
Star Count 2586
Watcher Count 61
Fork Count 411
Issue Count 141

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date