修改授权详情

pull/6/head
guanghongwei 2015-02-11 23:32:24 +08:00
parent f050866d94
commit 4190b19450
5 changed files with 167 additions and 48 deletions

View File

@ -8,8 +8,45 @@ os.environ['DJANGO_SETTINGS_MODULE'] = 'jumpserver.settings'
django.setup()
from juser.views import db_add_user, md5_crypt, CRYPTOR
from jasset.models import Asset, IDC
from jasset.models import Asset, IDC, BisGroup
from juser.models import UserGroup
from jasset.views import jasset_group_add
from jperm.models import CmdGroup
def test_add_idc():
for i in range(1, 20):
name = 'IDC' + str(i)
IDC.objects.create(name=name, comment='')
print 'Add: %s' % name
def test_add_asset_group():
BisGroup.objects.create(name='ALL', type='A', comment='ALL')
for i in range(1, 20):
name = 'AssetGroup' + str(i)
BisGroup.objects.create(name=name, type='A', comment=name)
print 'Add: %s' % name
def test_add_user_group():
for i in range(1, 20):
name = 'DepartGroup' + str(i)
UserGroup.objects.create(name=name, type='M', comment=name)
print 'Add: %s' % name
for i in range(1, 20):
name = 'UserGroup' + str(i)
UserGroup.objects.create(name=name, type='A', comment=name)
print 'Add: %s' % name
def test_add_cmd_group():
for i in range(1, 20):
name = 'CMD' + str(i)
cmd = '/sbin/ping%s, /sbin/ifconfig/' % str(i)
CmdGroup.objects.create(name=name, cmd=cmd, comment=name)
print 'Add: %s' % name
def test_add_user():
@ -36,11 +73,12 @@ def test_add_asset():
if __name__ == '__main__':
args = sys.argv
if args[1] == 'user':
test_add_user()
if args[1] == 'asset':
test_add_asset()
test_add_idc()
test_add_asset_group()
test_add_user_group()
test_add_cmd_group()
test_add_asset()
test_add_user()

View File

@ -176,16 +176,31 @@ def perm_edit(request):
def perm_detail(request):
user_group_id = request.GET.get('id')
user_group = UserGroup.objects.get(id=user_group_id)
asset_groups = [perm.asset_group for perm in user_group.perm_set.all()]
header_title, path1, path2 = u'编辑授权 | Perm Host Edit.', u'授权管理', u'授权详情'
perm_id = request.GET.get('id')
perm = Perm.objects.filter(id=perm_id)
if perm:
perm = perm[0]
user_groups = perm.user_group.all()
asset_groups = perm.asset_group.all()
users_list = []
assets_list = []
for user_group in user_groups:
users_list.extend(user_group.user_set.all())
for asset_group in asset_groups:
assets_list.extend(asset_group.asset_set.all())
return render_to_response('jperm/perm_detail.html', locals())
def perm_del(request):
user_group_id = request.GET.get('id')
user_group = UserGroup.objects.get(id=user_group_id)
Perm.objects.filter(user_group=user_group).delete()
perm_id = request.GET.get('id')
perm = Perm.objects.filter(id=perm_id)
if perm:
perm = perm[0]
perm.delete()
return HttpResponseRedirect('/jperm/perm_list/')

View File

@ -1,41 +1,107 @@
{% 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">{{ group.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> User.</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">ID</th>
<th class="text-center">主机组</th>
<th class="text-center">主机数量</th>
<th>用户名</th>
<th>姓名</th>
<th>部门</th>
<th>属组</th>
</tr>
</thead>
<tbody>
{% for asset_group in asset_groups %}
<tr class="gradeX">
<td class="text-center">{{ asset_group.id }}</td>
<td class="text-center">{{ asset_group.name }}</td>
<td class="text-center">{{ asset_group.asset_set.count }}</td>
</tr>
{% endfor %}
</table>
</thead>
<tbody>
{% for user in users_list %}
<tr>
<td>{{ user.username }}</td>
<td>{{ user.name }}</td>
<td>{{ user.username|group_manage_str }}</td>
<td>{{ user.username|groups_str }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<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>IP</th>
<th>IDC</th>
<th>主机组</th>
</tr>
</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 %}

View File

@ -81,7 +81,7 @@
</td>
<td class="text-center"> {{ perm.comment }} </td>
<td class="text-center">
<a title="[ {{ group.name }} 授权详情 ]" href="../perm_detail/?id={{ perm.id }}" class="iframe btn btn-xs btn-primary">详情</a>
<a title="[ {{ group.name }} 授权详情 ]" href="../perm_detail/?id={{ perm.id }}" class=" btn btn-xs btn-primary">详情</a>
<a href="../perm_edit/?id={{ perm.id }}" class="btn btn-xs btn-info">编辑</a>
<a href="../perm_del/?id={{ perm.id }}" class="btn btn-xs btn-danger">删除</a>
</td>

View File

@ -3,7 +3,7 @@
<h2>{{ header_title }}</h2>
<ol class="breadcrumb">
<li>
<a href="/">Home</a>
<a href="/">仪表盘</a>
</li>
<li>
<a>{{ path1 }}</a>