|
|
|
@ -12,6 +12,7 @@ from django.contrib.auth.hashers import check_password
|
|
|
|
|
from django.contrib.auth.models import AbstractUser |
|
|
|
|
from django.core.cache import cache |
|
|
|
|
from django.db import models |
|
|
|
|
from django.db.models import Count |
|
|
|
|
from django.shortcuts import reverse |
|
|
|
|
from django.utils import timezone |
|
|
|
|
from django.utils.module_loading import import_string |
|
|
|
@ -708,29 +709,29 @@ class MFAMixin:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class JSONFilterMixin: |
|
|
|
|
""" |
|
|
|
|
users = JSONManyToManyField('users.User', blank=True, null=True) |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
def get_json_filter_attr_q(name, value, match): |
|
|
|
|
from rbac.models import RoleBinding |
|
|
|
|
from orgs.utils import current_org |
|
|
|
|
|
|
|
|
|
kwargs = {} |
|
|
|
|
if name == 'system_roles': |
|
|
|
|
user_id = RoleBinding.objects \ |
|
|
|
|
.filter(role__in=value, scope='system') \ |
|
|
|
|
.values_list('user_id', flat=True) |
|
|
|
|
return models.Q(id__in=user_id) |
|
|
|
|
kwargs['scope'] = 'system' |
|
|
|
|
elif name == 'org_roles': |
|
|
|
|
kwargs = dict(role__in=value, scope='org') |
|
|
|
|
kwargs['scope'] = 'org' |
|
|
|
|
if not current_org.is_root(): |
|
|
|
|
kwargs['org_id'] = current_org.id |
|
|
|
|
else: |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
bindings = RoleBinding.objects.filter(**kwargs, role__in=value) |
|
|
|
|
if match == 'm2m_all': |
|
|
|
|
user_id = bindings.values('user_id').annotate(count=Count('user_id')) \ |
|
|
|
|
.filter(count=len(value)).values_list('user_id', flat=True) |
|
|
|
|
else: |
|
|
|
|
user_id = bindings.values_list('user_id', flat=True) |
|
|
|
|
|
|
|
|
|
user_id = RoleBinding.objects.filter(**kwargs) \ |
|
|
|
|
.values_list('user_id', flat=True) |
|
|
|
|
return models.Q(id__in=user_id) |
|
|
|
|
return None |
|
|
|
|
return models.Q(id__in=user_id) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class User(AuthMixin, TokenMixin, RoleMixin, MFAMixin, JSONFilterMixin, AbstractUser): |
|
|
|
|