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
d8a229c0
Commit
d8a229c0
authored
Nov 25, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
to Commpany
parent
72ad4b44
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
38 deletions
+39
-38
api.py
apps/assets/api.py
+1
-1
settings.py
apps/jumpserver/settings.py
+1
-1
jumpserver.js
apps/static/js/jumpserver.js
+0
-2
api.py
apps/users/api.py
+19
-2
user_list.html
apps/users/templates/users/user_list.html
+18
-32
No files found.
apps/assets/api.py
View file @
d8a229c0
...
...
@@ -17,6 +17,7 @@ class AssetViewSet(viewsets.ModelViewSet):
"""API endpoint that allows Asset to be viewed or edited."""
queryset
=
Asset
.
objects
.
all
()
serializer_class
=
serializers
.
AssetSerializer
filter_fields
=
(
'id'
,
'ip'
,
'hostname'
)
def
get_queryset
(
self
):
queryset
=
super
(
AssetViewSet
,
self
)
.
get_queryset
()
...
...
@@ -27,7 +28,6 @@ class AssetViewSet(viewsets.ModelViewSet):
if
asset_group_id
:
queryset
=
queryset
.
filter
(
groups__id
=
asset_group_id
)
return
queryset
...
...
apps/jumpserver/settings.py
View file @
d8a229c0
...
...
@@ -272,7 +272,7 @@ REST_FRAMEWORK = {
'rest_framework.authentication.BasicAuthentication'
,
'rest_framework.authentication.SessionAuthentication'
,
),
'DEFAULT_FILTER_BACKENDS'
:
(
'
rest_framework.filters
.DjangoFilterBackend'
,),
'DEFAULT_FILTER_BACKENDS'
:
(
'
django_filters.rest_framework
.DjangoFilterBackend'
,),
}
# Custom User Auth model
...
...
apps/static/js/jumpserver.js
View file @
d8a229c0
...
...
@@ -214,9 +214,7 @@ function APIUpdateAttr(props) {
// Sweet Alert for Delete
function
objectDelete
(
obj
,
name
,
url
)
{
var
$this
=
$
(
this
);
function
doDelete
()
{
var
uid
=
$this
.
data
(
'uid'
);
var
body
=
{};
var
success
=
function
()
{
swal
(
'Deleted!'
,
"[ "
+
name
+
"]"
+
" has been deleted "
,
"success"
);
...
...
apps/users/api.py
View file @
d8a229c0
...
...
@@ -2,8 +2,8 @@
#
import
base64
import
json
from
rest_framework
import
filters
from
django.shortcuts
import
get_object_or_404
from
django.core.cache
import
cache
from
django.conf
import
settings
...
...
@@ -12,6 +12,7 @@ from rest_framework.response import Response
from
rest_framework.views
import
APIView
from
rest_framework_bulk
import
ListBulkCreateUpdateDestroyAPIView
,
BulkModelViewSet
from
rest_framework
import
authentication
import
django_filters
from
django_filters.rest_framework
import
DjangoFilterBackend
from
common.mixins
import
BulkDeleteApiMixin
...
...
@@ -26,12 +27,28 @@ 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
):
queryset
=
User
.
objects
.
all
()
serializer_class
=
serializers
.
UserSerializer
permission_classes
=
(
IsSuperUser
,)
filter_backends
=
(
DjangoFilterBackend
,)
# filter_fields = ('username', 'email', 'name', 'id')
filter_fields
=
(
'username'
,
'email'
,
'name'
,
'id'
)
filter_class
=
IDInFilter
ordering_fields
=
(
'username'
,
'email'
)
...
...
apps/users/templates/users/user_list.html
View file @
d8a229c0
...
...
@@ -39,6 +39,7 @@
<option
value=
"delete"
>
{% trans 'Delete selected' %}
</option>
<option
value=
"update"
>
{% trans 'Update selected' %}
</option>
<option
value=
"deactive"
>
{% trans 'Deactive selected' %}
</option>
<option
value=
"active"
>
{% trans 'Active selected' %}
</option>
</select>
<div
class=
"input-group-btn pull-left"
style=
"padding-left: 5px;"
>
<button
id=
'btn_bulk_update'
style=
"height: 32px;"
class=
"btn btn-sm btn-primary"
>
...
...
@@ -75,7 +76,9 @@ $(document).ready(function(){
}},
{
targets
:
6
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
update_btn
=
'<a href="{% url "users:user-update" pk=99991937 %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'
.
replace
(
'99991937'
,
cellData
);
var
del_btn
=
'<a class="btn btn-xs btn-danger m-l-xs btn_user_delete" data-uid="99991937">{% trans "Delete" %}</a>'
.
replace
(
'99991937'
,
cellData
);
var
del_btn
=
'<a class="btn btn-xs btn-danger m-l-xs btn_user_delete" data-uid="99991937" data-name="99991938">{% trans "Delete" %}</a>'
.
replace
(
'99991937'
,
cellData
)
.
replace
(
'99991938'
,
rowData
.
name
);
if
(
rowData
.
id
===
1
||
rowData
.
username
==
"admin"
)
{
$
(
td
).
html
(
update_btn
)
}
else
{
...
...
@@ -150,6 +153,14 @@ $(document).ready(function(){
$data_table
.
ajax
.
reload
();
jumpserver
.
checked
=
false
;
}
function
doActive
()
{
var
body
=
$
.
each
(
id_list
,
function
(
index
,
user_object
)
{
user_object
[
'is_active'
]
=
true
;
});
APIUpdateAttr
({
url
:
the_url
,
method
:
'PATCH'
,
body
:
JSON
.
stringify
(
body
)});
$data_table
.
ajax
.
reload
();
jumpserver
.
checked
=
false
;
}
function
doDelete
()
{
swal
({
title
:
"{% trans 'Are you sure?' %}"
,
...
...
@@ -187,43 +198,18 @@ $(document).ready(function(){
case
'update'
:
doUpdate
();
break
;
case
'active'
:
doActive
();
break
;
default
:
break
;
}
}).
on
(
'click'
,
'.btn_user_delete'
,
function
(){
var
$this
=
$
(
this
);
function
doDelete
()
{
var
name
=
$this
.
data
(
'name'
);
var
uid
=
$this
.
data
(
'uid'
);
var
the_url
=
'{% url "api-users:user-detail" pk=99991937 %}'
.
replace
(
'99991937'
,
uid
);
var
body
=
{};
var
success
=
function
()
{
var
msg
=
"{% trans 'User Deleted.' %}"
;
swal
(
"{% trans 'User Delete' %}"
,
msg
,
"success"
);
$
(
'#user_list_table'
).
DataTable
().
ajax
.
reload
();
};
var
fail
=
function
()
{
var
msg
=
"{% trans 'User Deleting failed.' %}"
;
swal
(
"{% trans 'User Delete' %}"
,
msg
,
"error"
);
};
APIUpdateAttr
({
url
:
the_url
,
body
:
JSON
.
stringify
(
body
),
method
:
'DELETE'
,
success
:
success
,
error
:
fail
});
}
swal
({
title
:
"{% trans 'Are you sure?' %}"
,
text
:
"{% trans 'This will delete the selected user.' %}"
,
type
:
"warning"
,
showCancelButton
:
true
,
confirmButtonColor
:
"#DD6B55"
,
confirmButtonText
:
"{% trans 'Confirm' %}"
,
closeOnConfirm
:
false
},
function
()
{
doDelete
();
});
objectDelete
(
$this
,
name
,
the_url
);
}).
on
(
'click'
,
'#btn_user_bulk_update'
,
function
(){
var
json_data
=
$
(
'#fm_user_bulk_update'
).
serializeObject
();
var
body
=
{};
...
...
@@ -237,7 +223,7 @@ $(document).ready(function(){
if
(
typeof
body
.
groups
===
'string'
)
{
body
.
groups
=
[
parseInt
(
body
.
groups
)]
}
else
if
(
typeof
body
.
groups
===
'array'
)
{
new_groups
=
body
.
groups
.
map
(
Number
);
var
new_groups
=
body
.
groups
.
map
(
Number
);
body
.
groups
=
new_groups
;
}
var
$data_table
=
$
(
'#user_list_table'
).
DataTable
();
...
...
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