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
4c801bb8
Commit
4c801bb8
authored
Nov 19, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改用户列表
parent
1bba0041
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
10 deletions
+46
-10
api.py
apps/common/mixins/api.py
+9
-1
user.py
apps/users/api/user.py
+1
-0
user.py
apps/users/serializers/user.py
+36
-9
No files found.
apps/common/mixins/api.py
View file @
4c801bb8
...
...
@@ -25,6 +25,14 @@ class IDSpmFilterMixin:
return
backends
class
SerializerMixin
:
def
get_serializer_class
(
self
):
if
self
.
request
.
query_params
.
get
(
'draw'
)
\
and
hasattr
(
self
,
'serializer_display_class'
):
return
self
.
serializer_display_class
return
super
()
.
get_serializer_class
()
class
ExtraFilterFieldsMixin
:
default_added_filters
=
[
CustomFilter
,
IDSpmFilter
]
filter_backends
=
api_settings
.
DEFAULT_FILTER_BACKENDS
...
...
@@ -44,5 +52,5 @@ class ExtraFilterFieldsMixin:
return
queryset
class
CommonApiMixin
(
ExtraFilterFieldsMixin
):
class
CommonApiMixin
(
SerializerMixin
,
ExtraFilterFieldsMixin
):
pass
apps/users/api/user.py
View file @
4c801bb8
...
...
@@ -40,6 +40,7 @@ class UserViewSet(CommonApiMixin, UserQuerysetMixin, BulkModelViewSet):
filter_fields
=
(
'username'
,
'email'
,
'name'
,
'id'
)
search_fields
=
filter_fields
serializer_class
=
serializers
.
UserSerializer
serializer_display_class
=
serializers
.
UserDisplaySerializer
permission_classes
=
(
IsOrgAdmin
,
CanUpdateDeleteUser
)
def
get_queryset
(
self
):
...
...
apps/users/serializers/user.py
View file @
4c801bb8
...
...
@@ -13,35 +13,30 @@ from ..models import User, UserGroup
__all__
=
[
'UserSerializer'
,
'UserPKUpdateSerializer'
,
'UserUpdateGroupSerializer'
,
'ChangeUserPasswordSerializer'
,
'ResetOTPSerializer'
,
'UserProfileSerializer'
,
'UserProfileSerializer'
,
'UserDisplaySerializer'
,
]
class
UserSerializer
(
BulkSerializerMixin
,
serializers
.
ModelSerializer
):
class
Meta
:
model
=
User
list_serializer_class
=
AdaptedBulkListSerializer
fields
=
[
'id'
,
'name'
,
'username'
,
'password'
,
'email'
,
'public_key'
,
'groups'
,
'groups_display'
,
'role'
,
'role_display'
,
'wechat'
,
'phone'
,
'mfa_level'
,
'comment'
,
'source'
,
'source_display'
,
'is_valid'
,
'is_expired'
,
'groups'
,
'role'
,
'wechat'
,
'phone'
,
'mfa_level'
,
'comment'
,
'source'
,
'is_valid'
,
'is_expired'
,
'is_active'
,
'created_by'
,
'is_first_login'
,
'date_password_last_updated'
,
'date_expired'
,
'avatar_url'
,
]
extra_kwargs
=
{
'password'
:
{
'write_only'
:
True
,
'required'
:
False
,
'allow_null'
:
True
,
'allow_blank'
:
True
},
'public_key'
:
{
'write_only'
:
True
},
'groups_display'
:
{
'label'
:
_
(
'Groups name'
)},
'source_display'
:
{
'label'
:
_
(
'Source name'
)},
'is_first_login'
:
{
'label'
:
_
(
'Is first login'
),
'read_only'
:
True
},
'role_display'
:
{
'label'
:
_
(
'Role name'
)},
'is_valid'
:
{
'label'
:
_
(
'Is valid'
)},
'is_expired'
:
{
'label'
:
_
(
'Is expired'
)},
'avatar_url'
:
{
'label'
:
_
(
'Avatar url'
)},
'created_by'
:
{
'read_only'
:
True
,
'allow_blank'
:
True
},
'can_update'
:
{
'read_only'
:
True
},
'can_delete'
:
{
'read_only'
:
True
},
}
def
validate_role
(
self
,
value
):
...
...
@@ -84,6 +79,38 @@ class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer):
return
attrs
class
UserDisplaySerializer
(
UserSerializer
):
can_update
=
serializers
.
SerializerMethodField
()
can_delete
=
serializers
.
SerializerMethodField
()
class
Meta
(
UserSerializer
.
Meta
):
fields
=
UserSerializer
.
Meta
.
fields
+
[
'groups_display'
,
'role_display'
,
'source_display'
,
'can_update'
,
'can_delete'
,
]
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
get_extra_kwargs
(
self
):
kwargs
=
super
()
.
get_extra_kwargs
()
kwargs
.
update
({
'can_update'
:
{
'read_only'
:
True
},
'can_delete'
:
{
'read_only'
:
True
},
'groups_display'
:
{
'label'
:
_
(
'Groups name'
)},
'source_display'
:
{
'label'
:
_
(
'Source name'
)},
'role_display'
:
{
'label'
:
_
(
'Role name'
)},
})
return
kwargs
class
UserPKUpdateSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
User
...
...
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