mirror of https://github.com/jumpserver/jumpserver
1. 用户的批量回收, 角色删除会回收推送的角色
parent
8723d673d7
commit
58082179fe
|
@ -218,25 +218,25 @@ def get_role_info(role_id, type="all"):
|
|||
"""
|
||||
# 获取role对应的授权规则
|
||||
role_obj = PermRole.objects.get(id=role_id)
|
||||
rules_obj = role_obj.perm_rule.all()
|
||||
rule_push_obj = role_obj.perm_rule.all()
|
||||
# 获取role 对应的用户 和 用户组
|
||||
# 获取role 对应的主机 和主机组
|
||||
users_obj = []
|
||||
assets_obj = []
|
||||
user_groups_obj = []
|
||||
asset_groups_obj = []
|
||||
for rule in rules_obj:
|
||||
for user in rule.user.all():
|
||||
for push in rule_push_obj:
|
||||
for user in push.user.all():
|
||||
users_obj.append(user)
|
||||
for asset in rule.asset.all():
|
||||
for asset in push.asset.all():
|
||||
assets_obj.append(asset)
|
||||
for user_group in rule.user_group.all():
|
||||
for user_group in push.user_group.all():
|
||||
user_groups_obj.append(user_group)
|
||||
for asset_group in rule.asset_group.all():
|
||||
for asset_group in push.asset_group.all():
|
||||
asset_groups_obj.append(asset_group)
|
||||
|
||||
if type == "all":
|
||||
return {"rules": rules_obj,
|
||||
return {"rules": rule_push_obj,
|
||||
"users": users_obj,
|
||||
"user_groups": user_groups_obj,
|
||||
"assets": assets_obj,
|
||||
|
@ -244,7 +244,7 @@ def get_role_info(role_id, type="all"):
|
|||
}
|
||||
|
||||
elif type == "rule":
|
||||
return rules_obj
|
||||
return rule_push_obj
|
||||
elif type == "user":
|
||||
return users_obj
|
||||
elif type == "user_group":
|
||||
|
|
|
@ -297,12 +297,25 @@ def perm_role_delete(request):
|
|||
role_id = request.POST.get("id")
|
||||
role = PermRole.objects.get(id=role_id)
|
||||
role_key = role.key_path
|
||||
|
||||
# 删除推送到主机上的role
|
||||
recycle_assets = [push.asset for push in role.perm_push.all() if push.success]
|
||||
print recycle_assets
|
||||
|
||||
if recycle_assets:
|
||||
recycle_resource = gen_resource(recycle_assets)
|
||||
task = Tasks(recycle_resource)
|
||||
msg = task.del_user(get_object(PermRole, id=role_id).name)
|
||||
# TODO: 判断返回结果,处理异常
|
||||
print msg
|
||||
|
||||
# 删除存储的秘钥,以及目录
|
||||
key_files = os.listdir(role_key)
|
||||
for key_file in key_files:
|
||||
os.remove(os.path.join(role_key, key_file))
|
||||
os.rmdir(role_key)
|
||||
# 数据库里删除记录
|
||||
|
||||
# 数据库里删除记录 TODO: 判断返回结果,处理异常
|
||||
role.delete()
|
||||
return HttpResponse(u"删除角色: %s" % role.name)
|
||||
else:
|
||||
|
@ -585,15 +598,20 @@ def perm_sudo_delete(request):
|
|||
def perm_role_recycle(request):
|
||||
role_id = request.GET.get('role_id')
|
||||
asset_ids = request.GET.get('asset_id').split(',')
|
||||
success = request.GET.get("success")
|
||||
print request.GET
|
||||
|
||||
if success == "True":
|
||||
assets = [get_object(Asset, id=asset_id) for asset_id in asset_ids]
|
||||
recycle_resource = gen_resource(assets)
|
||||
task = Tasks(recycle_resource)
|
||||
msg = task.del_user(get_object(PermRole, id=role_id).name)
|
||||
print msg
|
||||
assets = [get_object(Asset, id=asset_id) for asset_id in asset_ids]
|
||||
|
||||
recycle_assets = []
|
||||
for asset in assets:
|
||||
if True in [push.success for push in asset.perm_push.all()]:
|
||||
recycle_assets.append(asset)
|
||||
|
||||
recycle_resource = gen_resource(recycle_assets)
|
||||
task = Tasks(recycle_resource)
|
||||
msg = task.del_user(get_object(PermRole, id=role_id).name)
|
||||
# TODO: 判断返回结果,处理异常
|
||||
print msg
|
||||
|
||||
for asset_id in asset_ids:
|
||||
asset = get_object(Asset, id=asset_id)
|
||||
|
|
|
@ -198,7 +198,7 @@
|
|||
{% else %}
|
||||
<td class="text-center" style="color: #ec4758;cursor: help" title="{{ info.result }}" >{{ info.success | yesno:"成功,失败,未知" }} </td>
|
||||
{% endif %}
|
||||
<td class="text-center" ><a class="fa fa-times del" href="/jperm/role/recycle/?role_id={{ role.id }}&asset_id={{ asset.id }}&success={{ info.success }}" style="color: #ec4758;"></a></td>
|
||||
<td class="text-center" ><a class="fa fa-times del" href="/jperm/role/recycle/?role_id={{ role.id }}&asset_id={{ asset.id }}" style="color: #ec4758;"></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
Loading…
Reference in New Issue