From b7acef8cb0c09690682f73701d2ea1a1af46de88 Mon Sep 17 00:00:00 2001 From: guanghongwei Date: Fri, 13 Feb 2015 00:00:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=88=E6=9D=83=E6=94=B6=E5=B0=BE=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- connect.py | 3 +- jperm/views.py | 29 ++------- jumpserver/templatetags/mytags.py | 3 +- jumpserver/views.py | 25 ++++++++ templates/jperm/perm_asset_detail.html | 86 ++++++++++++++++---------- templates/jperm/perm_list.html | 12 ++-- 6 files changed, 92 insertions(+), 66 deletions(-) diff --git a/connect.py b/connect.py index 6b14e2f3a..dfcbabdd5 100755 --- a/connect.py +++ b/connect.py @@ -24,8 +24,7 @@ django.setup() from juser.models import User from jasset.models import Asset from jlog.models import Log -from jperm.views import perm_user_asset -from jumpserver.views import PyCrypt +from jumpserver.views import PyCrypt, perm_user_asset try: import termios diff --git a/jperm/views.py b/jperm/views.py index 8d2166772..e577af3fc 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -7,7 +7,7 @@ from jasset.models import Asset, BisGroup from jperm.models import Perm, SudoPerm, CmdGroup from django.core.paginator import Paginator, EmptyPage, InvalidPage from django.db.models import Q -from jumpserver.views import LDAP_ENABLE, ldap_conn, CONF +from jumpserver.views import LDAP_ENABLE, ldap_conn, CONF, perm_user_asset if LDAP_ENABLE: @@ -34,26 +34,6 @@ def perm_group_update(user_group_name='', user_group_id='', asset_groups_name='' Perm(user_group=user_group, asset_group=asset_group).save() -def perm_user_asset(user_id=None, username=None): - if user_id: - user = User.objects.get(id=user_id) - else: - user = User.objects.get(username=username) - user_groups = user.user_group.all() - perms = [] - assets = [] - for user_group in user_groups: - perm = user_group.perm_set.all() - perms.extend(perm) - - asset_groups = [perm.asset_group for perm in perms] - - for asset_group in asset_groups: - assets.extend(list(asset_group.asset_set.all())) - - return list(set(assets)) - - def perm_list(request): header_title, path1, path2 = u'主机授权 | Perm Host Detail.', u'授权管理', u'授权详情' groups = contact_list = Perm.objects.all() @@ -205,9 +185,12 @@ def perm_del(request): def perm_asset_detail(request): + header_title, path1, path2 = u'用户授权主机 | User Perm Asset.', u'权限管理', u'用户主机详情' user_id = request.GET.get('id') - user = User.objects.get(id=user_id) - assets = perm_user_asset(user_id) + user = User.objects.filter(id=user_id) + if user: + user = user[0] + assets_list = perm_user_asset(user_id) return render_to_response('jperm/perm_asset_detail.html', locals()) diff --git a/jumpserver/templatetags/mytags.py b/jumpserver/templatetags/mytags.py index d64387d24..11f8c90cf 100644 --- a/jumpserver/templatetags/mytags.py +++ b/jumpserver/templatetags/mytags.py @@ -2,10 +2,9 @@ import time from django import template -from django.db.models import Q from juser.models import User, UserGroup -from jperm.views import perm_user_asset from jasset.models import BisGroup +from jumpserver.views import perm_user_asset register = template.Library() diff --git a/jumpserver/views.py b/jumpserver/views.py index b072d1ab0..dd2510ccc 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -47,6 +47,9 @@ def jasset_group_add(name, comment, type): smg = u'业务组%s添加成功' % name +class ServerError(Exception): + pass + def jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment): groups = [] is_active = {u'是': '1', u'否': '2'} @@ -193,6 +196,28 @@ class PyCrypt(object): return plain_text.rstrip('\0') +def perm_user_asset(user_id=None, username=None): + if user_id: + user = User.objects.get(id=user_id) + else: + user = User.objects.get(username=username) + user_groups = user.user_group.all() + perms = [] + assets = [] + asset_groups = [] + for user_group in user_groups: + perm = user_group.perm_set.all() + perms.extend(perm) + + for perm in perms: + asset_groups.extend(perm.asset_group.all()) + + for asset_group in asset_groups: + assets.extend(list(asset_group.asset_set.all())) + + return assets + + if LDAP_ENABLE: ldap_conn = LDAPMgmt(LDAP_HOST_URL, LDAP_BASE_DN, LDAP_ROOT_DN, LDAP_ROOT_PW) else: diff --git a/templates/jperm/perm_asset_detail.html b/templates/jperm/perm_asset_detail.html index f469138d5..a500c2458 100644 --- a/templates/jperm/perm_asset_detail.html +++ b/templates/jperm/perm_asset_detail.html @@ -1,41 +1,61 @@ +{% extends 'base.html' %} {% load mytags %} - - - {% include 'link_css.html' %} - - - - +{% block content %} + {% include 'nav_cat_bar.html' %} +
-
-

{{ user.name }} 授权详情

-
- - +
+
+
+
授权主机 Asset.
+ +
+
+
+ - - - + + + - - - {% for asset in assets %} - - - - - - {% endfor %} - -
主机端口登录方式IPIDC主机组
{{ asset.ip }}{{ asset.port }}{{ asset.login_type }}
+ + + {% for asset in assets_list %} + + {{ asset.ip }} + {{ asset.idc.name }} + + {% for group in asset.bis_group.all|filter_private %} + {{ group }} + {% endfor %} + + + {% endfor %} + + +
+
+
- - \ No newline at end of file + + +{% endblock %} \ No newline at end of file diff --git a/templates/jperm/perm_list.html b/templates/jperm/perm_list.html index 0d3e18b2e..c4c9fcbd9 100644 --- a/templates/jperm/perm_list.html +++ b/templates/jperm/perm_list.html @@ -143,12 +143,12 @@ {% for user in contacts2.object_list %} -{# {{ user.name }} #} -{# {{ user.id | get_role }} #} -{# {{ user.username | groups_str }} #} -{# {{ user.id | perm_asset_count }} #} -{# #} - 详情 + {{ user.name }} + {{ user.id | get_role }} + {{ user.username | groups_str }} + {{ user.id | perm_asset_count }} + + 详情 {% endfor %}