修改删除系统用户的交互 (#276)

* fix(api) 修改建立目录的bug

使用bash代替python完成建立777目录的功能

* fix passwd input

* fix(mkdir) 修改mkdirs策略

修改原来导致的bug

* fix passwd input (#232)

修复记录敏感密码bug

* fix passwd input

* fix passwd input

* fix passwd input

* fix(connect) 输入role id时,输入了role名称异常

抓取后并处理

* Update perm_role_edit.html

* fix role delete
pull/825/head
老广 2016-07-26 18:41:58 +08:00 committed by GitHub
parent 27223a1883
commit 270499a4fd
3 changed files with 34 additions and 31 deletions

View File

@ -316,6 +316,8 @@ class MyTask(MyRunner):
""" """
push the ssh authorized key to target. push the ssh authorized key to target.
""" """
if user == 'root':
return {"status": "failed", "msg": "root cann't be delete"}
module_args = 'user="%s" key="{{ lookup("file", "%s") }}" state="absent"' % (user, key_path) module_args = 'user="%s" key="{{ lookup("file", "%s") }}" state="absent"' % (user, key_path)
self.run("authorized_key", module_args, become=True) self.run("authorized_key", module_args, become=True)
@ -361,6 +363,8 @@ class MyTask(MyRunner):
""" """
delete a host user. delete a host user.
""" """
if username == 'root':
return {"status": "failed", "msg": "root cann't be delete"}
module_args = 'name=%s state=absent remove=yes move_home=yes force=yes' % username module_args = 'name=%s state=absent remove=yes move_home=yes force=yes' % username
self.run("user", module_args, become=True) self.run("user", module_args, become=True)
return self.results return self.results
@ -371,6 +375,8 @@ class MyTask(MyRunner):
:param username: :param username:
:return: :return:
""" """
if username == 'root':
return {"status": "failed", "msg": "root cann't be delete"}
module_args = "sed -i 's/^%s.*//' /etc/sudoers" % username module_args = "sed -i 's/^%s.*//' /etc/sudoers" % username
self.run("command", module_args, become=True) self.run("command", module_args, become=True)
return self.results return self.results

View File

@ -333,7 +333,6 @@ def perm_role_delete(request):
raise ServerError(u"role_id %s 无数据记录" % role_id) raise ServerError(u"role_id %s 无数据记录" % role_id)
# 删除推送到主机上的role # 删除推送到主机上的role
filter_type = request.GET.get("filter_type") filter_type = request.GET.get("filter_type")
print filter_type
if filter_type: if filter_type:
if filter_type == "recycle_assets": if filter_type == "recycle_assets":
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

@ -87,39 +87,37 @@ function remove_role(role_id){
url: "{% url 'role_del' %}", url: "{% url 'role_del' %}",
data: {id: role_id, filter_type: 'recycle_assets'}, data: {id: role_id, filter_type: 'recycle_assets'},
success: function(data) { success: function(data) {
console.log(data) var msg = data + " 资产上的系统用户会被删除, 包括其家目录,请谨慎操作!";
if (data) { layer.alert(msg, {
msg = data + "的系统用户会被删除,包括其家目录,请谨慎操作!" title: '警告',
} closeBtn: 0
else { }, function(){
msg = "该角色无已推送的系统用户, 可以安全删除" layer.confirm('危险动作, 除非你非常明白自己在做什么,否则请取消', {
} title: '再次确认',
if (confirm(msg)) { btn: ['确认', '取消']
$.ajax({ }, function(){
type: "POST", $.ajax({
url: "{% url 'role_del' %}", type: "POST",
data: "id=" + role_id, url: "{% url 'role_del' %}",
success: function(msg){ data: "id=" + role_id,
alert( "成功: " + msg ); success: function(msg){
var del_row = $('tbody#edittbody>tr#' + role_id); layer.msg( "成功: " + msg );
del_row.remove() var del_row = $('tbody#edittbody>tr#' + role_id);
}, del_row.remove()
error: function (msg) { },
console.log(msg); error: function (msg) {
alert("失败: " + msg.responseText) console.log(msg);
} layer.alert("失败: " + msg.responseText)
}); }
} });
}, }, function(){
layer.msg('取消', {icon: 1})
})
})},
error: function(error) { error: function(error) {
alert(error) alert(error)
}, }
}); });
} }
</script> </script>