mirror of https://github.com/jumpserver/jumpserver
修改 用户左侧显示
parent
b7acef8cb0
commit
f0cd064195
|
@ -1,7 +1,8 @@
|
|||
# coding: utf-8
|
||||
|
||||
from django.shortcuts import render_to_response
|
||||
from django.http import HttpResponseRedirect, HttpResponse
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.template import RequestContext
|
||||
from juser.models import User, UserGroup
|
||||
from jasset.models import Asset, BisGroup
|
||||
from jperm.models import Perm, SudoPerm, CmdGroup
|
||||
|
@ -51,7 +52,7 @@ def perm_list(request):
|
|||
except (EmptyPage, InvalidPage):
|
||||
contacts = paginator.page(paginator.num_pages)
|
||||
contacts2 = paginator2.page(paginator2.num_pages)
|
||||
return render_to_response('jperm/perm_list.html', locals())
|
||||
return render_to_response('jperm/perm_list.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def user_asset_cmd_groups_get(user_groups_select='', asset_groups_select='', cmd_groups_select=''):
|
||||
|
@ -92,7 +93,7 @@ def perm_add(request):
|
|||
perm.user_group = user_groups
|
||||
perm.asset_group = asset_groups
|
||||
msg = '添加成功'
|
||||
return render_to_response('jperm/perm_add.html', locals())
|
||||
return render_to_response('jperm/perm_add.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def perm_list_ajax(request):
|
||||
|
@ -151,8 +152,8 @@ def perm_edit(request):
|
|||
user_group_name = request.POST.get('user_group_name')
|
||||
asset_groups_selected = request.POST.getlist('asset_group_permed')
|
||||
perm_group_update(user_group_name=user_group_name, asset_groups_id=asset_groups_selected)
|
||||
return HttpResponseRedirect('/jperm/perm_list/', locals())
|
||||
return render_to_response('jperm/perm_edit.html', locals())
|
||||
return HttpResponseRedirect('/jperm/perm_list/', locals(), context_instance=RequestContext(request))
|
||||
return render_to_response('jperm/perm_edit.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def perm_detail(request):
|
||||
|
@ -172,7 +173,7 @@ def perm_detail(request):
|
|||
for asset_group in asset_groups:
|
||||
assets_list.extend(asset_group.asset_set.all())
|
||||
|
||||
return render_to_response('jperm/perm_detail.html', locals())
|
||||
return render_to_response('jperm/perm_detail.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def perm_del(request):
|
||||
|
@ -191,7 +192,7 @@ def perm_asset_detail(request):
|
|||
if user:
|
||||
user = user[0]
|
||||
assets_list = perm_user_asset(user_id)
|
||||
return render_to_response('jperm/perm_asset_detail.html', locals())
|
||||
return render_to_response('jperm/perm_asset_detail.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def sudo_db_add(name, user_runas, user_groups_select, asset_groups_select, cmd_groups_select, comment):
|
||||
|
@ -286,7 +287,7 @@ def sudo_add(request):
|
|||
|
||||
msg = '添加成功'
|
||||
return HttpResponseRedirect('/jperm/sudo_list/')
|
||||
return render_to_response('jperm/sudo_add.html', locals())
|
||||
return render_to_response('jperm/sudo_add.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def sudo_list(request):
|
||||
|
@ -306,7 +307,7 @@ def sudo_list(request):
|
|||
contacts1 = paginator1.page(page1)
|
||||
except (EmptyPage, InvalidPage):
|
||||
contacts1 = paginator1.page(paginator1.num_pages)
|
||||
return render_to_response('jperm/sudo_list.html', locals())
|
||||
return render_to_response('jperm/sudo_list.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def sudo_edit(request):
|
||||
|
@ -352,7 +353,7 @@ def sudo_edit(request):
|
|||
|
||||
return HttpResponseRedirect('/jperm/sudo_list/')
|
||||
|
||||
return render_to_response('jperm/sudo_edit.html', locals())
|
||||
return render_to_response('jperm/sudo_edit.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def sudo_detail(request):
|
||||
|
@ -376,7 +377,7 @@ def sudo_detail(request):
|
|||
for cmd_group in cmd_groups:
|
||||
cmds_list.append({cmd_group.name: cmd_group.cmd.split(',')})
|
||||
|
||||
return render_to_response('jperm/sudo_detail.html', locals())
|
||||
return render_to_response('jperm/sudo_detail.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def sudo_del(request):
|
||||
|
@ -403,7 +404,7 @@ def cmd_add(request):
|
|||
|
||||
return HttpResponseRedirect('/jperm/cmd_list/')
|
||||
|
||||
return render_to_response('jperm/sudo_cmd_add.html', locals())
|
||||
return render_to_response('jperm/sudo_cmd_add.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def cmd_edit(request):
|
||||
|
@ -429,7 +430,7 @@ def cmd_edit(request):
|
|||
if cmd_group:
|
||||
cmd_group.update(name=name, cmd=cmd, comment=comment)
|
||||
return HttpResponseRedirect('/jperm/cmd_list/')
|
||||
return render_to_response('jperm/sudo_cmd_add.html', locals())
|
||||
return render_to_response('jperm/sudo_cmd_add.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def cmd_list(request):
|
||||
|
@ -447,7 +448,7 @@ def cmd_list(request):
|
|||
contacts = paginator.page(page)
|
||||
except (EmptyPage, InvalidPage):
|
||||
contacts = paginator.page(paginator.num_pages)
|
||||
return render_to_response('jperm/sudo_cmd_list.html', locals())
|
||||
return render_to_response('jperm/sudo_cmd_list.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def cmd_del(request):
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
def name_proc(request):
|
||||
user_id = request.session.get('user_id')
|
||||
role = request.session.get('role')
|
||||
return {'user_id': user_id, 'role': role}
|
|
@ -90,6 +90,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (
|
|||
'django.core.context_processors.static',
|
||||
'django.core.context_processors.tz',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
'jumpserver.context_processors.name_proc'
|
||||
)
|
||||
|
||||
TEMPLATE_DIRS = (
|
||||
|
|
|
@ -97,3 +97,18 @@ def filter_private(group):
|
|||
p = BisGroup.objects.get(name='ALL')
|
||||
[agroup.append(g) for g in group if g != p]
|
||||
return agroup
|
||||
|
||||
|
||||
@register.filter(name='to_name')
|
||||
def to_name(user_id):
|
||||
user = User.objects.filter(id=user_id)
|
||||
if user:
|
||||
user = user[0]
|
||||
return user.name
|
||||
else:
|
||||
return '非法用户'
|
||||
|
||||
@register.filter(name='to_role_name')
|
||||
def to_role_name(role_id):
|
||||
role_dict = {'0': '普通用户', '1': '组管理员', '2': '超级管理员'}
|
||||
return role_dict.get(role_id, '未知')
|
|
@ -11,6 +11,7 @@ import os
|
|||
from django.http import HttpResponse
|
||||
from django.shortcuts import render_to_response
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.template import RequestContext
|
||||
|
||||
from juser.models import User
|
||||
from jasset.models import Asset, BisGroup, IDC
|
||||
|
@ -32,7 +33,7 @@ def md5_crypt(string):
|
|||
|
||||
|
||||
def base(request):
|
||||
return render_to_response('base.html')
|
||||
return render_to_response('base.html', context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def skin_config(request):
|
||||
|
@ -50,6 +51,7 @@ def jasset_group_add(name, comment, type):
|
|||
class ServerError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment):
|
||||
groups = []
|
||||
is_active = {u'是': '1', u'否': '2'}
|
||||
|
@ -99,7 +101,7 @@ def login(request):
|
|||
if user:
|
||||
user = user[0]
|
||||
if md5_crypt(password) == user.password:
|
||||
request.session['username'] = username
|
||||
request.session['user_id'] = user.id
|
||||
if user.role == 'SU':
|
||||
request.session['role'] = 2
|
||||
elif user.role == 'GA':
|
||||
|
|
|
@ -13,6 +13,7 @@ from django.http import HttpResponseRedirect
|
|||
from django.shortcuts import render_to_response
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.db.models import Q
|
||||
from django.template import RequestContext
|
||||
from django.http import HttpResponse
|
||||
from django.core.paginator import Paginator, EmptyPage, InvalidPage
|
||||
|
||||
|
@ -212,7 +213,7 @@ def ldap_del_user(username):
|
|||
def group_add(request, group_type_select='A'):
|
||||
error = ''
|
||||
msg = ''
|
||||
header_title, path1, path2 = '添加属组 | Add Group', 'juser', 'group_add'
|
||||
header_title, path1, path2 = '添加属组 | Group Add', '用户管理', '添加用户组'
|
||||
group_types = {
|
||||
'M': '部门',
|
||||
'A': '用户组',
|
||||
|
@ -245,7 +246,7 @@ def group_add(request, group_type_select='A'):
|
|||
else:
|
||||
msg = u'添加组 %s 成功' % group_name
|
||||
|
||||
return render_to_response('juser/group_add.html', locals())
|
||||
return render_to_response('juser/group_add.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def group_add_ajax(request):
|
||||
|
@ -256,11 +257,11 @@ def group_add_ajax(request):
|
|||
else:
|
||||
users = [user for user in users_all if not user.user_group.filter(type='M')]
|
||||
|
||||
return render_to_response('juser/group_add_ajax.html', locals())
|
||||
return render_to_response('juser/group_add_ajax.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def group_list(request):
|
||||
header_title, path1, path2 = '查看属组 | Show Group', 'juser', 'group_list'
|
||||
header_title, path1, path2 = '查看属组 | Show Group', '用户管理', '查看用户组'
|
||||
groups = contact_list = UserGroup.objects.filter(Q(type='M') | Q(type='A')).order_by('type')
|
||||
p = paginator = Paginator(contact_list, 10)
|
||||
|
||||
|
@ -273,7 +274,7 @@ def group_list(request):
|
|||
contacts = paginator.page(page)
|
||||
except (EmptyPage, InvalidPage):
|
||||
contacts = paginator.page(paginator.num_pages)
|
||||
return render_to_response('juser/group_list.html', locals())
|
||||
return render_to_response('juser/group_list.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def group_detail(request):
|
||||
|
@ -282,7 +283,7 @@ def group_detail(request):
|
|||
return HttpResponseRedirect('/')
|
||||
group = UserGroup.objects.get(id=group_id)
|
||||
users = group.user_set.all()
|
||||
return render_to_response('juser/group_detail.html', locals())
|
||||
return render_to_response('juser/group_detail.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def group_del(request):
|
||||
|
@ -291,7 +292,7 @@ def group_del(request):
|
|||
return HttpResponseRedirect('/')
|
||||
group = UserGroup.objects.get(id=group_id)
|
||||
group.delete()
|
||||
return HttpResponseRedirect('/juser/group_list/', locals())
|
||||
return HttpResponseRedirect('/juser/group_list/', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def group_edit(request):
|
||||
|
@ -312,7 +313,7 @@ def group_edit(request):
|
|||
users_selected = group.user_set.all()
|
||||
users = [user for user in users_all if user not in users_selected]
|
||||
|
||||
return render_to_response('juser/group_edit.html', locals())
|
||||
return render_to_response('juser/group_edit.html', locals(), context_instance=RequestContext(request))
|
||||
else:
|
||||
group_id = request.POST.get('group_id', None)
|
||||
group_name = request.POST.get('group_name', None)
|
||||
|
@ -341,7 +342,7 @@ def user_list(request):
|
|||
contacts = paginator.page(page)
|
||||
except (EmptyPage, InvalidPage):
|
||||
contacts = paginator.page(paginator.num_pages)
|
||||
return render_to_response('juser/user_list.html', locals())
|
||||
return render_to_response('juser/user_list.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def user_detail(request):
|
||||
|
@ -349,7 +350,7 @@ def user_detail(request):
|
|||
if not user_id:
|
||||
return HttpResponseRedirect('/')
|
||||
user = User.objects.get(id=user_id)
|
||||
return render_to_response('juser/user_detail.html', locals())
|
||||
return render_to_response('juser/user_detail.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def user_del(request):
|
||||
|
@ -362,7 +363,7 @@ def user_del(request):
|
|||
group.delete()
|
||||
server_del_user(user.username)
|
||||
ldap_del_user(user.username)
|
||||
return HttpResponseRedirect('/juser/user_list/', locals())
|
||||
return HttpResponseRedirect('/juser/user_list/', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def user_edit(request):
|
||||
|
@ -430,13 +431,13 @@ def user_edit(request):
|
|||
|
||||
return HttpResponseRedirect('/juser/user_list/')
|
||||
|
||||
return render_to_response('juser/user_add.html', locals())
|
||||
return render_to_response('juser/user_add.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def user_add(request):
|
||||
error = ''
|
||||
msg = ''
|
||||
header_title, path1, path2 = '添加用户 | Add User', 'juser', 'user_add'
|
||||
header_title, path1, path2 = '添加用户 | User Add', '用户管理', '添加用户'
|
||||
user_role = {'SU': u'超级管理员', 'GA': u'组管理员', 'CU': u'普通用户'}
|
||||
manage_groups = UserGroup.objects.filter(type='M')
|
||||
auth_groups = UserGroup.objects.filter(type='A')
|
||||
|
@ -497,7 +498,7 @@ def user_add(request):
|
|||
except Exception:
|
||||
pass
|
||||
|
||||
return render_to_response('juser/user_add.html', locals())
|
||||
return render_to_response('juser/user_add.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
{% load mytags %}
|
||||
<li class="nav-header">
|
||||
<div class="dropdown profile-element"> <span>
|
||||
<img alt="image" class="img-circle" src="/static/img/profile_small.jpg" />
|
||||
</span>
|
||||
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
|
||||
<span class="clear"> <span class="block m-t-xs"> <strong class="font-bold">David Williams</strong>
|
||||
</span> <span class="text-muted text-xs block">Art Director <b class="caret"></b></span> </span> </a>
|
||||
<span class="clear"> <span class="block m-t-xs"> <strong class="font-bold">{{ user_id }}</strong>
|
||||
</span> <span class="text-muted text-xs block">{{ role }} <b class="caret"></b></span> </span> </a>
|
||||
<ul class="dropdown-menu animated fadeInRight m-t-xs">
|
||||
<li><a href="profile.html">Profile</a></li>
|
||||
<li><a href="contacts.html">Contacts</a></li>
|
||||
|
|
Loading…
Reference in New Issue