Skip to content

Commit 1719eee

Browse files
committed
[Bugfix] 修复py3 bytes bug
1 parent 41633be commit 1719eee

6 files changed

Lines changed: 10 additions & 27 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ migrations/
2121
host_rsa_key
2222
*.bat
2323
tags
24-
tmp/*
2524
jumpserver.iml
25+
.python-version
26+
tmp/*

apps/assets/forms.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,6 @@ class Meta:
179179

180180

181181
class AdminUserForm(forms.ModelForm):
182-
# Admin user assets define, let user select, save it in form not in view
183-
assets = forms.ModelMultipleChoiceField(
184-
queryset=Asset.objects.all(),
185-
label=_('Asset'),
186-
required=False,
187-
widget=forms.SelectMultiple(
188-
attrs={'class': 'select2', 'data-placeholder': _('Select assets')})
189-
)
190182
# Form field name can not start with `_`, so redefine it,
191183
password = forms.CharField(
192184
widget=forms.PasswordInput, max_length=100,
@@ -196,20 +188,6 @@ class AdminUserForm(forms.ModelForm):
196188
# Need use upload private key file except paste private key content
197189
private_key_file = forms.FileField(required=False)
198190

199-
def __init__(self, *args, **kwargs):
200-
# When update a admin user instance, initial it
201-
if kwargs.get('instance'):
202-
initial = kwargs.get('initial', {})
203-
initial['assets'] = kwargs['instance'].assets.all()
204-
super(AdminUserForm, self).__init__(*args, **kwargs)
205-
206-
def _save_m2m(self):
207-
# Save assets relation with admin user
208-
super(AdminUserForm, self)._save_m2m()
209-
assets = self.cleaned_data['assets']
210-
self.instance.assets.clear()
211-
self.instance.assets.add(*tuple(assets))
212-
213191
def save(self, commit=True):
214192
# Because we define custom field, so we need rewrite :method: `save`
215193
admin_user = super(AdminUserForm, self).save(commit=commit)

apps/assets/templates/assets/admin_user_create_update.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ <h5>{% trans 'Create admin user' %}</h5>
3838
{% bootstrap_field form.username layout="horizontal" %}
3939
{% bootstrap_field form.password layout="horizontal" %}
4040
{% bootstrap_field form.private_key_file layout="horizontal" %}
41-
{% bootstrap_field form.assets layout="horizontal" %}
4241
{% bootstrap_field form.comment layout="horizontal" %}
4342

4443
<div class="form-group">

apps/common/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
22
#
3-
from __future__ import unicode_literals
43

54
from collections import OrderedDict
65
from six import string_types
@@ -55,6 +54,8 @@ def __init__(self, secret_key=SECRET_KEY):
5554
self.secret_key = secret_key
5655

5756
def sign(self, value):
57+
if isinstance(value, bytes):
58+
value = value.decode("utf-8")
5859
s = JSONWebSignatureSerializer(self.secret_key)
5960
return s.dumps(value)
6061

@@ -194,9 +195,10 @@ def ssh_key_string_to_obj(text):
194195

195196

196197
def ssh_pubkey_gen(private_key=None, username='jumpserver', hostname='localhost'):
198+
if isinstance(private_key, bytes):
199+
private_key = private_key.decode("utf-8")
197200
if isinstance(private_key, string_types):
198201
private_key = ssh_key_string_to_obj(private_key)
199-
200202
if not isinstance(private_key, (paramiko.RSAKey, paramiko.DSSKey)):
201203
raise IOError('Invalid private key')
202204

@@ -237,6 +239,8 @@ def ssh_key_gen(length=2048, type='rsa', password=None, username='jumpserver', h
237239

238240

239241
def validate_ssh_private_key(text):
242+
if isinstance(text, bytes):
243+
text = text.decode("utf-8")
240244
key = ssh_key_string_to_obj(text)
241245
if key is None:
242246
return False

apps/templates/_nav.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
<li id="applications">
3838
<a>
39-
<i class="fa fa-coffee"></i> <span class="nav-label">{% trans 'Applications' %}</span><span class="fa arrow"></span>
39+
<i class="fa fa-rocket"></i> <span class="nav-label">{% trans 'Applications' %}</span><span class="fa arrow"></span>
4040
</a>
4141
<ul class="nav nav-second-level">
4242
<li id="terminal"><a href="{% url 'applications:terminal-list' %}">{% trans 'Terminal' %}</a></li>

tmp/.gitkeep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Because ansible connect remote host using key file path except key string, so I create this dir for keep them.

0 commit comments

Comments
 (0)