mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 20:15:44 +00:00
Merge branch 'inventree:master' into matmair/issue2201
This commit is contained in:
@ -137,9 +137,10 @@ class RuleSet(models.Model):
|
||||
'sales_order': [
|
||||
'company_company',
|
||||
'order_salesorder',
|
||||
'order_salesorderallocation',
|
||||
'order_salesorderattachment',
|
||||
'order_salesorderlineitem',
|
||||
'order_salesorderallocation',
|
||||
'order_salesordershipment',
|
||||
]
|
||||
}
|
||||
|
||||
@ -503,6 +504,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')
|
||||
|
Reference in New Issue
Block a user