Merge branch 'dev'

pull/36/head
ibuler 2016-01-05 19:29:56 +08:00
commit d9b4f5504c
2 changed files with 62 additions and 18 deletions

View File

@ -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]

View File

@ -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>