Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
3b4db38f
Commit
3b4db38f
authored
Jul 26, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 添加serializer class避免报错
parent
bfd88167
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
28 additions
and
19 deletions
+28
-19
swagger.py
apps/jumpserver/swagger.py
+0
-2
api.py
apps/settings/api.py
+3
-2
serializers.py
apps/settings/serializers.py
+5
-0
command.py
apps/terminal/api/command.py
+2
-0
user.py
apps/users/api/user.py
+10
-10
v1.py
apps/users/serializers/v1.py
+8
-5
No files found.
apps/jumpserver/swagger.py
View file @
3b4db38f
...
@@ -24,8 +24,6 @@ class CustomSwaggerAutoSchema(SwaggerAutoSchema):
...
@@ -24,8 +24,6 @@ class CustomSwaggerAutoSchema(SwaggerAutoSchema):
if
dump_keys
[
0
]
==
"perms"
and
dump_keys
[
1
]
==
"users"
:
if
dump_keys
[
0
]
==
"perms"
and
dump_keys
[
1
]
==
"users"
:
if
self
.
path
.
find
(
'{id}'
)
<
0
:
if
self
.
path
.
find
(
'{id}'
)
<
0
:
dump_keys
.
insert
(
2
,
"my"
)
dump_keys
.
insert
(
2
,
"my"
)
print
(
self
.
path
)
print
(
dump_keys
)
if
action
.
replace
(
'bulk_'
,
''
)
==
dump_keys
[
-
1
]:
if
action
.
replace
(
'bulk_'
,
''
)
==
dump_keys
[
-
1
]:
dump_keys
[
-
1
]
=
action
dump_keys
[
-
1
]
=
action
return
super
()
.
get_operation_id
(
tuple
(
dump_keys
))
return
super
()
.
get_operation_id
(
tuple
(
dump_keys
))
...
...
apps/settings/api.py
View file @
3b4db38f
...
@@ -16,7 +16,7 @@ from .models import Setting
...
@@ -16,7 +16,7 @@ from .models import Setting
from
.utils
import
LDAPUtil
from
.utils
import
LDAPUtil
from
common.permissions
import
IsOrgAdmin
,
IsSuperUser
from
common.permissions
import
IsOrgAdmin
,
IsSuperUser
from
common.utils
import
get_logger
from
common.utils
import
get_logger
from
.serializers
import
MailTestSerializer
,
LDAPTestSerializer
from
.serializers
import
MailTestSerializer
,
LDAPTestSerializer
,
LDAPUserSerializer
logger
=
get_logger
(
__file__
)
logger
=
get_logger
(
__file__
)
...
@@ -96,6 +96,7 @@ class LDAPTestingAPI(APIView):
...
@@ -96,6 +96,7 @@ class LDAPTestingAPI(APIView):
class
LDAPUserListApi
(
generics
.
ListAPIView
):
class
LDAPUserListApi
(
generics
.
ListAPIView
):
pagination_class
=
LimitOffsetPagination
pagination_class
=
LimitOffsetPagination
permission_classes
=
(
IsOrgAdmin
,)
permission_classes
=
(
IsOrgAdmin
,)
serializer_class
=
LDAPUserSerializer
def
get_queryset
(
self
):
def
get_queryset
(
self
):
util
=
LDAPUtil
()
util
=
LDAPUtil
()
...
@@ -103,7 +104,7 @@ class LDAPUserListApi(generics.ListAPIView):
...
@@ -103,7 +104,7 @@ class LDAPUserListApi(generics.ListAPIView):
users
=
util
.
search_user_items
()
users
=
util
.
search_user_items
()
except
Exception
as
e
:
except
Exception
as
e
:
users
=
[]
users
=
[]
logger
.
error
(
e
,
exc_info
=
True
)
logger
.
error
(
e
)
# 前端data_table会根据row.id对table.selected值进行操作
# 前端data_table会根据row.id对table.selected值进行操作
for
user
in
users
:
for
user
in
users
:
user
[
'id'
]
=
user
[
'username'
]
user
[
'id'
]
=
user
[
'username'
]
...
...
apps/settings/serializers.py
View file @
3b4db38f
...
@@ -21,4 +21,9 @@ class LDAPTestSerializer(serializers.Serializer):
...
@@ -21,4 +21,9 @@ class LDAPTestSerializer(serializers.Serializer):
AUTH_LDAP_START_TLS
=
serializers
.
BooleanField
(
required
=
False
)
AUTH_LDAP_START_TLS
=
serializers
.
BooleanField
(
required
=
False
)
class
LDAPUserSerializer
(
serializers
.
Serializer
):
id
=
serializers
.
CharField
()
username
=
serializers
.
CharField
()
email
=
serializers
.
CharField
()
existing
=
serializers
.
BooleanField
(
read_only
=
True
)
apps/terminal/api/command.py
View file @
3b4db38f
...
@@ -91,6 +91,8 @@ class CommandViewSet(CommandQueryMixin, viewsets.ModelViewSet):
...
@@ -91,6 +91,8 @@ class CommandViewSet(CommandQueryMixin, viewsets.ModelViewSet):
class
CommandExportApi
(
CommandQueryMixin
,
generics
.
ListAPIView
):
class
CommandExportApi
(
CommandQueryMixin
,
generics
.
ListAPIView
):
serializer_class
=
SessionCommandSerializer
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
queryset
=
self
.
filter_queryset
(
self
.
get_queryset
())
queryset
=
self
.
filter_queryset
(
self
.
get_queryset
())
...
...
apps/users/api/user.py
View file @
3b4db38f
...
@@ -19,8 +19,7 @@ from common.permissions import (
...
@@ -19,8 +19,7 @@ from common.permissions import (
from
common.mixins
import
IDInCacheFilterMixin
from
common.mixins
import
IDInCacheFilterMixin
from
common.utils
import
get_logger
from
common.utils
import
get_logger
from
orgs.utils
import
current_org
from
orgs.utils
import
current_org
from
..serializers
import
UserSerializer
,
UserPKUpdateSerializer
,
\
from
..
import
serializers
UserUpdateGroupSerializer
,
ChangeUserPasswordSerializer
from
..models
import
User
from
..models
import
User
from
..signals
import
post_user_create
from
..signals
import
post_user_create
...
@@ -37,7 +36,7 @@ class UserViewSet(IDInCacheFilterMixin, BulkModelViewSet):
...
@@ -37,7 +36,7 @@ class UserViewSet(IDInCacheFilterMixin, BulkModelViewSet):
filter_fields
=
(
'username'
,
'email'
,
'name'
,
'id'
)
filter_fields
=
(
'username'
,
'email'
,
'name'
,
'id'
)
search_fields
=
filter_fields
search_fields
=
filter_fields
queryset
=
User
.
objects
.
exclude
(
role
=
User
.
ROLE_APP
)
queryset
=
User
.
objects
.
exclude
(
role
=
User
.
ROLE_APP
)
serializer_class
=
UserSerializer
serializer_class
=
serializers
.
UserSerializer
permission_classes
=
(
IsOrgAdmin
,
CanUpdateDeleteSuperUser
)
permission_classes
=
(
IsOrgAdmin
,
CanUpdateDeleteSuperUser
)
pagination_class
=
LimitOffsetPagination
pagination_class
=
LimitOffsetPagination
...
@@ -102,7 +101,7 @@ class UserViewSet(IDInCacheFilterMixin, BulkModelViewSet):
...
@@ -102,7 +101,7 @@ class UserViewSet(IDInCacheFilterMixin, BulkModelViewSet):
class
UserChangePasswordApi
(
generics
.
RetrieveUpdateAPIView
):
class
UserChangePasswordApi
(
generics
.
RetrieveUpdateAPIView
):
permission_classes
=
(
IsOrgAdmin
,)
permission_classes
=
(
IsOrgAdmin
,)
queryset
=
User
.
objects
.
all
()
queryset
=
User
.
objects
.
all
()
serializer_class
=
ChangeUserPasswordSerializer
serializer_class
=
serializers
.
ChangeUserPasswordSerializer
def
perform_update
(
self
,
serializer
):
def
perform_update
(
self
,
serializer
):
user
=
self
.
get_object
()
user
=
self
.
get_object
()
...
@@ -112,13 +111,13 @@ class UserChangePasswordApi(generics.RetrieveUpdateAPIView):
...
@@ -112,13 +111,13 @@ class UserChangePasswordApi(generics.RetrieveUpdateAPIView):
class
UserUpdateGroupApi
(
generics
.
RetrieveUpdateAPIView
):
class
UserUpdateGroupApi
(
generics
.
RetrieveUpdateAPIView
):
queryset
=
User
.
objects
.
all
()
queryset
=
User
.
objects
.
all
()
serializer_class
=
UserUpdateGroupSerializer
serializer_class
=
serializers
.
UserUpdateGroupSerializer
permission_classes
=
(
IsOrgAdmin
,)
permission_classes
=
(
IsOrgAdmin
,)
class
UserResetPasswordApi
(
generics
.
UpdateAPIView
):
class
UserResetPasswordApi
(
generics
.
UpdateAPIView
):
queryset
=
User
.
objects
.
all
()
queryset
=
User
.
objects
.
all
()
serializer_class
=
UserSerializer
serializer_class
=
serializers
.
UserSerializer
permission_classes
=
(
IsAuthenticated
,)
permission_classes
=
(
IsAuthenticated
,)
def
perform_update
(
self
,
serializer
):
def
perform_update
(
self
,
serializer
):
...
@@ -133,7 +132,7 @@ class UserResetPasswordApi(generics.UpdateAPIView):
...
@@ -133,7 +132,7 @@ class UserResetPasswordApi(generics.UpdateAPIView):
class
UserResetPKApi
(
generics
.
UpdateAPIView
):
class
UserResetPKApi
(
generics
.
UpdateAPIView
):
queryset
=
User
.
objects
.
all
()
queryset
=
User
.
objects
.
all
()
serializer_class
=
UserSerializer
serializer_class
=
serializers
.
UserSerializer
permission_classes
=
(
IsAuthenticated
,)
permission_classes
=
(
IsAuthenticated
,)
def
perform_update
(
self
,
serializer
):
def
perform_update
(
self
,
serializer
):
...
@@ -147,7 +146,7 @@ class UserResetPKApi(generics.UpdateAPIView):
...
@@ -147,7 +146,7 @@ class UserResetPKApi(generics.UpdateAPIView):
# 废弃
# 废弃
class
UserUpdatePKApi
(
generics
.
UpdateAPIView
):
class
UserUpdatePKApi
(
generics
.
UpdateAPIView
):
queryset
=
User
.
objects
.
all
()
queryset
=
User
.
objects
.
all
()
serializer_class
=
UserPKUpdateSerializer
serializer_class
=
serializers
.
UserPKUpdateSerializer
permission_classes
=
(
IsCurrentUserOrReadOnly
,)
permission_classes
=
(
IsCurrentUserOrReadOnly
,)
def
perform_update
(
self
,
serializer
):
def
perform_update
(
self
,
serializer
):
...
@@ -159,7 +158,7 @@ class UserUpdatePKApi(generics.UpdateAPIView):
...
@@ -159,7 +158,7 @@ class UserUpdatePKApi(generics.UpdateAPIView):
class
UserUnblockPKApi
(
generics
.
UpdateAPIView
):
class
UserUnblockPKApi
(
generics
.
UpdateAPIView
):
queryset
=
User
.
objects
.
all
()
queryset
=
User
.
objects
.
all
()
permission_classes
=
(
IsOrgAdmin
,)
permission_classes
=
(
IsOrgAdmin
,)
serializer_class
=
UserSerializer
serializer_class
=
serializers
.
UserSerializer
key_prefix_limit
=
"_LOGIN_LIMIT_{}_{}"
key_prefix_limit
=
"_LOGIN_LIMIT_{}_{}"
key_prefix_block
=
"_LOGIN_BLOCK_{}"
key_prefix_block
=
"_LOGIN_BLOCK_{}"
...
@@ -174,7 +173,7 @@ class UserUnblockPKApi(generics.UpdateAPIView):
...
@@ -174,7 +173,7 @@ class UserUnblockPKApi(generics.UpdateAPIView):
class
UserProfileApi
(
generics
.
RetrieveAPIView
):
class
UserProfileApi
(
generics
.
RetrieveAPIView
):
permission_classes
=
(
IsAuthenticated
,)
permission_classes
=
(
IsAuthenticated
,)
serializer_class
=
UserSerializer
serializer_class
=
serializers
.
UserSerializer
def
get_object
(
self
):
def
get_object
(
self
):
return
self
.
request
.
user
return
self
.
request
.
user
...
@@ -183,6 +182,7 @@ class UserProfileApi(generics.RetrieveAPIView):
...
@@ -183,6 +182,7 @@ class UserProfileApi(generics.RetrieveAPIView):
class
UserResetOTPApi
(
generics
.
RetrieveAPIView
):
class
UserResetOTPApi
(
generics
.
RetrieveAPIView
):
queryset
=
User
.
objects
.
all
()
queryset
=
User
.
objects
.
all
()
permission_classes
=
(
IsOrgAdmin
,)
permission_classes
=
(
IsOrgAdmin
,)
serializer_class
=
serializers
.
ResetOTPSerializer
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
user
=
self
.
get_object
()
if
kwargs
.
get
(
'pk'
)
else
request
.
user
user
=
self
.
get_object
()
if
kwargs
.
get
(
'pk'
)
else
request
.
user
...
...
apps/users/serializers/v1.py
View file @
3b4db38f
...
@@ -4,7 +4,7 @@ from django.utils.translation import ugettext_lazy as _
...
@@ -4,7 +4,7 @@ from django.utils.translation import ugettext_lazy as _
from
rest_framework
import
serializers
from
rest_framework
import
serializers
from
common.utils
import
get_signer
,
validate_ssh_public_key
from
common.utils
import
validate_ssh_public_key
from
common.mixins
import
BulkSerializerMixin
from
common.mixins
import
BulkSerializerMixin
from
common.fields
import
StringManyToManyField
from
common.fields
import
StringManyToManyField
from
common.serializers
import
AdaptedBulkListSerializer
from
common.serializers
import
AdaptedBulkListSerializer
...
@@ -15,13 +15,11 @@ from ..models import User, UserGroup
...
@@ -15,13 +15,11 @@ from ..models import User, UserGroup
__all__
=
[
__all__
=
[
'UserSerializer'
,
'UserPKUpdateSerializer'
,
'UserUpdateGroupSerializer'
,
'UserSerializer'
,
'UserPKUpdateSerializer'
,
'UserUpdateGroupSerializer'
,
'UserGroupSerializer'
,
'UserGroupListSerializer'
,
'UserGroupSerializer'
,
'UserGroupListSerializer'
,
'UserGroupUpdateMemberSerializer'
,
'ChangeUserPasswordSerializer'
'UserGroupUpdateMemberSerializer'
,
'ChangeUserPasswordSerializer'
,
'ResetOTPSerializer'
,
]
]
signer
=
get_signer
()
class
UserSerializer
(
BulkSerializerMixin
,
serializers
.
ModelSerializer
):
class
UserSerializer
(
BulkSerializerMixin
,
serializers
.
ModelSerializer
):
class
Meta
:
class
Meta
:
...
@@ -139,3 +137,7 @@ class ChangeUserPasswordSerializer(serializers.ModelSerializer):
...
@@ -139,3 +137,7 @@ class ChangeUserPasswordSerializer(serializers.ModelSerializer):
class
Meta
:
class
Meta
:
model
=
User
model
=
User
fields
=
[
'password'
]
fields
=
[
'password'
]
class
ResetOTPSerializer
(
serializers
.
Serializer
):
msg
=
serializers
.
CharField
(
read_only
=
True
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment