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
6e843533
Commit
6e843533
authored
Nov 25, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Base finish user
parent
d8a229c0
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
8 additions
and
37 deletions
+8
-37
api.py
apps/assets/api.py
+3
-3
serializers.py
apps/assets/serializers.py
+1
-1
mixins.py
apps/common/mixins.py
+1
-1
api.py
apps/users/api.py
+2
-19
serializers.py
apps/users/serializers.py
+0
-10
user_list.html
apps/users/templates/users/user_list.html
+1
-1
views.py
apps/users/views.py
+0
-2
No files found.
apps/assets/api.py
View file @
6e843533
...
...
@@ -6,14 +6,14 @@ from rest_framework.views import APIView
from
rest_framework_bulk
import
BulkListSerializer
,
BulkSerializerMixin
,
ListBulkCreateUpdateDestroyAPIView
from
django.shortcuts
import
get_object_or_404
from
common.mixins
import
BulkDeleteApi
Mixin
from
common.mixins
import
IDInFilter
Mixin
from
common.utils
import
get_object_or_none
,
signer
from
.hands
import
IsSuperUserOrTerminalUser
,
IsSuperUser
from
.models
import
AssetGroup
,
Asset
,
IDC
,
SystemUser
,
AdminUser
from
.
import
serializers
class
AssetViewSet
(
viewsets
.
ModelViewSet
):
class
AssetViewSet
(
IDInFilterMixin
,
viewsets
.
ModelViewSet
):
"""API endpoint that allows Asset to be viewed or edited."""
queryset
=
Asset
.
objects
.
all
()
serializer_class
=
serializers
.
AssetSerializer
...
...
@@ -71,7 +71,7 @@ class SystemUserViewSet(viewsets.ModelViewSet):
# return self.object.assets.all()
class
AssetListUpdateApi
(
BulkDeleteApi
Mixin
,
ListBulkCreateUpdateDestroyAPIView
):
class
AssetListUpdateApi
(
IDInFilter
Mixin
,
ListBulkCreateUpdateDestroyAPIView
):
queryset
=
Asset
.
objects
.
all
()
serializer_class
=
serializers
.
AssetSerializer
permission_classes
=
(
IsSuperUser
,)
...
...
apps/assets/serializers.py
View file @
6e843533
...
...
@@ -2,7 +2,7 @@
from
django.utils.translation
import
ugettext_lazy
as
_
from
rest_framework
import
viewsets
,
serializers
,
generics
from
.models
import
AssetGroup
,
Asset
,
IDC
,
AssetExtend
,
AdminUser
,
SystemUser
from
common.mixins
import
BulkDeleteApi
Mixin
from
common.mixins
import
IDInFilter
Mixin
from
rest_framework_bulk
import
BulkListSerializer
,
BulkSerializerMixin
...
...
apps/common/mixins.py
View file @
6e843533
...
...
@@ -46,7 +46,7 @@ class JSONResponseMixin(object):
return
JsonResponse
(
context
)
class
BulkDeleteApi
Mixin
(
object
):
class
IDInFilter
Mixin
(
object
):
def
filter_queryset
(
self
,
queryset
):
id_list
=
self
.
request
.
query_params
.
get
(
'id__in'
)
...
...
apps/users/api.py
View file @
6e843533
...
...
@@ -15,7 +15,7 @@ from rest_framework import authentication
import
django_filters
from
django_filters.rest_framework
import
DjangoFilterBackend
from
common.mixins
import
BulkDeleteApi
Mixin
from
common.mixins
import
IDInFilter
Mixin
from
common.utils
import
get_logger
from
.utils
import
check_user_valid
,
token_gen
from
.models
import
User
,
UserGroup
...
...
@@ -27,29 +27,12 @@ from . import serializers
logger
=
get_logger
(
__name__
)
class
IDInFilter
(
django_filters
.
rest_framework
.
FilterSet
):
id__in
=
django_filters
.
CharFilter
(
method
=
'in_filter'
)
class
Meta
:
model
=
User
fields
=
[
'id__in'
]
def
in_filter
(
self
,
queryset
,
name
,
value
):
try
:
value
=
json
.
loads
(
value
)
except
ValueError
:
value
=
[]
return
queryset
.
filter
(
**
{
name
+
'__in'
:
value
})
class
UserViewSet
(
BulkModelViewSet
):
class
UserViewSet
(
IDInFilterMixin
,
BulkModelViewSet
):
queryset
=
User
.
objects
.
all
()
serializer_class
=
serializers
.
UserSerializer
permission_classes
=
(
IsSuperUser
,)
filter_backends
=
(
DjangoFilterBackend
,)
filter_fields
=
(
'username'
,
'email'
,
'name'
,
'id'
)
filter_class
=
IDInFilter
ordering_fields
=
(
'username'
,
'email'
)
class
UserUpdateGroupApi
(
generics
.
RetrieveUpdateAPIView
):
...
...
apps/users/serializers.py
View file @
6e843533
...
...
@@ -9,12 +9,6 @@ from common.utils import signer, validate_ssh_public_key
from
.models
import
User
,
UserGroup
# class UserDetailSerializer(BulkSerializerMixin, serializers.ModelSerializer):
# class Meta:
# model = User
# fields = ['avatar', 'wechat', 'phone', 'enable_otp', 'comment', 'is_active', 'name']
class
UserSerializer
(
BulkSerializerMixin
,
serializers
.
ModelSerializer
):
groups_display
=
serializers
.
SerializerMethodField
()
groups
=
serializers
.
PrimaryKeyRelatedField
(
many
=
True
,
queryset
=
UserGroup
.
objects
.
all
())
...
...
@@ -33,10 +27,6 @@ class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer):
def
get_groups_display
(
obj
):
return
" "
.
join
([
group
.
name
for
group
in
obj
.
groups
.
all
()])
# @staticmethod
# def get_active_display(obj):
# return not (obj.is_expired and obj.is_active)
class
UserPKUpdateSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
...
...
apps/users/templates/users/user_list.html
View file @
6e843533
...
...
@@ -86,7 +86,7 @@ $(document).ready(function(){
}
}}],
ajax_url
:
'{% url "api-users:user-list" %}'
,
columns
:
[{
data
:
"id"
},
{
data
:
"
username"
},
{
data
:
"
name"
},
{
data
:
"get_role_display"
},
columns
:
[{
data
:
"id"
},
{
data
:
"
name"
},
{
data
:
"user
name"
},
{
data
:
"get_role_display"
},
{
data
:
"groups_display"
},
{
data
:
"is_valid"
},
{
data
:
"id"
}],
op_html
:
$
(
'#actions'
).
html
()
};
...
...
apps/users/views.py
View file @
6e843533
...
...
@@ -3,12 +3,10 @@
from
__future__
import
unicode_literals
import
json
import
uuid
import
codecs
from
openpyxl
import
Workbook
from
openpyxl.writer.excel
import
save_virtual_workbook
from
openpyxl
import
load_workbook
import
unicodecsv
as
csv
from
django
import
forms
from
django.utils
import
timezone
from
django.core.cache
import
cache
...
...
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