2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 04:55:44 +00:00

[BUG] Fix ownership (#4244)

* Reenable ownership tests

* [BUG] Stock item ownership results in stock item being read-only
Fixes #4229

* rebuild ownership tests

* jsut test stock stuff for now

* move ownership check to Owner

* fix assertation with lazy objects

* test all of stock

* Add edit checks

* remove old tests

* run full coverage again

* fix test
This commit is contained in:
Matthias Mair
2023-01-24 23:28:36 +01:00
committed by GitHub
parent e730b5c24c
commit 1960e662a7
3 changed files with 78 additions and 108 deletions

View File

@ -639,9 +639,9 @@ class Owner(models.Model):
ContentType.objects.get_for_model(user_model).id]
# If instance type is obvious: set content type
if type(user_or_group) is Group:
if isinstance(user_or_group, Group):
content_type_id = content_type_id_list[0]
elif type(user_or_group) is get_user_model():
elif isinstance(user_or_group, get_user_model()):
content_type_id = content_type_id_list[1]
if content_type_id:
@ -678,6 +678,12 @@ class Owner(models.Model):
return related_owners
def is_user_allowed(self, user, include_group: bool = False):
"""Check if user is allowed to access something owned by this owner."""
user_owner = Owner.get_owner(user)
return user_owner in self.get_related_owners(include_group=include_group)
@receiver(post_save, sender=Group, dispatch_uid='create_owner')
@receiver(post_save, sender=get_user_model(), dispatch_uid='create_owner')