今天就这样吧

pull/6/head
guanghongwei 10 years ago
parent 8f163eb634
commit ae0c28ef8f

@ -1,6 +1,6 @@
from django.db import models
from juser.models import UserGroup
from jasset.models import BisGroup
from juser.models import UserGroup, DEPT
from jasset.models import Asset, BisGroup
class Perm(models.Model):
@ -13,6 +13,14 @@ class Perm(models.Model):
return '%s_%s' % (self.user_group.name, self.asset_group.name)
class DeptPerm(models.Model):
dept = models.ForeignKey(DEPT)
asset = models.ForeignKey(Asset)
def __unicode__(self):
return '%s_%s' % (self.dept.name, self.asset.ip)
class CmdGroup(models.Model):
name = models.CharField(max_length=50)
cmd = models.CharField(max_length=999)

@ -8,7 +8,9 @@ urlpatterns = patterns('jperm.views',
(r'^perm_edit/$', 'perm_edit'),
(r'^perm_add/$', 'perm_add'),
(r'^dept_perm_edit/$', 'dept_perm_edit'),
(r'^perm_list/$', 'perm_list'),
(r'^dept_perm_list/$', 'dept_perm_list'),
(r'^perm_user_detail/$', 'perm_user_detail'),
# (r'^perm_list_ajax/$', 'perm_list_ajax'),
(r'^perm_detail/$', 'perm_detail'),

@ -3,9 +3,9 @@
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect, HttpResponse
from django.template import RequestContext
from juser.models import User, UserGroup
from juser.models import User, UserGroup, DEPT
from jasset.models import Asset, BisGroup
from jperm.models import Perm, SudoPerm, CmdGroup
from jperm.models import Perm, SudoPerm, CmdGroup, DeptPerm
from django.core.paginator import Paginator, EmptyPage, InvalidPage
from django.db.models import Q
from jumpserver.views import LDAP_ENABLE, ldap_conn, CONF, page_list_return, pages
@ -37,7 +37,7 @@ def user_asset_cmd_groups_get(user_groups_select='', asset_groups_select='', cmd
def perm_add(request):
header_title, path1, path2 = u'涓绘満鎺堟潈娣诲姞.', u'鎺堟潈绠$悊', u'鎺堟潈娣诲姞'
header_title, path1, path2 = u'涓绘満鎺堟潈娣诲姞', u'鎺堟潈绠$悊', u'鎺堟潈娣诲姞'
if request.method == 'GET':
user_groups = UserGroup.objects.filter(id__gt=2)
@ -60,6 +60,32 @@ def perm_add(request):
return render_to_response('jperm/perm_add.html', locals(), context_instance=RequestContext(request))
def dept_add_asset(dept_list, asset_list):
for dept_id in dept_list:
dept = DEPT.objects.filter(id=dept_id)
if dept:
dept = dept[0]
for asset_id in asset_list:
asset = Asset.objects.filter(id=asset_id)
if asset:
asset = asset[0]
DeptPerm(dept=dept, asset=asset).save()
def dept_perm_edit(request):
header_title, path1, path2 = u'閮ㄩ棬鎺堟潈娣诲姞', u'鎺堟潈绠$悊', u'閮ㄩ棬鎺堟潈娣诲姞'
depts = DEPT.objects.all()
assets = Asset.objects.all()
if request.method == 'POST':
dept_select = request.POST.getlist('dept_select')
asset_select = request.POST.getlist('asset_select')
dept_add_asset(dept_select, asset_select)
msg = '娣诲姞鎴愬姛'
return render_to_response('jperm/dept_perm_edit.html', locals(), context_instance=RequestContext(request))
def perm_list(request):
header_title, path1, path2 = u'涓绘満鎺堟潈', u'鎺堟潈绠$悊', u'鎺堟潈璇︽儏'
keyword = request.GET.get('search', '')
@ -71,39 +97,18 @@ def perm_list(request):
return render_to_response('jperm/perm_list.html', locals(), context_instance=RequestContext(request))
# def perm_list_ajax(request):
# tab = request.POST.get('tab', 'tab1')
# search = request.POST.get('search', '')
#
# if tab == 'tab1':
# groups = contact_list = UserGroup.objects.filter(name__icontains=search).order_by('type')
# p = paginator = Paginator(contact_list, 10)
#
# try:
# page = int(request.GET.get('page', '1'))
# except ValueError:
# page = 1
#
# try:
# contacts = paginator.page(page)
# except (EmptyPage, InvalidPage):
# contacts = paginator.page(paginator.num_pages)
#
# else:
# users = contact_list2 = User.objects.filter(name__icontains=search).order_by('id')
# p2 = paginator2 = Paginator(contact_list2, 10)
#
# try:
# page = int(request.GET.get('page', '1'))
# except ValueError:
# page = 1
#
# try:
# contacts2 = paginator2.page(page)
# except (EmptyPage, InvalidPage):
# contacts2 = paginator2.page(paginator2.num_pages)
#
# return render_to_response('jperm/perm_list_ajax.html', locals())
def dept_perm_list(request):
header_title, path1, path2 = '鏌ョ湅閮ㄩ棬', '鎺堟潈绠$悊', '閮ㄩ棬鎺堟潈'
keyword = request.GET.get('search')
if keyword:
contact_list = DEPT.objects.filter(Q(name__icontains=keyword) | Q(comment__icontains=keyword)).order_by('name')
else:
contact_list = DEPT.objects.filter(id__gt=1)
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(contact_list, request)
return render_to_response('jperm/dept_perm_list.html', locals(), context_instance=RequestContext(request))
def perm_group_update(perm_id, user_group_id_list, asset_groups_id_list):
perm = Perm.objects.filter(id=perm_id)
@ -145,8 +150,6 @@ def perm_edit(request):
perm_id = request.POST.get('perm_id', '')
user_group_id_list = request.POST.getlist('user_groups_select')
asset_group_id_list = request.POST.getlist('asset_groups_select')
# return HttpResponse("perm_id: %s user_group: %s asset_group: %s" % (perm_id, repr(user_group_id_list), repr(asset_group_id_list) ))
# return HttpResponse(perm_group_update(perm_id, user_group_id_list, asset_group_id_list))
perm_group_update(perm_id, user_group_id_list, asset_group_id_list)
return HttpResponseRedirect('/jperm/perm_list/')

@ -0,0 +1,158 @@
{% extends 'base.html' %}
{% load mytags %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-lg-10">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5> 閮ㄩ棬鎺堟潈娣诲姞 </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">
<form id="sudoPerm" method="post" class="form-horizontal" action="">
{% if error %}
<div class="alert alert-warning text-center">{{ error }}</div>
{% endif %}
{% if msg %}
<div class="alert alert-success text-center">{{ msg }}</div>
{% endif %}
<div class="row">
<div class="form-group">
<label for="" class="col-sm-2 control-label">閮ㄩ棬<span class="red-fonts">*</span></label>
<div class="col-sm-4">
<div>
<select id="depts" name="depts" class="form-control" size="12" multiple>
{% for dept in depts %}
<option value="{{ dept.id }}">{{ dept.name }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="col-sm-1">
<div class="btn-group" style="margin-top: 60px;">
<button type="button" class="btn btn-white" onclick="move('depts', 'dept_select')"><i class="fa fa-chevron-right"></i></button>
<button type="button" class="btn btn-white" onclick="move('dept_select', 'depts')"><i class="fa fa-chevron-left"></i> </button>
</div>
</div>
<div class="col-sm-3">
<div>
<select id="dept_select" name="dept_select" class="form-control m-b" size="12" multiple>
</select>
</div>
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="" class="col-sm-2 control-label">涓绘満<span class="red-fonts">*</span></label>
<div class="col-sm-4">
<div>
<select id="assets" name="assets" class="form-control m-b" size="12" multiple>
{% for asset in assets %}
<option value="{{ asset.id }}">{{ asset.ip }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="col-sm-1">
<div class="btn-group" style="margin-top: 60px;">
<button type="button" class="btn btn-white" onclick="move('assets', 'asset_select')"><i class="fa fa-chevron-right"></i></button>
<button type="button" class="btn btn-white" onclick="move('asset_select', 'assets')"><i class="fa fa-chevron-left"></i> </button>
</div>
</div>
<div class="col-sm-3">
<div>
<select id="asset_select" name="asset_select" class="form-control m-b" size="12" multiple>
</select>
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-white" type="reset">鍙栨秷</button>
<button id="submit_button" class="btn btn-primary" type="submit">纭淇濆瓨</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
$('#sudoPerm').validator({
timely: 2,
theme: "yellow_right_effect",
fields: {
"name": {
rule: "required",
tip: "杈撳叆鎺堟潈鍚",
ok: "",
msg: {required: "蹇呴』濉啓!"}
},
"user_groups_select": {
rule: "required",
tip: "閫夋嫨鐢ㄦ埛缁",
ok: "",
msg: {checked: "鑷冲皯閫夋嫨涓涓敤鎴风粍"}
},
"asset_groups_select": {
rule: "required",
tip: "閫夋嫨涓绘満缁",
ok: "",
msg: {checked: "鑷冲皯閫夋嫨涓涓富鏈虹粍"}
}
},
valid: function(form) {
form.submit();
}
});
$(document).ready(function(){
$("#submit_button").click(function(){
$('#users_selected option').each(function(){
$(this).prop('selected', true)
})
})
})
</script>
{% endblock %}

@ -0,0 +1,104 @@
{% extends 'base.html' %}
{% load mytags %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-lg-10">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5> 鏌ョ湅閮ㄩ棬 </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">
<div class="">
<a target="_blank" href="/juser/dept_add/" class="btn btn-sm btn-primary "> 娣诲姞閮ㄩ棬 </a>
<form id="search_form" method="get" action="" class="pull-right mail-search">
<div class="input-group">
<input type="text" class="form-control input-sm" id="search_input" name="search" placeholder="Search">
<div class="input-group-btn">
<button id='search_btn' type="submit" class="btn btn-sm btn-primary">
Search
</button>
</div>
</div>
</form>
</div>
<table class="table table-striped table-bordered table-hover " id="editable" >
<thead>
<tr>
<th class="text-center">閮ㄩ棬鍚嶇О</th>
<th class="text-center">鎴愬憳鏁伴噺</th>
<th class="text-center">鎺堟潈涓绘満鏁伴噺</th>
<th class="text-center">澶囨敞</th>
<th class="text-center">鎿嶄綔</th>
</tr>
</thead>
<tbody>
{% for dept in contacts.object_list %}
<tr class="gradeX">
<td class="text-center"> {{ dept.name }} </td>
<td class="text-center"> {{ dept.id | dept_member }} </td>
<td class="text-center"> {{ dept.id | dept_member }} </td>
<td class="text-center"> {{ dept.comment }} </td>
<td class="text-center">
<a title="[ {{ dept.name }} ] 鎴愬憳淇℃伅" href="../dept_detail/?id={{ dept.id }}" class="iframe btn btn-xs btn-primary">涓绘満</a>
<a href="../dept_perm_edit/?id={{ dept.id }}" class="btn btn-xs btn-info">鎺堟潈缂栬緫</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="row">
<div class="col-sm-6">
<div class="dataTables_info" id="editable_info" role="status" aria-live="polite">
Showing {{ contacts.start_index }} to {{ contacts.end_index }} of {{ p.count }} entries
</div>
</div>
{% include 'paginator.html' %}
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$(".iframe").colorbox({iframe:true, width:"70%", height:"70%"});
var check_array = []
$('#del_btn').click(function(){
$(".gradeX input:checked").each(function() {check_array.push($(this).attr("value")) })
$(".gradeX input:checked").closest("tr").remove()
$.post("/juser/dept_del_ajax/",
{dept_ids: check_array.join(",")},
function(data){
alert(data)
}
)
})
});
</script>
{% endblock %}

@ -50,9 +50,9 @@
<label for="" class="col-sm-2 control-label">鐢ㄦ埛缁<span class="red-fonts">*</span></label>
<div class="col-sm-4">
<div>
<select id="user_groups" name="user_groups" class="form-control" size="5" multiple>
<select id="user_groups" name="user_groups" class="form-control" size="10" multiple>
{% for user_group in user_groups %}
<option value="{{ user_group.id }}">{{ user_group.name }} --- {{ user_group.type|group_type_to_str }}</option>
<option value="{{ user_group.id }}">{{ user_group.name }}</option>
{% endfor %}
</select>
</div>
@ -80,7 +80,7 @@
<label for="" class="col-sm-2 control-label">涓绘満缁<span class="red-fonts">*</span></label>
<div class="col-sm-4">
<div>
<select id="asset_groups" name="asset_groups" class="form-control m-b" size="5" multiple>
<select id="asset_groups" name="asset_groups" class="form-control m-b" size="10" multiple>
{% for asset_group in asset_groups %}
<option value="{{ asset_group.id }}">{{ asset_group.name }}</option>
{% endfor %}

@ -36,6 +36,12 @@
<li id="jperm">
<a href="#"><i class="fa fa-edit"></i> <span class="nav-label">鎺堟潈绠$悊</span><span class="fa arrow"></span></a>
<ul class="nav nav-second-level">
<li id="dept_perm_add">
<a href="/jperm/dept_perm_add/">閮ㄩ棬鎺堟潈</a>
</li>
<li id="dept_perm_list">
<a href="/jperm/dept_perm_list/">鎺堟潈鏌ョ湅</a>
</li>
<li id="perm_add">
<a href="/jperm/perm_add/">鎺堟潈娣诲姞</a>
</li>

Loading鈥
Cancel
Save