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
|
||||
"""
|
||||
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":
|
||||
try:
|
||||
# 获取参数删除的role对象
|
||||
role_id = request.POST.get("id")
|
||||
role = get_object(PermRole, id=role_id)
|
||||
if not role:
|
||||
logger.warning(u"Delete Role: %s not exist" % role.name)
|
||||
raise ServerError(u"%s 无数据记录" % role.name)
|
||||
logger.warning(u"Delete Role: role_id %s not exist" % role_id)
|
||||
raise ServerError(u"role_id %s 无数据记录" % role_id)
|
||||
role_key = role.key_path
|
||||
# 删除推送到主机上的role
|
||||
recycle_assets = [push.asset for push in role.perm_push.all() if push.success]
|
||||
|
|
|
@ -84,22 +84,43 @@
|
|||
|
||||
<script>
|
||||
function remove_role(role_id){
|
||||
if (confirm("对应资产上已推送的系统用户会被删除,包括其家目录,请谨慎操作!")) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "{% url 'role_del' %}",
|
||||
data: "id=" + role_id,
|
||||
success: function(msg){
|
||||
alert( "成功: " + msg );
|
||||
var del_row = $('tbody#edittbody>tr#' + role_id);
|
||||
del_row.remove()
|
||||
},
|
||||
error: function (msg) {
|
||||
console.log(msg);
|
||||
alert("失败: " + msg.responseText)
|
||||
}
|
||||
});
|
||||
}
|
||||
$.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({
|
||||
type: "POST",
|
||||
url: "{% url 'role_del' %}",
|
||||
data: "id=" + role_id,
|
||||
success: function(msg){
|
||||
alert( "成功: " + msg );
|
||||
var del_row = $('tbody#edittbody>tr#' + role_id);
|
||||
del_row.remove()
|
||||
},
|
||||
error: function (msg) {
|
||||
console.log(msg);
|
||||
alert("失败: " + msg.responseText)
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function(error) {
|
||||
alert(error)
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue