mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Reduce repeat queries, streamline the check_permissions function
This commit is contained in:
@@ -38,8 +38,9 @@ def check_permissions(user, application=None):
|
|||||||
""" Check if the user has permissions to view or admin the application """
|
""" Check if the user has permissions to view or admin the application """
|
||||||
|
|
||||||
hrgroup, created = Group.objects.get_or_create(name=settings.HR_STAFF_GROUP)
|
hrgroup, created = Group.objects.get_or_create(name=settings.HR_STAFF_GROUP)
|
||||||
|
corplist = EVEPlayerCharacter.objects.filter(eveaccount__user=user,corporation__applications=True)
|
||||||
if not application:
|
if not application:
|
||||||
if hrgroup in user.groups.all() or user.is_superuser:
|
if hrgroup in user.groups.all() or user.is_superuser or corplist.filter(director=True).count():
|
||||||
return HR_ADMIN
|
return HR_ADMIN
|
||||||
else:
|
else:
|
||||||
if user.is_superuser:
|
if user.is_superuser:
|
||||||
@@ -48,13 +49,11 @@ def check_permissions(user, application=None):
|
|||||||
return HR_VIEWONLY
|
return HR_VIEWONLY
|
||||||
else:
|
else:
|
||||||
# Give admin access to directors of the corp
|
# Give admin access to directors of the corp
|
||||||
corplist = EVEPlayerCharacter.objects.filter(director=True,eveaccount__user=user).values_list('corporation__id', flat=True)
|
if application.corporation.id in corplist.filter(director=True).values_list('corporation__id', flat=True):
|
||||||
if application.corporation.id in corplist:
|
|
||||||
return HR_ADMIN
|
return HR_ADMIN
|
||||||
|
|
||||||
# Give access to none director HR people access
|
# Give access to none director HR people access
|
||||||
corplist = EVEPlayerCharacter.objects.filter(eveaccount__user=user).values_list('corporation__id', flat=True)
|
if application.corporation.id in corplist.values_list('corporation__id', flat=True) and hrgroup in user.groups.all():
|
||||||
if application.corporation.id in corplist and hrgroup in user.groups.all():
|
|
||||||
return HR_ADMIN
|
return HR_ADMIN
|
||||||
|
|
||||||
return HR_NONE
|
return HR_NONE
|
||||||
|
|||||||
Reference in New Issue
Block a user