From 3efd810fe16d0a2499ef45c9f99c70bc28c4aeb5 Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 2 Sep 2015 21:42:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BF=AE=E6=94=B9=E7=94=A8?= =?UTF-8?q?=E6=88=B7bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jumpserver/templatetags/mytags.py | 5 +- juser/models.py | 3 + juser/user_api.py | 15 +++- juser/views.py | 52 ++++++++------ templates/footer.html | 2 +- templates/juser/user_edit.html | 116 +++++++++++++++--------------- 6 files changed, 103 insertions(+), 90 deletions(-) diff --git a/jumpserver/templatetags/mytags.py b/jumpserver/templatetags/mytags.py index f5ed765e2..b8b236dfe 100644 --- a/jumpserver/templatetags/mytags.py +++ b/jumpserver/templatetags/mytags.py @@ -27,10 +27,9 @@ def int2str(value): @register.filter(name='get_role') def get_role(user_id): - user_role = {'SU': u'超级管理员', 'DA': u'部门管理员', 'CU': u'普通用户'} - user = User.objects.filter(id=user_id) + user_role = {'SU': u'超级管理员', 'GA': u'组管理员', 'CU': u'普通用户'} + user = get_object(User, id=user_id) if user: - user = user[0] return user_role.get(str(user.role), u"普通用户") else: return u"普通用户" diff --git a/juser/models.py b/juser/models.py index cb7a4b248..d2a0d9f8d 100644 --- a/juser/models.py +++ b/juser/models.py @@ -130,4 +130,7 @@ class AdminGroup(models.Model): user = models.ForeignKey(User) group = models.ForeignKey(UserGroup) + def __unicode__(self): + return '%s: %s' % (self.user.username, self.group.name) + diff --git a/juser/user_api.py b/juser/user_api.py index 0597e8f05..04a638a0f 100644 --- a/juser/user_api.py +++ b/juser/user_api.py @@ -81,19 +81,28 @@ def db_update_user(**kwargs): 数据库更新用户信息 """ groups_post = kwargs.pop('groups') + admin_groups_post = kwargs.pop('admin_groups') user_id = kwargs.pop('user_id') user = User.objects.filter(id=user_id) if user: user.update(**kwargs) - user = User.objects.get(id=user_id) + user = user[0] user.save() + else: + return None + group_select = [] if groups_post: - group_select = [] for group_id in groups_post: group = UserGroup.objects.filter(id=group_id) group_select.extend(group) - user.group = group_select + user.group = group_select + + if admin_groups_post != '': + user.admingroup_set.all().delete() + for group_id in admin_groups_post: + group = get_object(UserGroup, id=group_id) + AdminGroup(user=user, group=group).save() def db_del_user(username): diff --git a/juser/views.py b/juser/views.py index b9c225c17..c77f90cd2 100644 --- a/juser/views.py +++ b/juser/views.py @@ -527,54 +527,60 @@ def user_edit(request): if not user_id: return HttpResponseRedirect('/') - user_role = {'SU': u'超级管理员', 'DA': u'组管理员', 'CU': u'普通用户'} + user_role = {'SU': u'超级管理员', 'GA': u'组管理员', 'CU': u'普通用户'} user = get_object(User, id=user_id) group_all = UserGroup.objects.all() - if user: groups_str = ' '.join([str(group.id) for group in user.group.all()]) + admin_groups_str = ' '.join([str(admin_group.group.id) for admin_group in user.admingroup_set.all()]) else: - user_id = request.POST.get('user_id', '') + user_id = request.GET.get('id', '') password = request.POST.get('password', '') name = request.POST.get('name', '') email = request.POST.get('email', '') - dept_id = request.POST.get('dept_id') groups = request.POST.getlist('groups', []) role_post = request.POST.get('role', 'CU') - ssh_key_pwd = request.POST.get('ssh_key_pwd', '') - is_active = True if request.POST.get('is_active', '1') == '1' else False - + admin_groups = request.POST.getlist('admin_groups', []) + extra = request.POST.getlist('extra', []) + is_active = True if '0' in extra else False + email_need = True if '2' in extra else False user_role = {'SU': u'超级管理员', 'DA': u'部门管理员', 'CU': u'普通用户'} - dept = DEPT.objects.filter(id=dept_id) - if dept: - dept = dept[0] - else: - dept = DEPT.objects.get(id='2') - + print '#'*10 + str(email_need) + print extra if user_id: - user = User.objects.filter(id=user_id) - if user: - user = user[0] + user = get_object(User, id=user_id) else: return HttpResponseRedirect('/juser/user_list/') if password != user.password: + password_decode = password password = CRYPTOR.md5_crypt(password) - - if ssh_key_pwd != user.ssh_key_pwd: - gen_ssh_key(user.username, ssh_key_pwd) - ssh_key_pwd = CRYPTOR.encrypt(ssh_key_pwd) + else: + password_decode = None db_update_user(user_id=user_id, password=password, name=name, email=email, groups=groups, - dept=dept, + admin_groups=admin_groups, role=role_post, - is_active=is_active, - ssh_key_pwd=ssh_key_pwd) + is_active=is_active) + + if email_need: + + msg = u""" + Hi %s: + 您的信息已修改,请登录跳板机查看详细信息 + 地址:%s + 用户名: %s + 密码:%s (如果密码为None代表密码为原密码) + 角色:%s + + """ % (user.name, URL, user.username, password_decode, user_role.get(role_post, u'')) + + send_mail('您的信息已修改', msg, MAIL_FROM, [email], fail_silently=False) return HttpResponseRedirect('/juser/user_list/') diff --git a/templates/footer.html b/templates/footer.html index 969e5cfe6..0f1f6f76e 100644 --- a/templates/footer.html +++ b/templates/footer.html @@ -1,6 +1,6 @@
-
+ {% if error %}
{{ error }}
{% endif %} @@ -33,7 +33,6 @@
-
@@ -48,16 +47,6 @@
-
- -
- - - 登陆 Jumpserver 使用的SSH密钥的密码,更改密钥密码需要重新下载密钥 - -
-
-
@@ -79,23 +68,38 @@
- {% ifequal session_role_id 2 %}
- + {% for r, role_name in user_role.items %} +
+
+ +
+
+ {% endfor %} +
+
+ - {% endifequal %}
@@ -104,15 +108,15 @@
-
-
-
- +
+
+
+
-
- +
+
+
+
@@ -129,18 +133,20 @@
+{% endblock %} +{% block self_footer_js %} - - {% endblock %} \ No newline at end of file