Commit bf40aa8d authored by ibuler's avatar ibuler

[Update] 修改user list api

parent 0c349f93
......@@ -53,3 +53,15 @@ class CommonModelMixin(models.Model):
class Meta:
abstract = True
class DebugQueryManager(models.Manager):
def get_queryset(self):
import traceback
lines = traceback.format_stack()
print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>")
for line in lines[-10:-1]:
print(line)
print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
queryset = super().get_queryset()
return queryset
......@@ -4,7 +4,7 @@ from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _
from common.utils import is_uuid
from common.utils import is_uuid, lazyproperty
class Organization(models.Model):
......@@ -72,7 +72,8 @@ class Organization(models.Model):
org = cls.default() if default else None
return org
def get_org_users(self):
@lazyproperty
def org_users(self):
from users.models import User
if self.is_real():
return self.users.all()
......@@ -81,18 +82,29 @@ class Organization(models.Model):
users = users.filter(related_user_orgs__isnull=True)
return users
def get_org_admins(self):
def get_org_users(self):
return self.org_users
@lazyproperty
def org_admins(self):
from users.models import User
if self.is_real():
return self.admins.all()
return User.objects.filter(role=User.ROLE_ADMIN)
def get_org_auditors(self):
def get_org_admins(self):
return self.org_admins
@lazyproperty
def org_auditors(self):
from users.models import User
if self.is_real():
return self.auditors.all()
return User.objects.filter(role=User.ROLE_AUDITOR)
def get_org_auditors(self):
return self.org_auditors
def get_org_members(self, exclude=()):
from users.models import User
members = User.objects.none()
......
......@@ -299,6 +299,8 @@ function requestApi(props) {
msg = jqXHR.responseJSON.error
} else if (jqXHR.responseJSON.msg) {
msg = jqXHR.responseJSON.msg
} else if (jqXHR.responseJSON.detail) {
msg = jqXHR.responseJSON.detail
}
}
if (msg === "") {
......
......@@ -404,7 +404,8 @@ class MFAMixin:
def mfa_enabled_but_not_set(self):
if self.mfa_enabled and \
self.mfa_is_otp() and not self.otp_secret_key:
self.mfa_is_otp() and \
not self.otp_secret_key:
return True
return False
......
......@@ -18,9 +18,6 @@ __all__ = [
class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer):
can_update = serializers.SerializerMethodField()
can_delete = serializers.SerializerMethodField()
class Meta:
model = User
list_serializer_class = AdaptedBulkListSerializer
......@@ -31,7 +28,6 @@ class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer):
'comment', 'source', 'source_display', 'is_valid', 'is_expired',
'is_active', 'created_by', 'is_first_login',
'date_password_last_updated', 'date_expired', 'avatar_url',
'can_update', 'can_delete',
]
extra_kwargs = {
'password': {'write_only': True, 'required': False, 'allow_null': True, 'allow_blank': True},
......@@ -48,16 +44,6 @@ class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer):
'can_delete': {'read_only': True},
}
def get_can_update(self, obj):
return CanUpdateDeleteUser.has_update_object_permission(
self.context['request'], self.context['view'], obj
)
def get_can_delete(self, obj):
return CanUpdateDeleteUser.has_delete_object_permission(
self.context['request'], self.context['view'], obj
)
def validate_role(self, value):
request = self.context.get('request')
if not request.user.is_superuser and value != User.ROLE_USER:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment