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
bd882c8b
Commit
bd882c8b
authored
Nov 14, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
User group detail
parent
8d358a7a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
81 additions
and
48 deletions
+81
-48
jumpserver.js
apps/static/js/jumpserver.js
+12
-13
api.py
apps/users/api.py
+13
-3
serializers.py
apps/users/serializers.py
+27
-9
user_detail.html
apps/users/templates/users/user_detail.html
+2
-5
user_group_detail.html
apps/users/templates/users/user_group_detail.html
+0
-0
user_group_list.html
apps/users/templates/users/user_group_list.html
+10
-11
user_list.html
apps/users/templates/users/user_list.html
+6
-5
urls.py
apps/users/urls.py
+4
-1
views.py
apps/users/views.py
+7
-1
No files found.
apps/static/js/jumpserver.js
View file @
bd882c8b
...
...
@@ -297,6 +297,7 @@ jumpserver.initDataTable = function (options) {
url
:
options
.
i18n_url
||
"/static/js/plugins/dataTables/i18n/zh-hans.json"
},
order
:
options
.
order
||
[[
1
,
'asc'
]],
select
:
options
.
select
||
'multi'
,
buttons
:
options
.
buttons
||
[
{
extend
:
'excel'
,
exportOptions
:
{
...
...
@@ -323,9 +324,6 @@ jumpserver.initDataTable = function (options) {
}
],
columnDefs
:
columnDefs
,
// select: 'single',
// select: options.select || {style: 'single'},
// select: false,
ajax
:
{
url
:
options
.
ajax_url
,
dataSrc
:
""
...
...
@@ -333,16 +331,16 @@ jumpserver.initDataTable = function (options) {
columns
:
options
.
columns
||
[],
lengthMenu
:
[[
15
,
25
,
50
,
-
1
],
[
15
,
25
,
50
,
"All"
]]
});
//
table.on('select', function(e, dt, type, indexes) {
//
var $node = table[ type ]( indexes ).nodes().to$();
//
$node.find('input.ipt_check').prop('checked', true);
//
}).on('deselect', function(e, dt, type, indexes) {
//
var $node = table[ type ]( indexes ).nodes().to$();
//
$node.find('input.ipt_check').prop('checked', false);
//
}).on('draw', function(){
//
$('#op').html(options.op_html || '');
//
$('#uc').html(options.uc_html || '');
//
});
table
.
on
(
'select'
,
function
(
e
,
dt
,
type
,
indexes
)
{
var
$node
=
table
[
type
](
indexes
).
nodes
().
to$
();
$node
.
find
(
'input.ipt_check'
).
prop
(
'checked'
,
true
);
}).
on
(
'deselect'
,
function
(
e
,
dt
,
type
,
indexes
)
{
var
$node
=
table
[
type
](
indexes
).
nodes
().
to$
();
$node
.
find
(
'input.ipt_check'
).
prop
(
'checked'
,
false
);
}).
on
(
'draw'
,
function
(){
$
(
'#op'
).
html
(
options
.
op_html
||
''
);
$
(
'#uc'
).
html
(
options
.
uc_html
||
''
);
});
$
(
'.ipt_check_all'
).
on
(
'click'
,
function
()
{
if
(
!
jumpserver
.
checked
)
{
$
(
this
).
closest
(
'table'
).
find
(
'.ipt_check'
).
prop
(
'checked'
,
true
);
...
...
@@ -354,5 +352,6 @@ jumpserver.initDataTable = function (options) {
table
.
rows
().
deselect
();
}
});
return
table
;
};
apps/users/api.py
View file @
bd882c8b
...
...
@@ -30,9 +30,9 @@ class UserViewSet(BulkModelViewSet):
permission_classes
=
(
IsSuperUser
,)
class
User
AndGroupEdit
Api
(
generics
.
RetrieveUpdateAPIView
):
class
User
UpdateGroup
Api
(
generics
.
RetrieveUpdateAPIView
):
queryset
=
User
.
objects
.
all
()
serializer_class
=
serializers
.
User
And
GroupSerializer
serializer_class
=
serializers
.
User
Update
GroupSerializer
permission_classes
=
(
IsSuperUser
,)
...
...
@@ -72,7 +72,17 @@ class UserUpdatePKApi(generics.UpdateAPIView):
user
.
public_key
=
serializer
.
validated_data
[
'_public_key'
]
user
.
save
()
#
class
UserGroupViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
UserGroup
.
objects
.
all
()
serializer_class
=
serializers
.
UserGroupSerializer
class
UserGroupUpdateUserApi
(
generics
.
RetrieveUpdateAPIView
):
queryset
=
UserGroup
.
objects
.
all
()
serializer_class
=
serializers
.
UserGroupUpdateMemeberSerializer
permission_classes
=
(
IsSuperUser
,)
# class GroupDetailApi(generics.RetrieveUpdateDestroyAPIView):
# queryset = UserGroup.objects.all()
# serializer_class = serializers.GroupDetailSerializer
...
...
apps/users/serializers.py
View file @
bd882c8b
...
...
@@ -16,8 +16,7 @@ from .models import User, UserGroup
class
UserSerializer
(
BulkSerializerMixin
,
serializers
.
ModelSerializer
):
group_display
=
serializers
.
SerializerMethodField
()
active_display
=
serializers
.
SerializerMethodField
()
groups_display
=
serializers
.
SerializerMethodField
()
groups
=
serializers
.
PrimaryKeyRelatedField
(
many
=
True
,
queryset
=
UserGroup
.
objects
.
all
())
class
Meta
:
...
...
@@ -27,17 +26,16 @@ class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer):
def
get_field_names
(
self
,
declared_fields
,
info
):
fields
=
super
(
UserSerializer
,
self
)
.
get_field_names
(
declared_fields
,
info
)
fields
.
extend
([
'group
_display'
,
'get_role_display
'
])
fields
.
extend
([
'group
s_display'
,
'get_role_display'
,
'is_valid
'
])
return
fields
@staticmethod
def
get_group_display
(
obj
):
def
get_group
s
_display
(
obj
):
return
" "
.
join
([
group
.
name
for
group
in
obj
.
groups
.
all
()])
@staticmethod
def
get_active_display
(
obj
):
# TODO: user active state
return
not
(
obj
.
is_expired
and
obj
.
is_active
)
# @staticmethod
# def get_active_display(obj):
# return not (obj.is_expired and obj.is_active)
class
UserPKUpdateSerializer
(
serializers
.
ModelSerializer
):
...
...
@@ -54,7 +52,7 @@ class UserPKUpdateSerializer(serializers.ModelSerializer):
return
value
class
User
And
GroupSerializer
(
serializers
.
ModelSerializer
):
class
User
Update
GroupSerializer
(
serializers
.
ModelSerializer
):
groups
=
serializers
.
PrimaryKeyRelatedField
(
many
=
True
,
queryset
=
UserGroup
.
objects
.
all
())
class
Meta
:
...
...
@@ -62,6 +60,26 @@ class UserAndGroupSerializer(serializers.ModelSerializer):
fields
=
[
'id'
,
'groups'
]
class
UserGroupSerializer
(
BulkSerializerMixin
,
serializers
.
ModelSerializer
):
user_amount
=
serializers
.
SerializerMethodField
()
class
Meta
:
model
=
UserGroup
list_serializer_class
=
BulkListSerializer
@staticmethod
def
get_user_amount
(
obj
):
return
obj
.
users
.
count
()
class
UserGroupUpdateMemeberSerializer
(
serializers
.
ModelSerializer
):
users
=
serializers
.
PrimaryKeyRelatedField
(
many
=
True
,
queryset
=
User
.
objects
.
all
())
class
Meta
:
model
=
UserGroup
fields
=
[
'id'
,
'users'
]
# class GroupDetailSerializer(serializers.ModelSerializer):
# class Meta:
# model = UserGroup
...
...
apps/users/templates/users/user_detail.html
View file @
bd882c8b
...
...
@@ -224,9 +224,8 @@
jumpserver
.
selected_groups
=
{};
function
updateUserGroups
(
user_groups
)
{
var
the_url
=
"{% url 'users:
group-user-edit-api
' pk=user.id %}"
;
var
the_url
=
"{% url 'users:
api-user-update-group
' pk=user.id %}"
;
var
body
=
{
id
:
{{
user
.
id
}},
groups
:
Object
.
assign
([],
user_groups
)
};
var
success
=
function
(
data
)
{
...
...
@@ -245,13 +244,11 @@ function updateUserGroups(user_groups) {
});
// clear jumpserver.selected_groups
jumpserver
.
selected_groups
=
{};
toastr
.
success
(
'{% trans "UserGroup Update Success!" %}'
)
};
APIUpdateAttr
({
url
:
the_url
,
body
:
JSON
.
stringify
(
body
),
success
:
success
,
method
:
'PUT'
success
:
success
});
}
$
(
document
).
ready
(
function
()
{
...
...
apps/users/templates/users/user_group_detail.html
View file @
bd882c8b
This diff is collapsed.
Click to expand it.
apps/users/templates/users/user_group_list.html
View file @
bd882c8b
...
...
@@ -11,7 +11,6 @@
</th>
<th
class=
"text-center"
>
{% trans 'Name' %}
</th>
<th
class=
"text-center"
>
{% trans 'User Amount' %}
</th>
<th
class=
"text-center"
>
{% trans 'Asset Amount' %}
</th>
<th
class=
"text-center"
>
{% trans 'Comment' %}
</th>
<th
class=
"text-center"
>
{% trans 'Action' %}
</th>
</tr>
...
...
@@ -43,11 +42,11 @@ $(document).ready(function() {
var
detail_btn
=
'<a href="{% url "users:user-group-detail" pk=99991937 %}">'
+
cellData
+
'</a>'
;
$
(
td
).
html
(
detail_btn
.
replace
(
'99991937'
,
rowData
.
id
));
}},
{
targets
:
4
,
createdCell
:
function
(
td
,
cellData
)
{
var
innerHtml
=
cellData
.
length
>
18
?
cellData
.
substring
(
0
,
18
)
+
'...'
:
cellData
;
$
(
td
).
html
(
'<
a href="javascript:void(0);" data-toggle="tooltip" title="'
+
cellData
+
'">'
+
innerHtml
+
'</a
>'
);
{
targets
:
3
,
createdCell
:
function
(
td
,
cellData
)
{
var
innerHtml
=
cellData
.
length
>
30
?
cellData
.
substring
(
0
,
30
)
+
'...'
:
cellData
;
$
(
td
).
html
(
'<
span href="javascript:void(0);" data-toggle="tooltip" title="'
+
cellData
+
'">'
+
innerHtml
+
'</span
>'
);
}},
{
targets
:
5
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
{
targets
:
4
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
update_btn
=
'<a href="{% url "users:user-group-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_delete_user_group" data-uid="99991937">{% trans "Delete" %}</a>'
.
replace
(
'99991937'
,
cellData
);
if
(
rowData
.
id
===
1
)
{
...
...
@@ -56,9 +55,9 @@ $(document).ready(function() {
$
(
td
).
html
(
update_btn
+
del_btn
)
}
}}],
ajax_url
:
'{% url "users:
user-group-bulk-update-api
" %}'
,
ajax_url
:
'{% url "users:
api-user-group-list
" %}'
,
columns
:
[{
data
:
function
(){
return
""
}},
{
data
:
"name"
},
{
data
:
"user_amount"
},
{
data
:
function
(){
return
999
}},
{
data
:
"comment"
},
{
data
:
"id"
}],
{
data
:
"comment"
},
{
data
:
"id"
}],
op_html
:
$
(
'#actions'
).
html
()
};
jumpserver
.
initDataTable
(
options
);
...
...
@@ -66,7 +65,7 @@ $(document).ready(function() {
var
$this
=
$
(
this
);
function
doDelete
()
{
var
group_id
=
$this
.
data
(
'gid'
);
var
the_url
=
"{% url 'users:
user-group-detail-api'
99991937 %}"
.
replace
(
'99991937'
,
group_id
);
var
the_url
=
"{% url 'users:
api-user-group-detail' pk=
99991937 %}"
.
replace
(
'99991937'
,
group_id
);
var
body
=
{};
var
success
=
function
()
{
var
msg
=
"{% trans 'Group Deleted.' %}"
;
...
...
@@ -76,7 +75,7 @@ $(document).ready(function() {
var
fail
=
function
()
{
var
msg
=
"{% trans 'Group Deleting failed.' %}"
;
swal
(
"{% trans 'Group Delete' %}"
,
msg
,
"error"
);
}
}
;
APIUpdateAttr
({
url
:
the_url
,
body
:
JSON
.
stringify
(
body
),
...
...
@@ -105,8 +104,8 @@ $(document).ready(function() {
});
if
(
plain_id_list
===
[])
{
return
false
;
}
;
var
the_url
=
"{% url 'users:
user-group-bulk-update-api
' %}"
;
}
var
the_url
=
"{% url 'users:
api-user-group-list
' %}"
;
function
doDelete
()
{
swal
({
title
:
"{% trans 'Are you sure?' %}"
,
...
...
apps/users/templates/users/user_list.html
View file @
bd882c8b
...
...
@@ -15,7 +15,6 @@
<th
class=
"text-center"
>
{% trans 'Username' %}
</th>
<th
class=
"text-center"
>
{% trans 'Role' %}
</th>
<th
class=
"text-center"
>
{% trans 'User group' %}
</th>
<th
class=
"text-center"
>
{% trans 'Asset num' %}
</th>
<th
class=
"text-center"
>
{% trans 'Active' %}
</th>
<th
class=
"text-center"
>
{% trans 'Action' %}
</th>
</tr>
...
...
@@ -56,14 +55,14 @@ $(document).ready(function(){
var
innerHtml
=
cellData
.
length
>
20
?
cellData
.
substring
(
0
,
20
)
+
'...'
:
cellData
;
$
(
td
).
html
(
'<span href="javascript:void(0);" data-toggle="tooltip" title="'
+
cellData
+
'">'
+
innerHtml
+
'</span>'
);
}},
{
targets
:
6
,
createdCell
:
function
(
td
,
cellData
)
{
{
targets
:
5
,
createdCell
:
function
(
td
,
cellData
)
{
if
(
!
cellData
)
{
$
(
td
).
html
(
'<i class="fa fa-times text-danger"></i>'
)
}
else
{
$
(
td
).
html
(
'<i class="fa fa-check text-navy"></i>'
)
}
}},
{
targets
:
7
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
{
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
);
if
(
rowData
.
id
===
1
||
rowData
.
username
==
"admin"
)
{
...
...
@@ -73,8 +72,8 @@ $(document).ready(function(){
}
}}],
ajax_url
:
'{% url "users:api-user-list" %}'
,
columns
:
[{
data
:
function
(){
return
""
}},
{
data
:
"username"
},
{
data
:
"name"
},
{
data
:
"get_role_display"
},
{
data
:
"group_display"
},
{
data
:
function
(){
return
999
}},
{
data
:
"active_display
"
},
{
data
:
"id"
}],
columns
:
[{
data
:
function
(){
return
""
}},
{
data
:
"username"
},
{
data
:
"name"
},
{
data
:
"get_role_display"
},
{
data
:
"groups_display"
},
{
data
:
"is_valid
"
},
{
data
:
"id"
}],
op_html
:
$
(
'#actions'
).
html
()
};
jumpserver
.
initDataTable
(
options
);
...
...
@@ -224,6 +223,8 @@ $(document).ready(function(){
$form
.
ajaxSubmit
({
success
:
success
});
}).
on
(
'change'
,
'#id_excel'
,
function
()
{
$
(
this
).
siblings
(
'.help-block'
).
remove
();
}).
on
(
'click'
,
'.ipt_check'
,
function
()
{
console
.
log
(
'Hello'
)
})
</script>
{% endblock %}
...
...
apps/users/urls.py
View file @
bd882c8b
...
...
@@ -39,6 +39,7 @@ urlpatterns = [
router
=
BulkRouter
()
router
.
register
(
r'v1/users'
,
api
.
UserViewSet
,
'api-user'
)
router
.
register
(
r'v1/user-groups'
,
api
.
UserGroupViewSet
,
'api-user-group'
)
# router.register(r'v1/user-groups', api.AssetViewSet, 'api-groups')
...
...
@@ -53,7 +54,9 @@ urlpatterns += [
# url(r'^v1/user-groups/(?P<pk>\d+)/user/(?P<uid>\d+)/$',
# api.DeleteUserFromGroupApi.as_view(), name='delete-user-from-group-api'),
url
(
r'^v1/users/(?P<pk>\d+)/groups/$'
,
api
.
UserAndGroupEditApi
.
as_view
(),
name
=
'group-user-edit-api'
),
api
.
UserUpdateGroupApi
.
as_view
(),
name
=
'api-user-update-group'
),
url
(
r'^v1/user-groups/(?P<pk>\d+)/users/$'
,
api
.
UserGroupUpdateUserApi
.
as_view
(),
name
=
'api-user-group-update-user'
),
]
urlpatterns
+=
router
.
urls
apps/users/views.py
View file @
bd882c8b
...
...
@@ -216,10 +216,16 @@ class UserGroupUpdateView(AdminUserRequiredMixin, UpdateView):
class
UserGroupDetailView
(
AdminUserRequiredMixin
,
DetailView
):
model
=
UserGroup
context_object_name
=
'user_group'
template_name
=
'users/user_group_detail.html'
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Users'
),
'action'
:
_
(
'User Group Detail'
)}
users
=
User
.
objects
.
exclude
(
id__in
=
self
.
object
.
users
.
all
())
context
=
{
'app'
:
_
(
'Users'
),
'action'
:
_
(
'User Group Detail'
),
'users'
:
users
,
}
kwargs
.
update
(
context
)
return
super
(
UserGroupDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
...
...
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