授权收尾工作

pull/6/head
guanghongwei 10 years ago
parent 4190b19450
commit b7acef8cb0

@ -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

@ -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())

@ -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()

@ -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:

@ -1,41 +1,61 @@
{% extends 'base.html' %}
{% load mytags %}
<html>
<head>
{% include 'link_css.html' %}
<style type="text/css">
body
{
background: #FFFFFF;
}
</style>
</head>
<body>
{% block content %}
{% include 'nav_cat_bar.html' %}
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="contact-box">
<h2 class="text-center">{{ user.name }} 授权详情</h2>
<div class="ibox-content">
<table class="table table-striped table-bordered table-hover " id="editable" >
<thead>
<div class="col-lg-6">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>授权主机 <small> Asset.</small></h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-wrench"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li><a href="#">未启用 1</a>
</li>
<li><a href="#">未启用 2</a>
</li>
</ul>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
<table class="table">
<thead>
<tr>
<th class="text-center">主机</th>
<th class="text-center">端口</th>
<th class="text-center">登录方式</th>
<th>IP</th>
<th>IDC</th>
<th>主机组</th>
</tr>
</thead>
<tbody>
{% for asset in assets %}
<tr class="gradeX">
<td class="text-center">{{ asset.ip }}</td>
<td class="text-center">{{ asset.port }}</td>
<td class="text-center">{{ asset.login_type }}</td>
</tr>
{% endfor %}
</table>
</thead>
<tbody>
{% for asset in assets_list %}
<tr>
<td>{{ asset.ip }}</td>
<td>{{ asset.idc.name }}</td>
<td>
{% for group in asset.bis_group.all|filter_private %}
{{ group }}
{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</body>
</html>
</div>
{% endblock %}

@ -143,12 +143,12 @@
<tbody id="perm_list">
{% for user in contacts2.object_list %}
<tr class="gradeX">
{# <td class="text-center"> {{ user.name }} </td>#}
{# <td class="text-center"> {{ user.id | get_role }} </td>#}
{# <td class="text-center"> {{ user.username | groups_str }} </td>#}
{# <td class="text-center"> {{ user.id | perm_asset_count }} </td>#}
{# <td class="text-center">#}
<a title="[ {{ user.name }} ] 授权详情" href="../perm_asset_detail/?id={{ user.id }}" class="iframe btn btn-xs btn-primary">详情</a>
<td class="text-center"> {{ user.name }} </td>
<td class="text-center"> {{ user.id | get_role }} </td>
<td class="text-center"> {{ user.username | groups_str }} </td>
<td class="text-center"> {{ user.id | perm_asset_count }} </td>
<td class="text-center">
<a title="[ {{ user.name }} ] 授权详情" href="../perm_asset_detail/?id={{ user.id }}" class="btn btn-xs btn-primary">详情</a>
</td>
</tr>
{% endfor %}

Loading…
Cancel
Save