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
477d23ea
Commit
477d23ea
authored
Jul 19, 2017
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix some bug
parent
61014c74
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
21 additions
and
11 deletions
+21
-11
forms.py
apps/assets/forms.py
+2
-3
asset.py
apps/assets/models/asset.py
+1
-1
_system_user.html
apps/assets/templates/assets/_system_user.html
+0
-5
system_user.py
apps/assets/views/system_user.py
+10
-0
utils.py
apps/common/utils.py
+4
-0
utils.py
apps/perms/utils.py
+4
-2
No files found.
apps/assets/forms.py
View file @
477d23ea
...
...
@@ -70,7 +70,6 @@ class AssetBulkUpdateForm(forms.ModelForm):
required
=
True
,
help_text
=
'* required'
,
label
=
_
(
'Select assets'
),
# choices=[(asset.id, asset.hostname) for asset in Asset.objects.all()],
widget
=
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
...
...
@@ -182,7 +181,7 @@ class AdminUserForm(forms.ModelForm):
# Form field name can not start with `_`, so redefine it,
password
=
forms
.
CharField
(
widget
=
forms
.
PasswordInput
,
max_length
=
100
,
min_length
=
8
,
strip
=
True
,
required
=
False
,
strip
=
True
,
required
=
False
,
help_text
=
_
(
'If also set private key, use that first'
),
)
# Need use upload private key file except paste private key content
...
...
@@ -239,7 +238,7 @@ class SystemUserForm(forms.ModelForm):
auto_generate_key
=
forms
.
BooleanField
(
initial
=
True
,
required
=
False
)
# Form field name can not start with `_`, so redefine it,
password
=
forms
.
CharField
(
widget
=
forms
.
PasswordInput
,
required
=
False
,
max_length
=
100
,
min_length
=
8
,
strip
=
True
)
max_length
=
100
,
strip
=
True
)
# Need use upload private key file except paste private key content
private_key_file
=
forms
.
FileField
(
required
=
False
)
...
...
apps/assets/models/asset.py
View file @
477d23ea
...
...
@@ -125,7 +125,7 @@ class Asset(models.Model):
'method'
:
self
.
admin_user
.
become_method
,
'user'
:
self
.
admin_user
.
become_user
,
'pass'
:
self
.
admin_user
.
become_pass
,
}
if
self
.
admin_user
.
become
else
{},
}
if
self
.
admin_user
and
self
.
admin_user
.
become
else
{},
}
class
Meta
:
...
...
apps/assets/templates/assets/_system_user.html
View file @
477d23ea
...
...
@@ -27,11 +27,6 @@
</div>
</div>
<div
class=
"ibox-content"
>
{% if form.no_field_errors %}
<div
class=
"alert alert-danger"
>
{{ form.non_field_errors }}
</div>
{% endif %}
<form
enctype=
"multipart/form-data"
method=
"post"
class=
"form-horizontal"
action=
""
>
{% csrf_token %}
{% if form.non_field_errors %}
...
...
apps/assets/views/system_user.py
View file @
477d23ea
...
...
@@ -13,6 +13,8 @@ from django.views.generic.detail import DetailView, SingleObjectMixin
from
..
import
forms
from
..models
import
Asset
,
AssetGroup
,
AdminUser
,
IDC
,
SystemUser
from
..hands
import
AdminUserRequiredMixin
from
perms.utils
import
associate_system_users_and_assets
__all__
=
[
'SystemUserCreateView'
,
'SystemUserUpdateView'
,
'SystemUserDetailView'
,
'SystemUserDeleteView'
,
...
...
@@ -74,6 +76,14 @@ class SystemUserUpdateView(AdminUserRequiredMixin, UpdateView):
kwargs
.
update
(
context
)
return
super
(
SystemUserUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
def
form_valid
(
self
,
form
):
response
=
super
(
SystemUserUpdateView
,
self
)
.
form_valid
(
form
)
system_user
=
self
.
object
assets
=
system_user
.
assets
.
all
()
asset_groups
=
system_user
.
asset_groups
.
all
()
associate_system_users_and_assets
([
system_user
],
assets
,
asset_groups
,
force
=
True
)
return
response
def
get_success_url
(
self
):
success_url
=
reverse_lazy
(
'assets:system-user-detail'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
})
...
...
apps/common/utils.py
View file @
477d23ea
...
...
@@ -239,7 +239,11 @@ def ssh_key_gen(length=2048, type='rsa', password=None, username='jumpserver', h
def
validate_ssh_private_key
(
text
):
if
isinstance
(
text
,
bytes
):
try
:
text
=
text
.
decode
(
"utf-8"
)
except
UnicodeDecodeError
:
return
False
key
=
ssh_key_string_to_obj
(
text
)
if
key
is
None
:
return
False
...
...
apps/perms/utils.py
View file @
477d23ea
...
...
@@ -235,7 +235,7 @@ def push_system_user(assets, system_user):
return
task
.
id
def
associate_system_users_and_assets
(
system_users
,
assets
,
asset_groups
):
def
associate_system_users_and_assets
(
system_users
,
assets
,
asset_groups
,
force
=
False
):
"""关联系统用户和资产, 目的是保存它们的关系, 然后新加入的资产或系统
用户时,推送系统用户到资产
...
...
@@ -250,6 +250,9 @@ def associate_system_users_and_assets(system_users, assets, asset_groups):
for
system_user
in
system_users
:
assets_need_push
=
[]
if
system_user
.
auto_push
:
if
force
:
assets_need_push
=
assets_all
else
:
assets_need_push
.
extend
(
[
asset
for
asset
in
assets_all
if
asset
not
in
system_user
.
assets
.
all
()
...
...
@@ -258,4 +261,3 @@ def associate_system_users_and_assets(system_users, assets, asset_groups):
system_user
.
assets
.
add
(
*
(
tuple
(
assets_all
)))
push_system_user
(
assets_need_push
,
system_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