2020-10-22 09:05:47 +00:00
|
|
|
from django.db.models import Q
|
|
|
|
|
|
|
|
from common.utils import get_logger
|
2020-10-22 10:13:14 +00:00
|
|
|
from perms.models import ApplicationPermission
|
2020-10-22 09:05:47 +00:00
|
|
|
|
|
|
|
logger = get_logger(__file__)
|
|
|
|
|
|
|
|
|
2021-03-08 02:08:51 +00:00
|
|
|
def get_application_system_user_ids(user, application):
|
2021-02-23 06:37:42 +00:00
|
|
|
queryset = ApplicationPermission.objects.valid()\
|
|
|
|
.filter(
|
|
|
|
Q(users=user) | Q(user_groups__users=user),
|
|
|
|
Q(applications=application)
|
|
|
|
).values_list('system_users', flat=True)
|
2020-10-22 09:05:47 +00:00
|
|
|
return queryset
|
2021-02-23 06:37:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
def has_application_system_permission(user, application, system_user):
|
2021-03-08 02:08:51 +00:00
|
|
|
system_user_ids = get_application_system_user_ids(user, application)
|
|
|
|
return system_user.id in system_user_ids
|