You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jumpserver/jperm/views.py

85 lines
2.8 KiB

10 years ago
# coding: utf-8
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
10 years ago
from juser.models import User, UserGroup
from jasset.models import Asset
10 years ago
from jperm.models import Perm
10 years ago
from django.core.paginator import Paginator, EmptyPage, InvalidPage
def perm_host(request):
header_title, path1, path2 = u'主机授权 | Perm Host Detail.', u'jperm', u'perm_host'
users = contact_list = User.objects.all().order_by('id')
10 years ago
groups = contact_list2 = UserGroup.objects.all().order_by('id')
10 years ago
p = paginator = Paginator(contact_list, 10)
10 years ago
p2 = paginator2 = Paginator(contact_list2, 10)
10 years ago
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
contacts = paginator.page(page)
10 years ago
contacts2 = paginator2.page(page)
10 years ago
except (EmptyPage, InvalidPage):
contacts = paginator.page(paginator.num_pages)
10 years ago
contacts2 = paginator2.page(paginator2.num_pages)
return render_to_response('jperm/perm_host.html', locals())
10 years ago
def perm_edit(request):
header_title, path1, path2 = u'授权编辑 | Perm Edit.', u'jperm', u'perm_edit'
if request.method == 'GET':
if request.GET.get('id', None):
pass
def perm_add(request):
header_title, path1, path2 = u'添加授权 | Add User perm.', u'授权管理', u'添加授权'
10 years ago
if request.method == 'GET':
username = request.GET.get('username', None)
if not username:
return HttpResponseRedirect('/')
user = User.objects.get(username=username)
permed_hosts = []
10 years ago
for perm in user.perm_set.all():
10 years ago
permed_hosts.append(perm.asset)
hosts_all = Asset.objects.all()
hosts = list(set(hosts_all) - set(permed_hosts))
else:
username = request.POST.get('username', None)
10 years ago
host_ids = request.POST.getlist('host_ids', None)
10 years ago
user = User.objects.get(username=username)
10 years ago
for id in host_ids:
asset = Asset.objects.get(id=id)
10 years ago
perm = Perm(user=user, asset=asset)
10 years ago
perm.save()
msg = u'添加成功'
return render_to_response('jperm/perm_add.html', locals())
def perm_user_show(request):
header_title, path1, path2 = u'查看授权用户 | Perm User Detail.', u'授权管理', u'用户详情'
users = User.objects.all()
return render_to_response('jperm/perm_user_show.html', locals(),)
def perm_list(request):
header_title, path1, path2 = u'查看用户授权 | Perm User Detail.', u'授权管理', u'用户详情'
username = request.GET.get('username', None)
if not username:
return HttpResponseRedirect('/')
user = User.objects.get(username=username)
hosts = []
10 years ago
for perm in user.perm_set.all():
hosts.append(perm.asset)
return render_to_response('jperm/perm_list.html', locals())