2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-16 20:15:44 +00:00

Merge branch 'inventree:master' into matmair/issue2279

This commit is contained in:
Matthias Mair
2021-12-04 17:52:58 +01:00
committed by GitHub
82 changed files with 23406 additions and 16264 deletions

View File

@ -134,9 +134,10 @@ class RuleSet(models.Model):
'sales_order': [
'company_company',
'order_salesorder',
'order_salesorderallocation',
'order_salesorderattachment',
'order_salesorderlineitem',
'order_salesorderallocation',
'order_salesordershipment',
]
}
@ -477,6 +478,34 @@ class Owner(models.Model):
owner: Returns the Group or User instance combining the owner_type and owner_id fields
"""
@classmethod
def get_owners_matching_user(cls, user):
"""
Return all "owner" objects matching the provided user:
A) An exact match for the user
B) Any groups that the user is a part of
"""
user_type = ContentType.objects.get(app_label='auth', model='user')
group_type = ContentType.objects.get(app_label='auth', model='group')
owners = []
try:
owners.append(cls.objects.get(owner_id=user.pk, owner_type=user_type))
except:
pass
for group in user.groups.all():
try:
owner = cls.objects.get(owner_id=group.pk, owner_type=group_type)
owners.append(owner)
except:
pass
return owners
@staticmethod
def get_api_url():
return reverse('api-owner-list')