mirror of https://github.com/jumpserver/jumpserver
commit
5b407fe8bc
|
@ -14,6 +14,7 @@ from common.mixins import CommonApiMixin
|
|||
from common.utils import get_logger
|
||||
from orgs.utils import current_org
|
||||
from .. import serializers
|
||||
from ..serializers import UserSerializer, UserRetrieveSerializer
|
||||
from .mixins import UserQuerysetMixin
|
||||
from ..models import User
|
||||
from ..signals import post_user_create
|
||||
|
@ -29,8 +30,11 @@ __all__ = [
|
|||
class UserViewSet(CommonApiMixin, UserQuerysetMixin, BulkModelViewSet):
|
||||
filter_fields = ('username', 'email', 'name', 'id', 'source')
|
||||
search_fields = filter_fields
|
||||
serializer_class = serializers.UserSerializer
|
||||
permission_classes = (IsOrgAdmin, CanUpdateDeleteUser)
|
||||
serializer_classes = {
|
||||
'default': UserSerializer,
|
||||
'retrieve': UserRetrieveSerializer
|
||||
}
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().prefetch_related('groups')
|
||||
|
|
|
@ -16,7 +16,8 @@ __all__ = [
|
|||
'UserSerializer', 'UserPKUpdateSerializer',
|
||||
'ChangeUserPasswordSerializer', 'ResetOTPSerializer',
|
||||
'UserProfileSerializer', 'UserOrgSerializer',
|
||||
'UserUpdatePasswordSerializer', 'UserUpdatePublicKeySerializer'
|
||||
'UserUpdatePasswordSerializer', 'UserUpdatePublicKeySerializer',
|
||||
'UserRetrieveSerializer'
|
||||
]
|
||||
|
||||
|
||||
|
@ -40,7 +41,6 @@ class UserSerializer(CommonBulkSerializerMixin, serializers.ModelSerializer):
|
|||
login_blocked = serializers.SerializerMethodField()
|
||||
can_update = serializers.SerializerMethodField()
|
||||
can_delete = serializers.SerializerMethodField()
|
||||
login_confirm_settings = serializers.PrimaryKeyRelatedField(read_only=True, source='login_confirm_setting.reviewers', many=True)
|
||||
|
||||
key_prefix_block = "_LOGIN_BLOCK_{}"
|
||||
|
||||
|
@ -60,7 +60,7 @@ class UserSerializer(CommonBulkSerializerMixin, serializers.ModelSerializer):
|
|||
]
|
||||
fields = fields_small + [
|
||||
'groups', 'role', 'groups_display', 'role_display',
|
||||
'can_update', 'can_delete', 'login_blocked', 'login_confirm_settings'
|
||||
'can_update', 'can_delete', 'login_blocked',
|
||||
]
|
||||
|
||||
extra_kwargs = {
|
||||
|
@ -158,6 +158,14 @@ class UserSerializer(CommonBulkSerializerMixin, serializers.ModelSerializer):
|
|||
return blocked
|
||||
|
||||
|
||||
class UserRetrieveSerializer(UserSerializer):
|
||||
login_confirm_settings = serializers.PrimaryKeyRelatedField(read_only=True,
|
||||
source='login_confirm_setting.reviewers', many=True)
|
||||
|
||||
class Meta(UserSerializer.Meta):
|
||||
fields = UserSerializer.Meta.fields + ['login_confirm_settings']
|
||||
|
||||
|
||||
class UserPKUpdateSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = User
|
||||
|
|
Loading…
Reference in New Issue