mirror of https://github.com/jumpserver/jumpserver
添加授权
parent
8bc7485c88
commit
a8ce9e9952
|
@ -4,6 +4,7 @@ from django.shortcuts import render_to_response
|
|||
from django.http import HttpResponseRedirect
|
||||
from juser.models import User
|
||||
from jasset.models import Asset
|
||||
from jpermission.models import Permission
|
||||
|
||||
|
||||
def perm_user_list(request):
|
||||
|
@ -14,6 +15,7 @@ def perm_user_list(request):
|
|||
|
||||
def perm_add(request):
|
||||
header_title, path1, path2 = u'添加授权 | Add User perm.', u'授权管理', u'添加授权'
|
||||
if request.method == 'GET':
|
||||
username = request.GET.get('username', None)
|
||||
if not username:
|
||||
return HttpResponseRedirect('/')
|
||||
|
@ -26,4 +28,15 @@ def perm_add(request):
|
|||
hosts_all = Asset.objects.all()
|
||||
hosts = list(set(hosts_all) - set(permed_hosts))
|
||||
|
||||
else:
|
||||
username = request.POST.get('username', None)
|
||||
host_ips = request.POST.getlist('host_ips', None)
|
||||
|
||||
user = User.objects.get(username=username)
|
||||
for ip in host_ips:
|
||||
asset = Asset.objects.get(ip=ip)
|
||||
perm = Permission(user=user, asset=asset)
|
||||
perm.save()
|
||||
msg = u'添加成功'
|
||||
|
||||
return render_to_response('jperm/perm_add.html', locals())
|
|
@ -37,14 +37,17 @@
|
|||
{% endif %}
|
||||
<div class="form-group">
|
||||
<div class="col-sm-8">
|
||||
<select id="host_ips" name="host_ips" multiple>
|
||||
<input name="username" value="{{ user.username }}" hidden="hidden">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-8">
|
||||
<select id="host_ips" name="host_ips" multiple style="width: 100%">
|
||||
{% for host in hosts %}
|
||||
<option value="{{ host.id }}">{{ host.ip }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% for host in hosts %}
|
||||
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue