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
2ec0ab87
Commit
2ec0ab87
authored
Apr 12, 2017
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix form bug
parent
695e4da8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
30 additions
and
113 deletions
+30
-113
api.py
apps/assets/api.py
+16
-0
forms.py
apps/assets/forms.py
+1
-1
user.py
apps/assets/models/user.py
+1
-0
asset_group_detail.html
apps/assets/templates/assets/asset_group_detail.html
+0
-0
api_urls.py
apps/assets/urls/api_urls.py
+3
-0
models.py
apps/ops/models.py
+4
-1
task_detail.html
apps/ops/templates/ops/task_detail.html
+1
-1
asset_permission_create_update.html
...perms/templates/perms/asset_permission_create_update.html
+2
-2
forms.py
apps/users/forms.py
+1
-1
_user_bulk_update_modal.html
apps/users/templates/users/_user_bulk_update_modal.html
+0
-72
user_list.html
apps/users/templates/users/user_list.html
+0
-35
requirements.txt
requirements/requirements.txt
+1
-0
No files found.
apps/assets/api.py
View file @
2ec0ab87
...
...
@@ -172,3 +172,19 @@ class AssetAdminUserTestView(AssetRefreshHardwareView):
return
Response
(
'1'
)
else
:
return
Response
(
'0'
,
status
=
502
)
class
AssetGroupPushSystemUserView
(
generics
.
UpdateAPIView
):
queryset
=
AssetGroup
.
objects
.
all
()
permission_classes
=
(
IsSuperUser
,)
def
patch
(
self
,
request
,
*
args
,
**
kwargs
):
asset_group
=
self
.
get_object
()
assets
=
asset_group
.
assets
.
all
()
system_user_id
=
self
.
request
.
data
[
'system_user'
]
system_user
=
get_object_or_none
(
SystemUser
,
id
=
system_user_id
)
if
not
assets
or
not
system_user
:
return
Response
(
'Invalid system user id or asset group id'
,
status
=
404
)
task
=
push_users
.
delay
([
asset
.
_to_secret_json
()
for
asset
in
assets
],
system_user
.
_to_secret_json
())
return
Response
(
task
.
id
)
apps/assets/forms.py
View file @
2ec0ab87
...
...
@@ -70,7 +70,7 @@ class AssetBulkUpdateForm(forms.ModelForm):
required
=
True
,
help_text
=
'* required'
,
label
=
_
(
'Select assets'
),
choices
=
[(
asset
.
id
,
asset
.
hostname
)
for
asset
in
Asset
.
objects
.
all
()],
#
choices=[(asset.id, asset.hostname) for asset in Asset.objects.all()],
widget
=
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
...
...
apps/assets/models/user.py
View file @
2ec0ab87
...
...
@@ -157,6 +157,7 @@ class SystemUser(models.Model):
def
__unicode__
(
self
):
return
self
.
name
__str__
=
__unicode__
@property
def
password
(
self
):
...
...
apps/assets/templates/assets/asset_group_detail.html
View file @
2ec0ab87
This diff is collapsed.
Click to expand it.
apps/assets/urls/api_urls.py
View file @
2ec0ab87
...
...
@@ -29,6 +29,9 @@ urlpatterns = [
url
(
r'^v1/assets/(?P<pk>\d+)/system-users/$'
,
api
.
SystemUserUpdateApi
.
as_view
(),
name
=
'asset-update-system-users'
),
url
(
r'^v1/asset-groups/(?P<pk>\d+)/push-system-user/$'
,
api
.
AssetGroupPushSystemUserView
.
as_view
(),
name
=
'asset-group-push-system-user'
),
# update the system users, which add and delete the asset to the system user
url
(
r'^v1/system_user/(?P<pk>\d+)/assets/$'
,
api
.
SystemUserUpdateAssetsApi
.
as_view
(),
name
=
'systemuser-update-assets'
),
...
...
apps/ops/models.py
View file @
2ec0ab87
...
...
@@ -7,6 +7,7 @@ import json
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
from
assets.models
import
Asset
__all__
=
[
"Task"
]
...
...
@@ -33,7 +34,9 @@ class Task(models.Model):
@property
def
total_assets
(
self
):
return
self
.
assets
.
split
(
','
)
assets_id
=
[
i
for
i
in
self
.
assets
.
split
(
','
)
if
i
.
isdigit
()]
assets
=
Asset
.
objects
.
filter
(
id__in
=
assets_id
)
return
assets
@property
def
assets_json
(
self
):
...
...
apps/ops/templates/ops/task_detail.html
View file @
2ec0ab87
...
...
@@ -85,7 +85,7 @@
<td>
<b>
{% for asset in object.total_assets %}
{{ asset
}}
<br/>
{{ asset.hostname
}}
<br/>
{% endfor %}
</b>
</td>
...
...
apps/perms/templates/perms/asset_permission_create_update.html
View file @
2ec0ab87
...
...
@@ -38,9 +38,9 @@
{% bootstrap_field form.user_groups layout="horizontal" %}
<div
class=
"hr-line-dashed"
></div>
<h3>
{% trans 'Asset' %}
</h3>
{
{ form.assets|bootstrap_horizontal|safe }
}
{
% bootstrap_field form.assets layout="horizontal" %
}
{% bootstrap_field form.asset_groups layout="horizontal" %}
{
{ form.system_users |bootstrap_horizontal }
}
{
% bootstrap_field form.system_users layout="horizontal" %
}
<div
class=
"hr-line-dashed"
></div>
<h3>
{% trans 'Other' %}
</h3>
<div
class=
"form-group"
>
...
...
apps/users/forms.py
View file @
2ec0ab87
...
...
@@ -123,7 +123,7 @@ class UserBulkUpdateForm(forms.ModelForm):
required
=
True
,
help_text
=
'* required'
,
label
=
_
(
'Select users'
),
choices
=
[(
user
.
id
,
user
.
name
)
for
user
in
User
.
objects
.
all
()],
# choices=[(user.id, user.name
) for user in User.objects.all()],
widget
=
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
...
...
apps/users/templates/users/_user_bulk_update_modal.html
deleted
100644 → 0
View file @
695e4da8
{% extends '_modal.html' %}
{% load i18n %}
{% load bootstrap3 %}
{% block modal_id %}user_bulk_update_modal{% endblock %}
{% block modal_class %}modal-lg{% endblock %}
{% block modal_title%}{% trans "Update selected user" %}{% endblock %}
{% block modal_body %}
{% block form %}
<div
class=
"ydxbd"
id=
"formlists"
style=
"display: block;"
>
<p
id=
"tags_p"
class=
"mgl-5 c02"
>
选择需要修改属性
</p>
<div
class=
"tagBtnList"
>
<a
class=
"label label-primary"
id=
"change_all"
value=
"1"
>
全选
</a>
{% for field in form %}
{# {% if field.name != 'assets' %}#}
<a
data-id=
"{{ field.id_for_label }}"
class=
"label label-default label-primary field-tag"
value=
"1"
>
{{ field.label }}
</a>
{# {% endif %}#}
{% endfor %}
</div>
</div>
<form
method=
"post"
class=
"form-horizontal"
id=
"add_form"
>
{% csrf_token %}
{% bootstrap_form form layout="horizontal" %}
<div
class=
"form-group abc"
>
<div
class=
"col-sm-4 col-sm-offset-2"
>
<button
class=
"btn btn-white"
type=
"reset"
>
{% trans 'Reset' %}
</button>
<button
class=
"btn btn-primary"
type=
"submit"
>
{% trans 'Submit' %}
</button>
</div>
</div>
</form>
{% endblock %}
{% endblock %}
{#{% block custom_foot_js %}#}
{#
<script>
#
}
{
#
$
(
document
).
ready
(
function
()
{
#
}
{
#
$
(
'.select2'
).
select2
();
#
}
{
#
}).
on
(
'click'
,
'.field-tag'
,
function
()
{
#
}
{
#
changeField
(
this
);
#
}
{
#
}).
on
(
'click'
,
'#change_all'
,
function
()
{
#
}
{
#
var
tag_fields
=
$
(
'.field-tag'
);
#
}
{
#
var
$this
=
$
(
this
);
#
}
{
#
var
active
=
'1'
;
#
}
{
#
if
(
$this
.
attr
(
'value'
)
==
'0'
){
#
}
{
#
active
=
'0'
;
#
}
{
#
$this
.
attr
(
'value'
,
'1'
).
addClass
(
'label-primary'
)
#
}
{
#
}
else
{
#
}
{
#
active
=
'1'
;
#
}
{
#
$this
.
attr
(
'value'
,
'0'
).
removeClass
(
'label-primary'
)
#
}
{
#
}
#
}
{
#
$
.
each
(
tag_fields
,
function
(
k
,
v
)
{
#
}
{
#
changeField
(
v
,
active
)
#
}
{
#
})
#
}
{
#
});
#
}
{
##
}
{
#
function
changeField
(
obj
,
active
)
{
#
}
{
#
var
$this
=
$
(
obj
);
#
}
{
#
var
field_id
=
$this
.
data
(
'id'
);
#
}
{
#
if
(
!
active
)
{
#
}
{
#
active
=
$this
.
attr
(
'value'
);
#
}
{
#
}
#
}
{
#
if
(
active
==
'0'
)
{
#
}
{
#
$this
.
attr
(
'value'
,
'1'
).
addClass
(
'label-primary'
);
#
}
{
#
var
form_groups
=
$
(
'#add_form .form-group:not(.abc)'
);
#
}
{
#
form_groups
.
filter
(
':has(#'
+
field_id
+
')'
).
show
().
find
(
'select,input'
).
prop
(
'disabled'
,
false
)
#
}
{
#
}
else
{
#
}
{
#
$this
.
attr
(
'value'
,
'0'
).
removeClass
(
'label-primary'
);
#
}
{
#
var
form_groups
=
$
(
'#add_form .form-group:not(.abc)'
);
#
}
{
#
form_groups
.
filter
(
':has(#'
+
field_id
+
')'
).
hide
().
find
(
'select,input'
).
prop
(
'disabled'
,
true
)
#
}
{
#
}
#
}
{
#
}
#
}
{
#
</script>
#}
{#{% endblock %}#}
apps/users/templates/users/user_list.html
View file @
2ec0ab87
...
...
@@ -48,7 +48,6 @@
</div>
</div>
</div>
{% include "users/_user_bulk_update_modal.html" %}
{% include "users/_user_import_modal.html" %}
{% endblock %}
{% block content_bottom_left %}{% endblock %}
...
...
@@ -235,40 +234,6 @@ $(document).ready(function(){
var
uid
=
$this
.
data
(
'uid'
);
var
the_url
=
'{% url "api-users:user-detail" pk=99991937 %}'
.
replace
(
'99991937'
,
uid
);
objectDelete
(
$this
,
name
,
the_url
);
}).
on
(
'click'
,
'#btn_user_bulk_update'
,
function
(){
var
json_data
=
$
(
'#fm_user_bulk_update'
).
serializeObject
();
var
body
=
{};
body
.
enable_otp
=
(
json_data
.
enable_otp
===
'on'
)?
true
:
false
;
if
(
json_data
.
role
!=
''
)
{
body
.
role
=
json_data
.
role
;
}
if
(
json_data
.
groups
!=
undefined
)
{
body
.
groups
=
json_data
.
groups
;
}
if
(
typeof
body
.
groups
===
'string'
)
{
body
.
groups
=
[
parseInt
(
body
.
groups
)]
}
else
if
(
typeof
body
.
groups
===
'array'
)
{
var
new_groups
=
body
.
groups
.
map
(
Number
);
body
.
groups
=
new_groups
;
}
var
$data_table
=
$
(
'#user_list_table'
).
DataTable
();
var
post_list
=
[];
$data_table
.
rows
({
selected
:
true
}).
every
(
function
(){
var
content
=
Object
.
assign
({
id
:
this
.
data
().
id
},
body
);
post_list
.
push
(
content
);
});
if
(
post_list
===
[])
{
return
false
}
var
the_url
=
"{% url 'api-users:user-list' %}"
;
var
success
=
function
()
{
var
msg
=
"{% trans 'The selected users has been updated successfully.' %}"
;
swal
(
"{% trans 'User Updated' %}"
,
msg
,
"success"
);
$
(
'#user_list_table'
).
DataTable
().
ajax
.
reload
();
jumpserver
.
checked
=
false
;
};
{
#
APIUpdateAttr
({
url
:
the_url
,
method
:
'PATCH'
,
body
:
JSON
.
stringify
(
post_list
),
success
:
success
});
#
}
$
(
'#user_bulk_update_modal'
).
modal
(
'hide'
);
})
</script>
{% endblock %}
...
...
requirements/requirements.txt
View file @
2ec0ab87
...
...
@@ -17,3 +17,4 @@ itsdangerous
eventlet
django-filter
passlib
ForgeryPy
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