mirror of https://github.com/jumpserver/jumpserver
Merge branch 'dev' of git.coding.net:jumpserver/jumpserver into dev
commit
e65cad5074
|
@ -259,23 +259,23 @@ def get_role_info(role_id, type="all"):
|
|||
asset_groups_obj.append(asset_group)
|
||||
|
||||
if type == "all":
|
||||
return {"rules": rule_push_obj,
|
||||
"users": users_obj,
|
||||
"user_groups": user_groups_obj,
|
||||
"assets": assets_obj,
|
||||
"asset_groups": asset_groups_obj,
|
||||
return {"rules": set(rule_push_obj),
|
||||
"users": set(users_obj),
|
||||
"user_groups": set(user_groups_obj),
|
||||
"assets": set(assets_obj),
|
||||
"asset_groups": set(asset_groups_obj),
|
||||
}
|
||||
|
||||
elif type == "rule":
|
||||
return rule_push_obj
|
||||
return set(rule_push_obj)
|
||||
elif type == "user":
|
||||
return users_obj
|
||||
return set(users_obj)
|
||||
elif type == "user_group":
|
||||
return user_groups_obj
|
||||
return set(user_groups_obj)
|
||||
elif type == "asset":
|
||||
return assets_obj
|
||||
return set(assets_obj)
|
||||
elif type == "asset_group":
|
||||
return asset_groups_obj
|
||||
return set(asset_groups_obj)
|
||||
else:
|
||||
return u"不支持的查询"
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ logger = set_log(LOG_LEVEL, filename='jumpserver_perm.log')
|
|||
def perm_rule_list(request):
|
||||
"""
|
||||
list rule page
|
||||
授权规则列表
|
||||
"""
|
||||
# 渲染数据
|
||||
header_title, path1, path2 = "授权规则", "规则管理", "查看规则"
|
||||
|
@ -46,6 +47,7 @@ def perm_rule_list(request):
|
|||
def perm_rule_detail(request):
|
||||
"""
|
||||
rule detail page
|
||||
授权详情
|
||||
"""
|
||||
# 渲染数据
|
||||
header_title, path1, path2 = "授权规则", "规则管理", "规则详情"
|
||||
|
@ -54,14 +56,18 @@ def perm_rule_detail(request):
|
|||
rule_id = request.GET.get("id")
|
||||
rule_obj = PermRule.objects.get(id=rule_id)
|
||||
user_obj = rule_obj.user.all()
|
||||
user_group_obj = rule_obj.user_group.all()
|
||||
asset_obj = rule_obj.asset.all()
|
||||
asset_group_obj = rule_obj.asset_group.all()
|
||||
roles_name = [role.name for role in rule_obj.role.all()]
|
||||
|
||||
# 渲染数据
|
||||
roles_name = ','.join(roles_name)
|
||||
rule = rule_obj
|
||||
users = user_obj
|
||||
user_groups = user_group_obj
|
||||
assets = asset_obj
|
||||
asset_groups = asset_group_obj
|
||||
|
||||
return my_render('jperm/perm_rule_detail.html', locals(), request)
|
||||
|
||||
|
@ -69,6 +75,7 @@ def perm_rule_detail(request):
|
|||
def perm_rule_add(request):
|
||||
"""
|
||||
add rule page
|
||||
添加授权
|
||||
"""
|
||||
# 渲染数据
|
||||
header_title, path1, path2 = "授权规则", "规则管理", "添加规则"
|
||||
|
@ -116,8 +123,8 @@ def perm_rule_add(request):
|
|||
need_push_asset = set()
|
||||
|
||||
for role in roles_obj:
|
||||
asset_no_push = get_role_push_host(role=role)[0] # 获取某角色已经推送的资产
|
||||
need_push_asset.update(set(calc_assets) - set(asset_no_push))
|
||||
asset_no_push = get_role_push_host(role=role)[1] # 获取某角色已经推送的资产
|
||||
need_push_asset.update(set(calc_assets) & set(asset_no_push))
|
||||
if need_push_asset:
|
||||
raise ServerError(u'没有推送角色 %s 的主机 %s'
|
||||
% (role.name, ','.join([asset.hostname for asset in need_push_asset])))
|
||||
|
@ -183,15 +190,13 @@ def perm_rule_edit(request):
|
|||
# 获取需要授权的用户列表
|
||||
users_obj = [User.objects.get(id=user_id) for user_id in users_select]
|
||||
user_groups_obj = [UserGroup.objects.get(id=group_id) for group_id in user_groups_select]
|
||||
# group_users_obj = [user for user in [group.user_set.all() for group in user_groups_obj]]
|
||||
# calc_users = set(group_users_obj) | set(users_obj)
|
||||
|
||||
# 获取授予的角色列表
|
||||
roles_obj = [PermRole.objects.get(id=role_id) for role_id in roles_select]
|
||||
need_push_asset = set()
|
||||
for role in roles_obj:
|
||||
asset_no_push = get_role_push_host(role=role)[0] # 获取某角色已经推送的资产
|
||||
need_push_asset.update(set(calc_assets) - set(asset_no_push))
|
||||
asset_no_push = get_role_push_host(role=role)[1] # 获取某角色已经推送的资产
|
||||
need_push_asset.update(set(calc_assets) & set(asset_no_push))
|
||||
if need_push_asset:
|
||||
raise ServerError(u'没有推送角色 %s 的主机 %s'
|
||||
% (role.name, ','.join([asset.hostname for asset in need_push_asset])))
|
||||
|
|
|
@ -13,7 +13,7 @@ password = mysql234
|
|||
database = jumpserver
|
||||
|
||||
[websocket]
|
||||
web_socket_host = j:3000
|
||||
web_socket_host = 127.0.0.1:3000
|
||||
|
||||
[mail]
|
||||
mail_enable = 1
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
{% for rule in rules %}
|
||||
<tr class="gradeX">
|
||||
<td class="text-center"> {{ rule.date_added | date:"Y-m-d H:i:s"}} </td>
|
||||
<td class="text-center"> {{ rule.name }} </td>
|
||||
<td class="text-center"> <a href="/jperm/perm_rule_detail/?id={{ rule.id }}">{{ rule.name }}</a> </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
@ -54,7 +54,7 @@
|
|||
<div class="col-sm-4">
|
||||
<div class="ibox float-e-margins">
|
||||
<div class="ibox-title">
|
||||
<span class="label label-primary"><b>{{ role.name }} - 授权用户/用户组</b></span>
|
||||
<span class="label label-primary"><b>授权用户/用户组</b></span>
|
||||
<div class="ibox-tools">
|
||||
<a class="collapse-link">
|
||||
<i class="fa fa-chevron-up"></i>
|
||||
|
@ -74,33 +74,47 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="ibox-content">
|
||||
<div>
|
||||
<div class="text-left">
|
||||
<div class="text-center" style="float: left;">
|
||||
<table class="table table-striped" id="ugedit" >
|
||||
<thead>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center">用户</th>
|
||||
<th class="text-center">用户组</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{% for user in users %}
|
||||
<tr class="gradeX">
|
||||
<td class="text-center"> {{ user.name }} </td>
|
||||
<td class="text-center"> {{ user | user_which_groups:"group" }} </td>
|
||||
<td class="text-center"> <a href="/juser/user_detail/?id={{ user.id }}">{{ user.name }}</a> </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="text-center" style="float: right;">
|
||||
<table class="table table-striped" id="ugedit" >
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center">用户组</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{% for group in user_groups %}
|
||||
<tr class="gradeX">
|
||||
<td class="text-center"> <a href="/juser/user_list/?gid={{ group.id }}">{{ group.name }}</a> </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<div class="ibox float-e-margins">
|
||||
<div class="ibox-title">
|
||||
<span class="label label-primary"><b>{{ role.name }} - 授权主机/主机组</b></span>
|
||||
<span class="label label-primary"><b>授权主机/主机组</b></span>
|
||||
<div class="ibox-tools">
|
||||
<a class="collapse-link">
|
||||
<i class="fa fa-chevron-up"></i>
|
||||
|
@ -120,29 +134,33 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="ibox-content">
|
||||
<div>
|
||||
<div class="text-left">
|
||||
<div class="text-center" style="float:left;">
|
||||
<table class="table table-striped" id="agedit" >
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center">主机</th>
|
||||
<th class="text-center">主机组</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for asset in assets %}
|
||||
<tr class="gradeX">
|
||||
<td class="text-center"> {{ asset.ip }} </td>
|
||||
<td class="text-center"> {{ asset | asset_which_groups:"group" }} </td>
|
||||
<td class="text-center"> <a href="/jasset/asset_detail/?id={{ asset.id }}">{{ asset.ip }}</a> </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
<div class="text-center" style="float:right;">
|
||||
<table class="table table-striped" id="agedit" >
|
||||
<tr>
|
||||
<th class="text-center">主机组</th>
|
||||
</tr>
|
||||
{% for group in asset_groups %}
|
||||
<tr class="gradeX">
|
||||
<td class="text-center"> <a href="/jasset/asset_list/?group_id={{ group.id }}">{{ group.name }}</a> </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
|
|
|
@ -83,29 +83,40 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="ibox-content">
|
||||
<div>
|
||||
<div class="text-left">
|
||||
<div class="text-center" style="float: left;">
|
||||
<table class="table table-striped" id="ugedit" >
|
||||
<thead>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center">用户</th>
|
||||
<th class="text-center">用户组</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="gradeX">
|
||||
{% for user in users %}
|
||||
<td class="text-center"> {{ user.name }} </td>
|
||||
{% endfor %}
|
||||
{% for group in user_groups %}
|
||||
<td class="text-center"> {{ group.name }} </td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
</tbody>
|
||||
<tbody>
|
||||
{% for user in users %}
|
||||
<tr class="gradeX">
|
||||
<td class="text-center"> <a href="/juser/user_detail/?id={{ user.id }}">{{ user.name }}</a> </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="text-center" style="float: right;">
|
||||
<table class="table table-striped" id="ugedit" >
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center">用户组</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{% for group in user_groups %}
|
||||
<tr class="gradeX">
|
||||
<td class="text-center"> <a href="/juser/user_list/?gid={{ group.id }}">{{ group.name }}</a> </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -132,28 +143,30 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="ibox-content">
|
||||
<div>
|
||||
<div class="text-left">
|
||||
<div class="text-center" style="float:left;">
|
||||
<table class="table table-striped" id="agedit" >
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center">主机</th>
|
||||
<th class="text-center">主机组</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for asset in assets %}
|
||||
<tr class="gradeX">
|
||||
{% for asset in assets %}
|
||||
<td class="text-center"> {{ asset.ip }} </td>
|
||||
{% endfor %}
|
||||
{% for group in asset_groups %}
|
||||
<td class="text-center"> {{ group.name }} </td>
|
||||
{% endfor %}
|
||||
<td class="text-center"> <a href="/jasset/asset_detail/?id={{ asset.id }}">{{ asset.ip }}</a> </td>
|
||||
</tr>
|
||||
</tbody>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
<div class="text-center" style="float:right;">
|
||||
<table class="table table-striped" id="agedit" >
|
||||
<tr>
|
||||
<th class="text-center">主机组</th>
|
||||
</tr>
|
||||
{% for group in asset_groups %}
|
||||
<tr class="gradeX">
|
||||
<td class="text-center"> <a href="/jasset/asset_list/?group_id={{ group.id }}">{{ group.name }}</a> </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
<tbody id="edittbody">
|
||||
{% for rule in rules %}
|
||||
<tr class="gradeX" id={{ rule.id }}>
|
||||
<td class="text-center"> {{ rule.name }} </td>
|
||||
<td class="text-center"> <a href="/jperm/perm_rule_detail/?id={{ rule.id }}" >{{ rule.name }}</a> </td>
|
||||
<td class="text-center">
|
||||
{{ rule | rule_member_count:"user" }}
|
||||
</td>
|
||||
|
@ -79,7 +79,6 @@
|
|||
{{ rule | rule_member_count:"role" }}
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<a href="/jperm/perm_rule_detail/?id={{ rule.id }}" class="btn btn-xs btn-primary">详情</a>
|
||||
<a href="/jperm/perm_rule_edit/?id={{ rule.id }}" class="btn btn-xs btn-info">编辑</a>
|
||||
<button onclick="remove_rule({{ rule.id }})" class="btn btn-xs btn-danger">删除</button>
|
||||
</td>
|
||||
|
|
Loading…
Reference in New Issue