Ejemplo n.º 1
0
 def validate_user(user):
     if user not in current_org.get_members():
         error = _('The user `{}` is not in the current organization: `{}`').format(
             user, current_org
         )
         raise serializers.ValidationError(error)
     return user
Ejemplo n.º 2
0
 def dates_total_count_inactive_users(self):
     total = current_org.get_members().count()
     active = self.dates_total_count_active_users
     count = total - active
     if count < 0:
         count = 0
     return count
Ejemplo n.º 3
0
 def perform_bulk_update(self, serializer):
     user_ids = [
         d.get("id") or d.get("pk") for d in serializer.validated_data
     ]
     users = current_org.get_members().filter(id__in=user_ids)
     for user in users:
         self.check_object_permissions(self.request, user)
     return super().perform_bulk_update(serializer)
Ejemplo n.º 4
0
 def get_org_users(cls, org=None):
     queryset = cls.objects.all()
     if org is None:
         org = current_org
     if not org.is_root():
         queryset = current_org.get_members()
     queryset = cls.filter_not_service_account(queryset)
     return queryset
Ejemplo n.º 5
0
    def filter_queryset(self, request, queryset, view):
        org_role = request.query_params.get('org_role')
        if not org_role:
            return queryset

        if org_role == 'admins':
            return queryset & (current_org.admins
                               | User.objects.filter(role=User.ROLE.ADMIN))
        elif org_role == 'auditors':
            return queryset & current_org.auditors
        elif org_role == 'users':
            return queryset & current_org.users
        elif org_role == 'members':
            return queryset & current_org.get_members()
Ejemplo n.º 6
0
 def get_login_logs(cls, date_from=None, date_to=None, user=None, keyword=None):
     login_logs = cls.objects.all()
     if date_from and date_to:
         date_from = "{} {}".format(date_from, '00:00:00')
         date_to = "{} {}".format(date_to, '23:59:59')
         login_logs = login_logs.filter(
             datetime__gte=date_from, datetime__lte=date_to
         )
     if user:
         login_logs = login_logs.filter(username=user)
     if keyword:
         login_logs = login_logs.filter(
             Q(ip__contains=keyword) |
             Q(city__contains=keyword) |
             Q(username__contains=keyword)
         )
     if not current_org.is_root():
         username_list = current_org.get_members().values_list('username', flat=True)
         login_logs = login_logs.filter(username__in=username_list)
     return login_logs
Ejemplo n.º 7
0
 def get_queryset(self):
     users = current_org.get_members()
     queryset = super().get_queryset().filter(
         user__in=[user.__str__() for user in users])
     return queryset
Ejemplo n.º 8
0
 def get_org_members():
     users = current_org.get_members().values_list('username', flat=True)
     return users
Ejemplo n.º 9
0
 def dates_total_count_disabled_users(self):
     return current_org.get_members().filter(is_active=False).count()
Ejemplo n.º 10
0
 def get_total_count_users():
     return current_org.get_members().count()
Ejemplo n.º 11
0
 def has_permission(self, request, view):
     query_user_id = request.query_params.get('user')
     if not query_user_id:
         return False
     query_user = current_org.get_members().filter(id=query_user_id).first()
     return bool(query_user)
Ejemplo n.º 12
0
 def _get_user_list(self):
     users = current_org.get_members(exclude=('Auditor',))
     return users
Ejemplo n.º 13
0
def get_current_org_members():
    from orgs.utils import current_org
    return current_org.get_members()
Ejemplo n.º 14
0
def get_current_org_members(exclude=()):
    from orgs.utils import current_org
    return current_org.get_members(exclude=exclude)