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
72a82c41
Commit
72a82c41
authored
Jan 09, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改 success message, 添加资产组时可以添加资产
parent
450a9495
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
134 additions
and
310 deletions
+134
-310
forms.py
apps/assets/forms.py
+16
-11
asset.py
apps/assets/models/asset.py
+1
-1
signals_handler.py
apps/assets/signals_handler.py
+5
-4
asset_group_create.html
apps/assets/templates/assets/asset_group_create.html
+18
-107
admin_user.py
apps/assets/views/admin_user.py
+13
-22
asset.py
apps/assets/views/asset.py
+10
-4
cluster.py
apps/assets/views/cluster.py
+12
-7
group.py
apps/assets/views/group.py
+17
-26
system_user.py
apps/assets/views/system_user.py
+14
-28
const.py
apps/common/const.py
+8
-0
settings.py
apps/jumpserver/settings.py
+1
-0
django.mo
apps/locale/zh/LC_MESSAGES/django.mo
+0
-0
django.po
apps/locale/zh/LC_MESSAGES/django.po
+0
-0
views.py
apps/perms/views.py
+3
-57
user_group_create_update.html
apps/users/templates/users/user_group_create_update.html
+3
-15
group.py
apps/users/views/group.py
+6
-18
user.py
apps/users/views/user.py
+7
-10
No files found.
apps/assets/forms.py
View file @
72a82c41
...
...
@@ -124,20 +124,25 @@ class AssetGroupForm(forms.ModelForm):
label
=
_
(
'Asset'
),
required
=
False
,
widget
=
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select assets'
)}
)
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select assets'
)}
)
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
if
kwargs
.
get
(
'instance'
,
None
):
def
__init__
(
self
,
**
kwargs
):
instance
=
kwargs
.
get
(
'instance'
)
if
instance
:
initial
=
kwargs
.
get
(
'initial'
,
{})
initial
[
'assets'
]
=
kwargs
[
'instance'
]
.
assets
.
all
()
super
(
AssetGroupForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
def
_save_m2m
(
self
):
super
(
AssetGroupForm
,
self
)
.
_save_m2m
()
assets
=
self
.
cleaned_data
[
'assets'
]
self
.
instance
.
assets
.
clear
()
self
.
instance
.
assets
.
add
(
*
tuple
(
assets
))
initial
.
update
({
'assets'
:
instance
.
assets
.
all
(),
})
kwargs
[
'initial'
]
=
initial
super
()
.
__init__
(
**
kwargs
)
def
save
(
self
,
commit
=
True
):
group
=
super
()
.
save
(
commit
=
commit
)
assets
=
self
.
cleaned_data
[
'assets'
]
group
.
assets
.
set
(
assets
)
return
group
class
Meta
:
model
=
AssetGroup
...
...
apps/assets/models/asset.py
View file @
72a82c41
...
...
@@ -44,7 +44,7 @@ class Asset(models.Model):
hostname
=
models
.
CharField
(
max_length
=
128
,
unique
=
True
,
verbose_name
=
_
(
'Hostname'
))
port
=
models
.
IntegerField
(
default
=
22
,
verbose_name
=
_
(
'Port'
))
groups
=
models
.
ManyToManyField
(
AssetGroup
,
blank
=
True
,
related_name
=
'assets'
,
verbose_name
=
_
(
'Asset groups'
))
cluster
=
models
.
ForeignKey
(
Cluster
,
blank
=
True
,
null
=
True
,
related_name
=
'assets'
,
on_delete
=
models
.
SET_NULL
,
verbose_name
=
_
(
'Cluster'
))
cluster
=
models
.
ForeignKey
(
Cluster
,
related_name
=
'assets'
,
on_delete
=
models
.
PROTECT
,
verbose_name
=
_
(
'Cluster'
))
is_active
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
_
(
'Is active'
))
type
=
models
.
CharField
(
choices
=
TYPE_CHOICES
,
max_length
=
16
,
blank
=
True
,
null
=
True
,
default
=
'Server'
,
verbose_name
=
_
(
'Asset type'
),)
env
=
models
.
CharField
(
choices
=
ENV_CHOICES
,
max_length
=
8
,
blank
=
True
,
null
=
True
,
default
=
'Prod'
,
verbose_name
=
_
(
'Asset environment'
),)
...
...
apps/assets/signals_handler.py
View file @
72a82c41
...
...
@@ -27,10 +27,11 @@ def test_asset_conn_on_created(asset):
def
push_cluster_system_users_to_asset
(
asset
):
logger
.
info
(
"Push cluster system user to asset: {}"
.
format
(
asset
))
task_name
=
_
(
"Push cluster system users to asset"
)
system_users
=
asset
.
cluster
.
systemuser_set
.
all
()
push_system_user_util
.
delay
(
system_users
,
[
asset
],
task_name
)
if
asset
.
cluster
:
logger
.
info
(
"Push cluster system user to asset: {}"
.
format
(
asset
))
task_name
=
_
(
"Push cluster system users to asset"
)
system_users
=
asset
.
cluster
.
systemuser_set
.
all
()
push_system_user_util
.
delay
(
system_users
,
[
asset
],
task_name
)
@receiver
(
post_save
,
sender
=
Asset
,
dispatch_uid
=
"my_unique_identifier"
)
...
...
apps/assets/templates/assets/asset_group_create.html
View file @
72a82c41
{% extends 'base.html' %}
{% load i18n %}
{% extends '_base_create_update.html' %}
{% load static %}
{% load bootstrap3 %}
{% block custom_head_css_js %}
<link
href=
"{% static 'css/plugins/select2/select2.min.css' %}"
rel=
"stylesheet"
>
<script
src=
"{% static 'js/plugins/select2/select2.full.min.js' %}"
></script>
{% endblock %}
{% block content %}
<div
class=
"wrapper wrapper-content animated fadeInRight"
>
<div
class=
"row"
>
<div
class=
"col-sm-10"
>
<div
class=
"ibox float-e-margins"
>
<div
id=
"ibox-content"
class=
"ibox-title"
>
<h5>
{{ action }}
</h5>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
{% load i18n %}
<div
class=
"ibox-content"
>
<div
class=
"panel blank-panel"
>
<div
class=
"panel-body"
>
<div
class=
"tab-content"
>
<form
id=
"groupForm"
method=
"post"
class=
"form-horizontal"
>
{% csrf_token %}
<h3
class=
"widget-head-color-box"
>
资产组信息
</h3>
{% bootstrap_field form.name layout="horizontal" %}
{% bootstrap_field form.comment layout="horizontal" %}
{#
<div
class=
"hr-line-dashed"
></div>
#}
{#
<h3
class=
"widget-head-color-box"
>
用户选择的资产
</h3>
#}
{#
<div
class=
"form-group"
>
#}
{#
<label
class=
"col-sm-2 control-label"
id=
"asset_on_count"
>
已选({{ assets_count }})
</label>
#}
{#
<div
class=
"col-sm-9"
id=
"asset_sed"
>
#}
{#
<div
class=
"form-asset-on"
id=
"add_asset"
>
#}
{#
<p
id=
"asset_on_p"
>
#}
{# {% for asset in assets_on_list %}#}
{#
<button
name=
'asset_hostname'
title=
'{{ asset.ip }}'
type=
'button'
class=
'btn btn-default btn-xs'
>
{{ asset.hostname }}
</button>
#}
{# {% endfor %}#}
{#
</p>
#}
{#
</div>
#}
{#
</div>
#}
{#
</div>
#}
<div
class=
"hr-line-dashed"
></div>
<div
class=
"form-group"
>
<div
class=
"col-sm-4 col-sm-offset-5"
>
<button
class=
"btn btn-white"
type=
"reset"
>
重置
</button>
<button
class=
"btn btn-primary"
type=
"submit"
>
提交
</button>
<div
id=
'box2'
>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% block form %}
<form
id=
"groupForm"
method=
"post"
class=
"form-horizontal"
>
{% csrf_token %}
{% bootstrap_field form.name layout="horizontal" %}
{% bootstrap_field form.assets layout="horizontal" %}
{% bootstrap_field form.comment layout="horizontal" %}
<div
class=
"hr-line-dashed"
></div>
<div
class=
"form-group"
>
<div
class=
"col-sm-4 col-sm-offset-2"
>
<button
class=
"btn btn-default"
type=
"reset"
>
{% trans 'Reset' %}
</button>
<button
id=
"submit_button"
class=
"btn btn-primary"
type=
"submit"
>
{% trans 'Submit' %}
</button>
</div>
</div>
</div>
<!-- 模态框(Modal) -->
<div
class=
"modal fade"
id=
"modal"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"myModalLabel"
aria-hidden=
"true"
>
<div
class=
"modal-dialog modal-lg"
>
<div
class=
"modal-content"
id=
"box"
>
<!--此部分为主体内容,将远程加载进来-->
</div>
</div>
</div>
</form>
{% endblock %}
{% block custom_foot_js %}
<script
type=
"text/javascript"
>
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
();
$
(
'.select2-system-user'
).
select2
();
});
$
(
'#add_asset'
).
on
(
'click'
,
function
(){
$
(
'#modal'
).
modal
(
'show'
);
});
$
(
'#modal'
).
modal
({
show
:
false
,
backdrop
:
'static'
,
keyboard
:
'false'
,
remote
:
"{% url 'assets:asset-modal-list' %}?group_id={{ group_id }}"
});
$
(
'#modal'
).
on
(
'show.bs.modal'
,
function
(){
//alert('当调用show方法时,立即触发;')
$
(
'.select2'
).
select2
({
closeOnSelect
:
false
});
});
$
(
'#modal'
).
on
(
'shown.bs.modal'
,
function
(){
//alert('当弹窗完全加载完后,再触发;')
});
$
(
'#modal'
).
on
(
'hide.bs.modal'
,
function
(){
//alert('当关闭时,立即触发;')
});
$
(
'#modal'
).
on
(
'hidden.bs.modal'
,
function
(){
//alert('当关完全关闭后,再触发;')
});
$
(
'#modal'
).
on
(
'loaded.bs.modal'
,
function
(){
//alert('当远程数据加载完毕后,再触发;')
});
</script>
{% endblock %}
\ No newline at end of file
apps/assets/views/admin_user.py
View file @
72a82c41
...
...
@@ -2,20 +2,22 @@
from
__future__
import
absolute_import
,
unicode_literals
from
django.utils.translation
import
ugettext
as
_
from
django.conf
import
settings
from
django.views.generic
import
TemplateView
,
ListView
,
View
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
FormView
,
UpdateView
from
django.urls
import
reverse_lazy
from
django.views.generic
import
TemplateView
,
ListView
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
UpdateView
from
django.contrib.messages.views
import
SuccessMessageMixin
from
django.views.generic.detail
import
DetailView
,
SingleObjectMixin
from
common.const
import
create_success_msg
,
update_success_msg
from
..
import
forms
from
..models
import
A
sset
,
AssetGroup
,
AdminUser
,
Cluster
,
SystemUs
er
from
..models
import
A
dminUser
,
Clust
er
from
..hands
import
AdminUserRequiredMixin
__all__
=
[
'AdminUserCreateView'
,
'AdminUserDetailView'
,
'AdminUserDeleteView'
,
'AdminUserListView'
,
'AdminUserUpdateView'
,
'AdminUserAssetsView'
,
]
__all__
=
[
'AdminUserCreateView'
,
'AdminUserDetailView'
,
'AdminUserDeleteView'
,
'AdminUserListView'
,
'AdminUserUpdateView'
,
'AdminUserAssetsView'
,
]
class
AdminUserListView
(
AdminUserRequiredMixin
,
TemplateView
):
...
...
@@ -38,6 +40,7 @@ class AdminUserCreateView(AdminUserRequiredMixin,
form_class
=
forms
.
AdminUserForm
template_name
=
'assets/admin_user_create_update.html'
success_url
=
reverse_lazy
(
'assets:admin-user-list'
)
success_message
=
create_success_msg
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
...
...
@@ -47,20 +50,13 @@ class AdminUserCreateView(AdminUserRequiredMixin,
kwargs
.
update
(
context
)
return
super
()
.
get_context_data
(
**
kwargs
)
def
get_success_message
(
self
,
cleaned_data
):
success_message
=
_
(
'Create admin user <a href="{url}">{name}</a> successfully.'
.
format
(
url
=
reverse_lazy
(
'assets:admin-user-detail'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
}),
name
=
self
.
object
.
name
,
))
return
success_message
class
AdminUserUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
class
AdminUserUpdateView
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
UpdateView
):
model
=
AdminUser
form_class
=
forms
.
AdminUserForm
template_name
=
'assets/admin_user_create_update.html'
success_url
=
reverse_lazy
(
'assets:admin-user-list'
)
success_message
=
update_success_msg
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
...
...
@@ -70,11 +66,6 @@ class AdminUserUpdateView(AdminUserRequiredMixin, UpdateView):
kwargs
.
update
(
context
)
return
super
()
.
get_context_data
(
**
kwargs
)
def
get_success_url
(
self
):
success_url
=
reverse_lazy
(
'assets:admin-user-detail'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
})
return
success_url
class
AdminUserDetailView
(
AdminUserRequiredMixin
,
DetailView
):
model
=
AdminUser
...
...
apps/assets/views/asset.py
View file @
72a82c41
...
...
@@ -21,10 +21,11 @@ from django.core.cache import cache
from
django.utils
import
timezone
from
django.contrib.auth.mixins
import
LoginRequiredMixin
from
django.shortcuts
import
redirect
from
django.contrib.messages.views
import
SuccessMessageMixin
from
common.mixins
import
JSONResponseMixin
from
common.utils
import
get_object_or_none
,
get_logger
,
is_uuid
from
common.const
import
create_success_msg
,
update_success_msg
from
..
import
forms
from
..models
import
Asset
,
AssetGroup
,
AdminUser
,
Cluster
,
SystemUser
from
..hands
import
AdminUserRequiredMixin
...
...
@@ -46,7 +47,6 @@ class AssetListView(AdminUserRequiredMixin, TemplateView):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Asset list'
),
# 'groups': AssetGroup.objects.all(),
'system_users'
:
SystemUser
.
objects
.
all
(),
}
kwargs
.
update
(
context
)
...
...
@@ -66,7 +66,7 @@ class UserAssetListView(LoginRequiredMixin, TemplateView):
return
super
()
.
get_context_data
(
**
kwargs
)
class
AssetCreateView
(
AdminUserRequiredMixin
,
CreateView
):
class
AssetCreateView
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
model
=
Asset
form_class
=
forms
.
AssetCreateForm
template_name
=
'assets/asset_create.html'
...
...
@@ -87,6 +87,9 @@ class AssetCreateView(AdminUserRequiredMixin, CreateView):
kwargs
.
update
(
context
)
return
super
()
.
get_context_data
(
**
kwargs
)
def
get_success_message
(
self
,
cleaned_data
):
return
create_success_msg
%
({
"name"
:
cleaned_data
[
"hostname"
]})
class
AssetModalListView
(
AdminUserRequiredMixin
,
ListView
):
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
...
...
@@ -147,7 +150,7 @@ class AssetBulkUpdateView(AdminUserRequiredMixin, ListView):
return
super
()
.
get_context_data
(
**
kwargs
)
class
AssetUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
class
AssetUpdateView
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
UpdateView
):
model
=
Asset
form_class
=
forms
.
AssetUpdateForm
template_name
=
'assets/asset_update.html'
...
...
@@ -161,6 +164,9 @@ class AssetUpdateView(AdminUserRequiredMixin, UpdateView):
kwargs
.
update
(
context
)
return
super
()
.
get_context_data
(
**
kwargs
)
def
get_success_message
(
self
,
cleaned_data
):
return
update_success_msg
%
({
"name"
:
cleaned_data
[
"hostname"
]})
class
AssetDeleteView
(
AdminUserRequiredMixin
,
DeleteView
):
model
=
Asset
...
...
apps/assets/views/cluster.py
View file @
72a82c41
# coding:utf-8
from
__future__
import
absolute_import
,
unicode_literals
from
django.utils.translation
import
ugettext
as
_
from
django.views.generic
import
TemplateView
,
ListView
,
View
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
FormView
,
UpdateView
from
django.urls
import
reverse_lazy
from
django.views.generic.detail
import
DetailView
,
SingleObjectMixin
from
django.contrib.messages.views
import
SuccessMessageMixin
from
common.const
import
create_success_msg
,
update_success_msg
from
..
import
forms
from
..models
import
Asset
,
AssetGroup
,
AdminUser
,
Cluster
,
SystemUser
from
..hands
import
AdminUserRequiredMixin
__all__
=
[
'ClusterListView'
,
'ClusterCreateView'
,
'ClusterUpdateView'
,
'ClusterDetailView'
,
'ClusterDeleteView'
,
'ClusterAssetsView'
]
__all__
=
[
'ClusterListView'
,
'ClusterCreateView'
,
'ClusterUpdateView'
,
'ClusterDetailView'
,
'ClusterDeleteView'
,
'ClusterAssetsView'
,
]
class
ClusterListView
(
AdminUserRequiredMixin
,
TemplateView
):
...
...
@@ -21,17 +25,17 @@ class ClusterListView(AdminUserRequiredMixin, TemplateView):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Cluster list'
),
# 'keyword': self.request.GET.get('keyword', '')
}
kwargs
.
update
(
context
)
return
super
()
.
get_context_data
(
**
kwargs
)
class
ClusterCreateView
(
AdminUserRequiredMixin
,
CreateView
):
class
ClusterCreateView
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
model
=
Cluster
form_class
=
forms
.
ClusterForm
template_name
=
'assets/cluster_create_update.html'
success_url
=
reverse_lazy
(
'assets:cluster-list'
)
success_message
=
create_success_msg
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
...
...
@@ -43,17 +47,18 @@ class ClusterCreateView(AdminUserRequiredMixin, CreateView):
def
form_valid
(
self
,
form
):
cluster
=
form
.
save
(
commit
=
False
)
cluster
.
created_by
=
self
.
request
.
user
.
username
or
'System'
cluster
.
created_by
=
self
.
request
.
user
.
username
cluster
.
save
()
return
super
()
.
form_valid
(
form
)
class
ClusterUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
class
ClusterUpdateView
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
UpdateView
):
model
=
Cluster
form_class
=
forms
.
ClusterForm
template_name
=
'assets/cluster_create_update.html'
context_object_name
=
'cluster'
success_url
=
reverse_lazy
(
'assets:cluster-list'
)
success_message
=
update_success_msg
def
form_valid
(
self
,
form
):
cluster
=
form
.
save
(
commit
=
False
)
...
...
apps/assets/views/group.py
View file @
72a82c41
...
...
@@ -7,42 +7,41 @@ from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateVi
from
django.urls
import
reverse_lazy
from
django.views.generic.detail
import
DetailView
,
SingleObjectMixin
from
django.shortcuts
import
get_object_or_404
,
reverse
,
redirect
from
django.contrib.messages.views
import
SuccessMessageMixin
from
common.const
import
create_success_msg
,
update_success_msg
from
..
import
forms
from
..models
import
Asset
,
AssetGroup
,
AdminUser
,
Cluster
,
SystemUser
from
..hands
import
AdminUserRequiredMixin
__all__
=
[
'AssetGroupCreateView'
,
'AssetGroupDetailView'
,
'AssetGroupUpdateView'
,
'AssetGroupListView'
,
'AssetGroupDeleteView'
,
]
__all__
=
[
'AssetGroupCreateView'
,
'AssetGroupDetailView'
,
'AssetGroupUpdateView'
,
'AssetGroupListView'
,
'AssetGroupDeleteView'
,
]
class
AssetGroupCreateView
(
AdminUserRequiredMixin
,
CreateView
):
class
AssetGroupCreateView
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
model
=
AssetGroup
form_class
=
forms
.
AssetGroupForm
template_name
=
'assets/asset_group_create.html'
success_url
=
reverse_lazy
(
'assets:asset-group-list'
)
success_message
=
create_success_msg
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Create asset group'
),
'assets_count'
:
0
,
}
kwargs
.
update
(
context
)
return
super
(
AssetGroupCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
return
super
()
.
get_context_data
(
**
kwargs
)
def
form_valid
(
self
,
form
):
asset_group
=
form
.
save
()
assets_id_list
=
self
.
request
.
POST
.
getlist
(
'assets'
,
[])
assets
=
[
get_object_or_404
(
Asset
,
id
=
int
(
asset_id
))
for
asset_id
in
assets_id_list
]
asset_group
.
created_by
=
self
.
request
.
user
.
username
or
'Admin'
asset_group
.
assets
.
add
(
*
tuple
(
assets
))
asset_group
.
save
()
return
super
(
AssetGroupCreateView
,
self
)
.
form_valid
(
form
)
group
=
form
.
save
()
group
.
created_by
=
self
.
request
.
user
.
username
group
.
save
()
return
super
()
.
form_valid
(
form
)
class
AssetGroupListView
(
AdminUserRequiredMixin
,
TemplateView
):
...
...
@@ -54,7 +53,6 @@ class AssetGroupListView(AdminUserRequiredMixin, TemplateView):
'action'
:
_
(
'Asset group list'
),
'assets'
:
Asset
.
objects
.
all
(),
'system_users'
:
SystemUser
.
objects
.
all
(),
'keyword'
:
self
.
request
.
GET
.
get
(
'keyword'
,
''
)
}
kwargs
.
update
(
context
)
return
super
(
AssetGroupListView
,
self
)
.
get_context_data
(
**
kwargs
)
...
...
@@ -77,27 +75,20 @@ class AssetGroupDetailView(AdminUserRequiredMixin, DetailView):
return
super
()
.
get_context_data
(
**
kwargs
)
class
AssetGroupUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
class
AssetGroupUpdateView
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
UpdateView
):
model
=
AssetGroup
form_class
=
forms
.
AssetGroupForm
template_name
=
'assets/asset_group_create.html'
success_url
=
reverse_lazy
(
'assets:asset-group-list'
)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
(
queryset
=
AssetGroup
.
objects
.
all
())
return
super
(
AssetGroupUpdateView
,
self
)
.
get
(
request
,
*
args
,
**
kwargs
)
success_message
=
update_success_msg
def
get_context_data
(
self
,
**
kwargs
):
assets_all
=
self
.
object
.
assets
.
all
()
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Create asset group'
),
'assets_on_list'
:
assets_all
,
'assets_count'
:
len
(
assets_all
),
'group_id'
:
self
.
object
.
id
,
}
kwargs
.
update
(
context
)
return
super
(
AssetGroupUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
return
super
()
.
get_context_data
(
**
kwargs
)
class
AssetGroupDeleteView
(
AdminUserRequiredMixin
,
DeleteView
):
...
...
apps/assets/views/system_user.py
View file @
72a82c41
# ~*~ coding: utf-8 ~*~
from
django.contrib
import
messages
from
django.shortcuts
import
redirect
,
reverse
from
django.shortcuts
import
reverse
from
django.utils.translation
import
ugettext
as
_
from
django.db
import
transaction
from
django.views.generic
import
TemplateView
,
ListView
,
FormView
from
django.views.generic
import
TemplateView
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
UpdateView
from
django.urls
import
reverse_lazy
from
django.contrib.messages.views
import
SuccessMessageMixin
from
django.views.generic.detail
import
DetailView
,
SingleObjectMixin
from
django.views.generic.detail
import
DetailView
from
..forms
import
SystemUserForm
,
SystemUserUpdateForm
,
SystemUserAuthForm
from
common.const
import
create_success_msg
,
update_success_msg
from
..forms
import
SystemUserForm
,
SystemUserUpdateForm
from
..models
import
SystemUser
,
Cluster
from
..hands
import
AdminUserRequiredMixin
__all__
=
[
'SystemUserCreateView'
,
'SystemUserUpdateView'
,
'SystemUserDetailView'
,
'SystemUserDeleteView'
,
'SystemUserAssetView'
,
'SystemUserListView'
,
]
__all__
=
[
'SystemUserCreateView'
,
'SystemUserUpdateView'
,
'SystemUserDetailView'
,
'SystemUserDeleteView'
,
'SystemUserAssetView'
,
'SystemUserListView'
,
]
class
SystemUserListView
(
AdminUserRequiredMixin
,
TemplateView
):
...
...
@@ -38,10 +39,7 @@ class SystemUserCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateVi
form_class
=
SystemUserForm
template_name
=
'assets/system_user_create.html'
success_url
=
reverse_lazy
(
'assets:system-user-list'
)
@transaction.atomic
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
return
super
(
SystemUserCreateView
,
self
)
.
post
(
request
,
*
args
,
**
kwargs
)
success_message
=
create_success_msg
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
...
...
@@ -51,20 +49,13 @@ class SystemUserCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateVi
kwargs
.
update
(
context
)
return
super
()
.
get_context_data
(
**
kwargs
)
def
get_success_message
(
self
,
cleaned_data
):
url
=
reverse
(
'assets:system-user-detail'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
})
success_message
=
_
(
'Create system user <a href="{url}">{name}</a> '
'successfully.'
.
format
(
url
=
url
,
name
=
self
.
object
.
name
)
)
return
success_message
class
SystemUserUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
class
SystemUserUpdateView
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
UpdateView
):
model
=
SystemUser
form_class
=
SystemUserUpdateForm
template_name
=
'assets/system_user_update.html'
success_url
=
reverse_lazy
(
'assets:system-user-list'
)
success_message
=
update_success_msg
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
...
...
@@ -74,11 +65,6 @@ class SystemUserUpdateView(AdminUserRequiredMixin, UpdateView):
kwargs
.
update
(
context
)
return
super
()
.
get_context_data
(
**
kwargs
)
def
get_success_url
(
self
):
success_url
=
reverse_lazy
(
'assets:system-user-detail'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
})
return
success_url
class
SystemUserDetailView
(
AdminUserRequiredMixin
,
DetailView
):
template_name
=
'assets/system_user_detail.html'
...
...
apps/common/const.py
0 → 100644
View file @
72a82c41
# -*- coding: utf-8 -*-
#
from
django.utils.translation
import
ugettext
as
_
create_success_msg
=
_
(
"<b>
%(name)
s</b> was created successfully"
)
update_success_msg
=
_
(
"<b>
%(name)
s</b> was updated successfully"
)
\ No newline at end of file
apps/jumpserver/settings.py
View file @
72a82c41
...
...
@@ -374,4 +374,5 @@ BOOTSTRAP3 = {
'horizontal_field_class'
:
'col-md-9'
,
# Set placeholder attributes to label if no placeholder is provided
'set_placeholder'
:
True
,
'success_css_class'
:
''
,
}
apps/locale/zh/LC_MESSAGES/django.mo
View file @
72a82c41
No preview for this file type
apps/locale/zh/LC_MESSAGES/django.po
View file @
72a82c41
This diff is collapsed.
Click to expand it.
apps/perms/views.py
View file @
72a82c41
...
...
@@ -11,6 +11,7 @@ from django.contrib.messages.views import SuccessMessageMixin
from
django.views.generic.detail
import
DetailView
,
SingleObjectMixin
from
django.contrib
import
messages
from
common.const
import
create_success_msg
,
update_success_msg
from
.hands
import
AdminUserRequiredMixin
,
User
,
UserGroup
,
SystemUser
,
\
Asset
,
AssetGroup
from
.models
import
AssetPermission
...
...
@@ -31,46 +32,12 @@ class AssetPermissionListView(AdminUserRequiredMixin, ListView):
return
super
()
.
get_context_data
(
**
kwargs
)
class
MessageMixin
:
def
form_valid
(
self
,
form
):
response
=
super
()
.
form_valid
(
form
)
errors
=
self
.
object
.
check_system_user_in_assets
()
if
errors
:
message
=
self
.
get_warning_messages
(
errors
)
messages
.
warning
(
self
.
request
,
message
)
else
:
message
=
self
.
get_success_message
(
form
.
cleaned_data
)
messages
.
success
(
self
.
request
,
message
)
success_message
=
self
.
get_success_message
(
form
.
cleaned_data
)
if
success_message
:
messages
.
success
(
self
.
request
,
success_message
)
return
response
@staticmethod
def
get_warning_messages
(
errors
):
message
=
"<b><i class='fa fa-warning'></i>WARNING: System user "
\
"should in behind clusters, so that "
\
"system user cat auto push to the cluster assets:</b> <br>"
for
system_user
,
clusters
in
errors
.
items
():
message
+=
" >>> {}: {} "
.
format
(
system_user
.
name
,
", "
.
join
((
cluster
.
name
for
cluster
in
clusters
)))
return
message
def
get_success_message
(
self
,
cleaned_data
):
url
=
reverse_lazy
(
'perms:asset-permission-detail'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
})
success_message
=
_
(
'Create asset permission <a href="{url}"> {name} </a> '
'successfully.'
.
format
(
url
=
url
,
name
=
self
.
object
.
name
))
return
success_message
class
AssetPermissionCreateView
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
model
=
AssetPermission
form_class
=
AssetPermissionForm
template_name
=
'perms/asset_permission_create_update.html'
success_url
=
reverse_lazy
(
'perms:asset-permission-list'
)
warning
=
None
success_message
=
create_success_msg
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
...
...
@@ -80,23 +47,13 @@ class AssetPermissionCreateView(AdminUserRequiredMixin, SuccessMessageMixin, Cre
kwargs
.
update
(
context
)
return
super
()
.
get_context_data
(
**
kwargs
)
def
get_success_message
(
self
,
cleaned_data
):
url
=
reverse_lazy
(
'perms:asset-permission-detail'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
}
)
success_message
=
_
(
'Create asset permission <a href="{url}"> {name} </a> '
'success.'
.
format
(
url
=
url
,
name
=
self
.
object
.
name
)
)
return
success_message
class
AssetPermissionUpdateView
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
UpdateView
):
model
=
AssetPermission
form_class
=
AssetPermissionForm
template_name
=
'perms/asset_permission_create_update.html'
success_url
=
reverse_lazy
(
"perms:asset-permission-list"
)
success_message
=
update_success_msg
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
...
...
@@ -106,17 +63,6 @@ class AssetPermissionUpdateView(AdminUserRequiredMixin, SuccessMessageMixin, Upd
kwargs
.
update
(
context
)
return
super
()
.
get_context_data
(
**
kwargs
)
def
get_success_message
(
self
,
cleaned_data
):
url
=
reverse_lazy
(
'perms:asset-permission-detail'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
}
)
success_message
=
_
(
'Update asset permission <a href="{url}"> {name} </a> '
'success.'
.
format
(
url
=
url
,
name
=
self
.
object
.
name
)
)
return
success_message
class
AssetPermissionDetailView
(
AdminUserRequiredMixin
,
DetailView
):
template_name
=
'perms/asset_permission_detail.html'
...
...
apps/users/templates/users/user_group_create_update.html
View file @
72a82c41
...
...
@@ -25,20 +25,6 @@
{% csrf_token %}
{% bootstrap_field form.name layout="horizontal" %}
{% bootstrap_field form.users layout="horizontal" %}
{#
<div
class=
"form-group"
>
#}
{#
<label
for=
"users"
class=
"col-sm-2 control-label"
>
{% trans 'Users' %}
</label>
#}
{#
<div
class=
"col-sm-9"
>
#}
{#
<select
name=
"users"
id=
"id_users"
data-placeholder=
"{% trans 'Select User' %}"
class=
"select2 form-control m-b"
multiple
tabindex=
"2"
>
#}
{# {% for user in users %}#}
{# {% if user.id in group_users %}#}
{#
<option
value=
"{{ user.id }}"
selected
>
{{ user.name }}
</option>
#}
{# {% else %}#}
{#
<option
value=
"{{ user.id }}"
>
{{ user.name }}
</option>
#}
{# {% endif %}#}
{# {% endfor %}#}
{#
</select>
#}
{#
</div>
#}
{#
</div>
#}
{% bootstrap_field form.comment layout="horizontal" %}
<div
class=
"form-group"
>
<div
class=
"col-sm-4 col-sm-offset-2"
>
...
...
@@ -57,7 +43,9 @@
{% block custom_foot_js %}
<script>
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
();
$
(
'.select2'
).
select2
({
closeOnSelect
:
false
});
})
</script>
{% endblock %}
apps/users/views/group.py
View file @
72a82c41
...
...
@@ -2,17 +2,15 @@
from
__future__
import
unicode_literals
from
django
import
forms
from
django.shortcuts
import
reverse
,
redirect
from
django.utils.translation
import
ugettext
as
_
from
django.urls
import
reverse_lazy
from
django.views.generic
import
ListView
from
django.views.generic.base
import
TemplateView
from
django.views.generic.edit
import
CreateView
,
UpdateView
,
FormMixin
from
django.views.generic.detail
import
DetailView
,
SingleObjectMixin
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
django.views.generic.detail
import
DetailView
from
django.contrib.messages.views
import
SuccessMessageMixin
from
common.utils
import
get_logger
from
perms.models
import
AssetPermission
from
common.const
import
create_success_msg
,
update_success_msg
from
..models
import
User
,
UserGroup
from
..utils
import
AdminUserRequiredMixin
from
..
import
forms
...
...
@@ -39,9 +37,7 @@ class UserGroupCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateVie
form_class
=
forms
.
UserGroupForm
template_name
=
'users/user_group_create_update.html'
success_url
=
reverse_lazy
(
'users:user-group-list'
)
success_message
=
_
(
'User group <a href={url}> {name} </a> was created successfully'
)
success_message
=
create_success_msg
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
...
...
@@ -51,21 +47,13 @@ class UserGroupCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateVie
kwargs
.
update
(
context
)
return
super
()
.
get_context_data
(
**
kwargs
)
def
get_success_message
(
self
,
cleaned_data
):
url
=
reverse_lazy
(
'users:user-group-detail'
,
kwargs
=
{
'pk'
:
self
.
object
.
id
}
)
return
self
.
success_message
.
format
(
url
=
url
,
name
=
self
.
object
.
name
)
class
UserGroupUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
class
UserGroupUpdateView
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
UpdateView
):
model
=
UserGroup
form_class
=
forms
.
UserGroupForm
template_name
=
'users/user_group_create_update.html'
success_url
=
reverse_lazy
(
'users:user-group-list'
)
success_message
=
update_success_msg
def
get_context_data
(
self
,
**
kwargs
):
users
=
User
.
objects
.
all
()
...
...
apps/users/views/user.py
View file @
72a82c41
...
...
@@ -27,12 +27,14 @@ from django.views.generic.detail import DetailView, SingleObjectMixin
from
django.views.decorators.csrf
import
csrf_exempt
from
django.contrib.auth
import
logout
as
auth_logout
from
common.const
import
create_success_msg
,
update_success_msg
from
common.mixins
import
JSONResponseMixin
from
common.utils
import
get_logger
,
get_object_or_none
,
is_uuid
from
..
import
forms
from
..models
import
User
,
UserGroup
from
..utils
import
AdminUserRequiredMixin
from
..signals
import
on_user_created
from
common.mixins
import
JSONResponseMixin
from
common.utils
import
get_logger
,
get_object_or_none
,
is_uuid
__all__
=
[
'UserListView'
,
'UserCreateView'
,
'UserDetailView'
,
...
...
@@ -63,7 +65,7 @@ class UserCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
form_class
=
forms
.
UserCreateUpdateForm
template_name
=
'users/user_create.html'
success_url
=
reverse_lazy
(
'users:user-list'
)
success_message
=
_
(
'Create user <a href="{url}">{name}</a> successfully.'
)
success_message
=
create_success_msg
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
()
.
get_context_data
(
**
kwargs
)
...
...
@@ -77,19 +79,14 @@ class UserCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
on_user_created
.
send
(
self
.
__class__
,
user
=
user
)
return
super
()
.
form_valid
(
form
)
def
get_success_message
(
self
,
cleaned_data
):
url
=
reverse_lazy
(
'users:user-detail'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
})
return
self
.
success_message
.
format
(
url
=
url
,
name
=
self
.
object
.
name
)
class
UserUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
class
UserUpdateView
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
UpdateView
):
model
=
User
form_class
=
forms
.
UserCreateUpdateForm
template_name
=
'users/user_update.html'
context_object_name
=
'user_object'
success_url
=
reverse_lazy
(
'users:user-list'
)
success_message
=
update_success_msg
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Users'
),
'action'
:
_
(
'Update 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