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

View File

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