mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-07-31 22:36:37 +00:00
ҳ
This commit is contained in:
parent
546393d9c3
commit
475501595e
@ -5,8 +5,7 @@ from jasset.models import Asset, BisGroup
|
||||
|
||||
class Perm(models.Model):
|
||||
user_group = models.ForeignKey(UserGroup)
|
||||
asset_group = models.ManyToManyField(BisGroup)
|
||||
comment = models.CharField(max_length=100)
|
||||
asset_group = models.ForeignKey(BisGroup)
|
||||
|
||||
def __unicode__(self):
|
||||
return '%s_%s' % (self.user_group.name, self.asset_group.name)
|
||||
|
@ -122,47 +122,40 @@ def dept_perm_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)
|
||||
if perm:
|
||||
perm = perm[0]
|
||||
user_group_list = []
|
||||
asset_group_list = []
|
||||
|
||||
for user_group_id in user_group_id_list:
|
||||
user_group_list.extend(UserGroup.objects.filter(id=user_group_id))
|
||||
def perm_group_update(user_group_id, asset_groups_id_list):
|
||||
user_group = UserGroup.objects.filter(id=user_group_id)
|
||||
if user_group:
|
||||
user_group = user_group[0]
|
||||
old_asset_group = [perm.asset_group for perm in user_group.perm_set.all()]
|
||||
new_asset_group = []
|
||||
|
||||
for asset_group_id in asset_groups_id_list:
|
||||
asset_group_list.extend(BisGroup.objects.filter(id=asset_group_id))
|
||||
new_asset_group.extend(BisGroup.objects.filter(id=asset_group_id))
|
||||
|
||||
perm.user_group.clear()
|
||||
perm.asset_group.clear()
|
||||
perm.user_group = user_group_list
|
||||
perm.asset_group = asset_group_list
|
||||
del_asset_group = [asset_group for asset_group in old_asset_group if asset_group not in new_asset_group]
|
||||
add_asset_group = [asset_group for asset_group in new_asset_group if asset_group not in old_asset_group]
|
||||
|
||||
for asset_group in del_asset_group:
|
||||
Perm.objects.filter(user_group=user_group, asset_group=asset_group).delete()
|
||||
|
||||
for asset_group in add_asset_group:
|
||||
Perm(user_group=user_group, asset_group=asset_group).save()
|
||||
|
||||
|
||||
def perm_edit(request):
|
||||
if request.method == 'GET':
|
||||
header_title, path1, path2 = u'编辑授权', u'授权管理', u'授权编辑'
|
||||
perm_id = request.GET.get('id', '')
|
||||
perm = Perm.objects.filter(id=perm_id)
|
||||
if perm:
|
||||
perm = perm[0]
|
||||
name = perm.name
|
||||
comment = perm.comment
|
||||
user_groups_select = perm.user_group.all()
|
||||
asset_groups_select = perm.asset_group.all()
|
||||
|
||||
user_groups_all = UserGroup.objects.all()
|
||||
user_group_id = request.GET.get('id', '')
|
||||
user_group = UserGroup.objects.filter(id=user_group_id)
|
||||
if user_group:
|
||||
user_group = user_group[0]
|
||||
asset_groups_all = BisGroup.objects.all()
|
||||
|
||||
user_groups = [user_group for user_group in user_groups_all if user_group not in user_groups_select]
|
||||
asset_groups_select = [perm.asset_group for perm in user_group.perm_set.all()]
|
||||
asset_groups = [asset_group for asset_group in asset_groups_all if asset_group not in asset_groups_select]
|
||||
else:
|
||||
perm_id = request.POST.get('perm_id', '')
|
||||
user_group_id_list = request.POST.getlist('user_groups_select')
|
||||
user_group_id = request.POST.get('user_group_id')
|
||||
asset_group_id_list = request.POST.getlist('asset_groups_select')
|
||||
perm_group_update(perm_id, user_group_id_list, asset_group_id_list)
|
||||
perm_group_update(user_group_id, asset_group_id_list)
|
||||
|
||||
return HttpResponseRedirect('/jperm/perm_list/')
|
||||
return render_to_response('jperm/perm_edit.html', locals(), context_instance=RequestContext(request))
|
||||
|
@ -108,6 +108,27 @@ def dept_perm_count(dept_id):
|
||||
return 0
|
||||
|
||||
|
||||
@register.filter(name='ugrp_perm_agrp_count')
|
||||
def ugrp_perm_agrp_count(user_group_id):
|
||||
user_group = UserGroup.objects.filter(id=user_group_id)
|
||||
if user_group:
|
||||
user_group = user_group[0]
|
||||
return user_group.perm_set.all().count()
|
||||
return 0
|
||||
|
||||
|
||||
@register.filter(name='ugrp_perm_asset_count')
|
||||
def ugrp_perm_asset_count(user_group_id):
|
||||
user_group = UserGroup.objects.filter(id=user_group_id)
|
||||
assets = []
|
||||
if user_group:
|
||||
user_group = user_group[0]
|
||||
asset_groups = [perm.asset_group for perm in user_group.perm_set.all()]
|
||||
for asset_group in asset_groups:
|
||||
assets.extend(asset_group.asset_set.all())
|
||||
return len(set(assets))
|
||||
|
||||
|
||||
@register.filter(name='group_type_to_str')
|
||||
def group_type_to_str(type_name):
|
||||
group_types = {
|
||||
|
@ -20,7 +20,7 @@ urlpatterns = patterns('juser.views',
|
||||
(r'^group_del_ajax/$', 'group_del_ajax'),
|
||||
(r'^group_edit/$', 'group_edit'),
|
||||
(r'^user_add/$', 'user_add'),
|
||||
(r'^user_list/$', 'user_list'),
|
||||
(r'^user_list/(?P<option>\w*)/?$', 'user_list'),
|
||||
(r'^user_detail/$', 'user_detail'),
|
||||
(r'^user_del/$', 'user_del'),
|
||||
(r'^user_del_ajax/$', 'user_del_ajax'),
|
||||
|
@ -502,14 +502,31 @@ def user_add(request):
|
||||
return render_to_response('juser/user_add.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def user_list(request):
|
||||
def user_list(request, option=""):
|
||||
user_role = {'SU': u'超级管理员', 'GA': u'组管理员', 'CU': u'普通用户'}
|
||||
header_title, path1, path2 = '查看用户', '用户管理', '用户列表'
|
||||
keyword = request.GET.get('search', '')
|
||||
if keyword:
|
||||
keyword = request.GET.get('keyword', '')
|
||||
gid = request.GET.get('gid', '')
|
||||
did = request.GET.get('did', '')
|
||||
if option == "search":
|
||||
contact_list = User.objects.filter(Q(username__icontains=keyword) | Q(name__icontains=keyword)).order_by('name')
|
||||
elif option == "group":
|
||||
user_group = UserGroup.objects.filter(id=gid)
|
||||
if user_group:
|
||||
user_group = user_group[0]
|
||||
contact_list = user_group.user_set.all().order_by('name')
|
||||
else:
|
||||
contact_list = []
|
||||
elif option == "dept":
|
||||
dept = DEPT.objects.filter(id=did)
|
||||
if dept:
|
||||
dept = dept[0]
|
||||
contact_list = dept.user_set.all().order_by('name')
|
||||
else:
|
||||
contact_list = []
|
||||
else:
|
||||
contact_list = User.objects.all().order_by('id')
|
||||
print option
|
||||
contact_list = User.objects.all().order_by('name')
|
||||
|
||||
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(contact_list, request)
|
||||
|
||||
|
@ -48,8 +48,8 @@
|
||||
<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>
|
||||
<th class="text-center">备注</th>
|
||||
<th class="text-center">操作</th>
|
||||
</tr>
|
||||
@ -63,7 +63,7 @@
|
||||
<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>
|
||||
<a href="../dept_perm_edit/?id={{ dept.id }}" class="btn btn-xs btn-danger">授权编辑</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -38,43 +38,10 @@
|
||||
{% endif %}
|
||||
<div class="row">
|
||||
<div class="form-group">
|
||||
<label for="name" class="col-sm-2 control-label">授权名<span class="red-fonts">*</span></label>
|
||||
<div class="col-sm-8">
|
||||
<input id="name" name="name" placeholder="授权名称" type="text" class="form-control" value="{{ name }}">
|
||||
<input id="perm_id" name="perm_id" style="display: none" value="{{ perm.id }}">
|
||||
<span class="help-block m-b-none">取个名字方便辨识</span>
|
||||
</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>
|
||||
<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>
|
||||
{% for user_group in user_groups %}
|
||||
<option value="{{ user_group.id }}">{{ user_group.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-sm-1">
|
||||
<div class="btn-group" style="margin-top: 12px;">
|
||||
<button type="button" class="btn btn-white" onclick="move('user_groups', 'user_groups_select')"><i class="fa fa-chevron-right"></i></button>
|
||||
<button type="button" class="btn btn-white" onclick="move('user_groups_select', 'user_groups')"><i class="fa fa-chevron-left"></i> </button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-3">
|
||||
<div>
|
||||
<select id="user_groups_select" name="user_groups_select" class="form-control m-b" size="5" multiple>
|
||||
{% for user_group in user_groups_select %}
|
||||
<option value="{{ user_group.id }}">{{ user_group.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<input id="user_group_id" name="user_group_id"type="text" value="{{ user_group.id }}" style="display: none">
|
||||
<input id="user_group_name" name="user_group_name" type="text" class="form-control" value="{{ user_group.name }}" readonly>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -84,7 +51,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="12" multiple>
|
||||
{% for asset_group in asset_groups %}
|
||||
<option value="{{ asset_group.id }}">{{ asset_group.name }}</option>
|
||||
{% endfor %}
|
||||
@ -93,7 +60,7 @@
|
||||
</div>
|
||||
|
||||
<div class="col-sm-1">
|
||||
<div class="btn-group" style="margin-top: 12px;">
|
||||
<div class="btn-group" style="margin-top: 42px;">
|
||||
<button type="button" class="btn btn-white" onclick="move('asset_groups', 'asset_groups_select')"><i class="fa fa-chevron-right"></i></button>
|
||||
<button type="button" class="btn btn-white" onclick="move('asset_groups_select', 'asset_groups')"><i class="fa fa-chevron-left"></i> </button>
|
||||
</div>
|
||||
@ -101,7 +68,7 @@
|
||||
|
||||
<div class="col-sm-3">
|
||||
<div>
|
||||
<select id="asset_groups_select" name="asset_groups_select" class="form-control m-b" size="5" multiple>
|
||||
<select id="asset_groups_select" name="asset_groups_select" class="form-control m-b" size="12" multiple>
|
||||
{% for asset_group in asset_groups_select %}
|
||||
<option value="{{ asset_group.id }}">{{ asset_group.name }}</option>
|
||||
{% endfor %}
|
||||
@ -109,16 +76,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="group_name" class="col-sm-2 control-label">备注</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="comment" name="comment" placeholder="备注说明" type="text" class="form-control" value="{{ comment }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="form-group">
|
||||
|
@ -48,9 +48,9 @@
|
||||
<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>
|
||||
<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>
|
||||
@ -61,12 +61,13 @@
|
||||
<td class="text-center"> {{ group.name }} </td>
|
||||
<td class="text-center"> {{ group.dept.name }} </td>
|
||||
<td class="text-center"> {{ group.id | member_count }} </td>
|
||||
<td class="text-center"> {{ group.id | member_count }} </td>
|
||||
<td class="text-center"> {{ group.id | member_count }} </td>
|
||||
<td class="text-center"> {{ group.id | ugrp_perm_agrp_count }} </td>
|
||||
<td class="text-center"> {{ group.id | ugrp_perm_asset_count }} </td>
|
||||
<td class="text-center"> {{ group.comment }} </td>
|
||||
<td class="text-center">
|
||||
<a href="../perm_edit/?id={{ group.id }}" class="btn btn-xs btn-info">授权编辑</a>
|
||||
{# <a href="../group_del/?id={{ group.id }}" class="btn btn-xs btn-danger">删除</a>#}
|
||||
<a href="../perm_edit/?id={{ group.id }}" class="btn btn-xs btn-primary">主机组</a>
|
||||
<a href="../perm_edit/?id={{ group.id }}" class="btn btn-xs btn-info">主机</a>
|
||||
<a href="../perm_edit/?id={{ group.id }}" class="btn btn-xs btn-danger">授权编辑</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -51,7 +51,7 @@
|
||||
<input type="checkbox" id="select_all" onclick="selectAll()" name="select_all">
|
||||
</th>
|
||||
<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>
|
||||
@ -66,7 +66,7 @@
|
||||
<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="../user_list/dept/?did={{ dept.id }}" class="btn btn-xs btn-primary">成员</a>
|
||||
<a href="../dept_edit/?id={{ dept.id }}" class="btn btn-xs btn-info">编辑</a>
|
||||
<a href="../dept_del/?id={{ dept.id }}" class="btn btn-xs btn-danger">删除</a>
|
||||
</td>
|
||||
|
@ -52,7 +52,7 @@
|
||||
</th>
|
||||
<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>
|
||||
<th class="text-center">操作</th>
|
||||
</tr>
|
||||
@ -68,7 +68,7 @@
|
||||
<td class="text-center"> {{ group.id | member_count }} </td>
|
||||
<td class="text-center"> {{ group.comment }} </td>
|
||||
<td class="text-center">
|
||||
<a title="[ {{ group.name }} ] 成员信息" href="../group_detail/?id={{ group.id }}" class="iframe btn btn-xs btn-primary">成员</a>
|
||||
<a href="../user_list/group/?gid={{ group.id }}" class="btn btn-xs btn-primary">成员</a>
|
||||
<a href="../group_edit/?id={{ group.id }}" class="btn btn-xs btn-info">编辑</a>
|
||||
<a href="../group_del/?id={{ group.id }}" class="btn btn-xs btn-danger">删除</a>
|
||||
</td>
|
||||
|
@ -40,9 +40,6 @@
|
||||
<a href="/jperm/dept_perm_list/">部门授权</a>
|
||||
</li>
|
||||
|
||||
<li id="perm_add">
|
||||
<a href="/jperm/perm_add/">授权添加</a>
|
||||
</li>
|
||||
<li id="perm_list">
|
||||
<a href="/jperm/perm_list/">小组授权</a>
|
||||
</li>
|
||||
|
Loading…
Reference in New Issue
Block a user