From c1686d52e960eede1c17bb9386301280f0ef8103 Mon Sep 17 00:00:00 2001 From: guanghongwei Date: Fri, 30 Jan 2015 16:39:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=88=E6=9D=83=E7=BC=96=E8=BE=91=E5=92=8C?= =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E4=BF=AE=E6=94=B9=E5=AE=8C=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jperm/urls.py | 1 + jperm/views.py | 23 +++++++++++++++ jumpserver/templatetags/mytags.py | 5 ++++ templates/jperm/perm_asset_detail.html | 41 ++++++++++++++++++++++++++ templates/jperm/perm_list.html | 17 ++++++----- 5 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 templates/jperm/perm_asset_detail.html diff --git a/jperm/urls.py b/jperm/urls.py index 30a4fae1f..80d8f8630 100644 --- a/jperm/urls.py +++ b/jperm/urls.py @@ -10,4 +10,5 @@ urlpatterns = patterns('jperm.views', (r'^perm_list/$', 'perm_list'), (r'^perm_detail/$', 'perm_detail'), (r'^perm_del/$', 'perm_del'), + (r'^perm_asset_detail/$', 'perm_asset_detail'), ) diff --git a/jperm/views.py b/jperm/views.py index f80840543..a53b7938a 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -25,6 +25,23 @@ 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): + user = User.objects.get(id=user_id) + 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'jperm', u'perm_list' groups = contact_list = UserGroup.objects.all().order_by('type') @@ -75,6 +92,12 @@ def perm_del(request): return HttpResponseRedirect('/jperm/perm_list/') +def perm_asset_detail(request): + user_id = request.GET.get('id') + user = User.objects.get(id=user_id) + assets = perm_user_asset(user_id) + return render_to_response('jperm/perm_asset_detail.html', locals()) + # def perm_user_host(username, ips): # user = User.objects.get(username=username) diff --git a/jumpserver/templatetags/mytags.py b/jumpserver/templatetags/mytags.py index 003e53cc3..01b81d486 100644 --- a/jumpserver/templatetags/mytags.py +++ b/jumpserver/templatetags/mytags.py @@ -4,6 +4,7 @@ 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 register = template.Library() @@ -73,3 +74,7 @@ def group_type_to_str(type_name): 'A': '授权组', } return group_types.get(type_name) + +@register.filter(name='perm_asset_count') +def perm_asset_count(user_id): + return len(perm_user_asset(user_id)) diff --git a/templates/jperm/perm_asset_detail.html b/templates/jperm/perm_asset_detail.html new file mode 100644 index 000000000..f469138d5 --- /dev/null +++ b/templates/jperm/perm_asset_detail.html @@ -0,0 +1,41 @@ +{% load mytags %} + + + {% include 'link_css.html' %} + + + + + +
+
+

{{ user.name }} 授权详情

+
+ + + + + + + + + + + {% for asset in assets %} + + + + + + {% endfor %} + +
主机端口登录方式
{{ asset.ip }}{{ asset.port }}{{ asset.login_type }}
+
+
+ + \ No newline at end of file diff --git a/templates/jperm/perm_list.html b/templates/jperm/perm_list.html index 6e56381d7..dd8436d6c 100644 --- a/templates/jperm/perm_list.html +++ b/templates/jperm/perm_list.html @@ -113,19 +113,22 @@ - - + + + + - {% for group in contacts2.object_list %} + {% for user in contacts2.object_list %} - - + + + + {% endfor %}
组名备注用户角色属组主机数量 操作
{{ group.name }} {{ group.comment }} {{ user.name }} {{ user.id | get_role }} {{ user.username | groups_str }} {{ user.id | perm_asset_count }} - 详情 - 编辑 + 详情