mirror of https://github.com/jumpserver/jumpserver
删除role时提醒那些 主机上的系统用户会被删除, (需求:http://bbs.jumpserver.org/read/325.html)
parent
ed6559bbe9
commit
01cf2d4e7b
|
@ -319,14 +319,37 @@ def perm_role_delete(request):
|
||||||
"""
|
"""
|
||||||
delete role page
|
delete role page
|
||||||
"""
|
"""
|
||||||
|
if request.method == "GET":
|
||||||
|
try:
|
||||||
|
# 获取参数删除的role对象
|
||||||
|
role_id = request.GET.get("id")
|
||||||
|
role = get_object(PermRole, id=role_id)
|
||||||
|
if not role:
|
||||||
|
logger.warning(u"Delete Role: role_id %s not exist" % role_id)
|
||||||
|
raise ServerError(u"role_id %s 无数据记录" % role_id)
|
||||||
|
# 删除推送到主机上的role
|
||||||
|
filter_type = request.GET.get("filter_type")
|
||||||
|
print filter_type
|
||||||
|
if filter_type:
|
||||||
|
if filter_type == "recycle_assets":
|
||||||
|
recycle_assets = [push.asset for push in role.perm_push.all() if push.success]
|
||||||
|
print recycle_assets
|
||||||
|
recycle_assets_ip = ','.join([asset.ip for asset in recycle_assets])
|
||||||
|
return HttpResponse(recycle_assets_ip)
|
||||||
|
else:
|
||||||
|
return HttpResponse("no such filter_type: %s" % filter_type)
|
||||||
|
else:
|
||||||
|
return HttpResponse("filter_type: ?")
|
||||||
|
except ServerError, e:
|
||||||
|
return HttpResponse(e)
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
try:
|
try:
|
||||||
# 获取参数删除的role对象
|
# 获取参数删除的role对象
|
||||||
role_id = request.POST.get("id")
|
role_id = request.POST.get("id")
|
||||||
role = get_object(PermRole, id=role_id)
|
role = get_object(PermRole, id=role_id)
|
||||||
if not role:
|
if not role:
|
||||||
logger.warning(u"Delete Role: %s not exist" % role.name)
|
logger.warning(u"Delete Role: role_id %s not exist" % role_id)
|
||||||
raise ServerError(u"%s 无数据记录" % role.name)
|
raise ServerError(u"role_id %s 无数据记录" % role_id)
|
||||||
role_key = role.key_path
|
role_key = role.key_path
|
||||||
# 删除推送到主机上的role
|
# 删除推送到主机上的role
|
||||||
recycle_assets = [push.asset for push in role.perm_push.all() if push.success]
|
recycle_assets = [push.asset for push in role.perm_push.all() if push.success]
|
||||||
|
|
|
@ -84,7 +84,19 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function remove_role(role_id){
|
function remove_role(role_id){
|
||||||
if (confirm("对应资产上已推送的系统用户会被删除,包括其家目录,请谨慎操作!")) {
|
$.ajax({
|
||||||
|
type: "GET",
|
||||||
|
url: "{% url 'role_del' %}",
|
||||||
|
data: {id: role_id, filter_type: 'recycle_assets'},
|
||||||
|
success: function(data) {
|
||||||
|
console.log(data)
|
||||||
|
if (data) {
|
||||||
|
msg = data + "的系统用户会被删除,包括其家目录,请谨慎操作!"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
msg = "该角色无已推送的系统用户, 可以安全删除"
|
||||||
|
}
|
||||||
|
if (confirm(msg)) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "{% url 'role_del' %}",
|
url: "{% url 'role_del' %}",
|
||||||
|
@ -100,6 +112,15 @@ function remove_role(role_id){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
error: function(error) {
|
||||||
|
alert(error)
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue