2020-10-30 02:29:47 +00:00
|
|
|
from django.db.models import Q
|
2020-10-22 09:05:47 +00:00
|
|
|
from perms.models import ApplicationPermission
|
|
|
|
from applications.models import Application
|
|
|
|
|
|
|
|
|
2021-03-08 02:08:51 +00:00
|
|
|
def get_user_all_applicationpermission_ids(user):
|
2020-10-30 02:29:47 +00:00
|
|
|
application_perm_ids = ApplicationPermission.objects.valid().filter(
|
|
|
|
Q(users=user) | Q(user_groups__users=user)
|
|
|
|
).distinct().values_list('id', flat=True)
|
2020-10-22 09:05:47 +00:00
|
|
|
return application_perm_ids
|
|
|
|
|
|
|
|
|
|
|
|
def get_user_granted_all_applications(user):
|
2021-03-08 02:08:51 +00:00
|
|
|
application_perm_ids = get_user_all_applicationpermission_ids(user)
|
2020-10-22 09:05:47 +00:00
|
|
|
applications = Application.objects.filter(
|
2021-03-08 02:08:51 +00:00
|
|
|
granted_by_permissions__id__in=application_perm_ids
|
2020-10-22 09:05:47 +00:00
|
|
|
).distinct()
|
|
|
|
return applications
|