From 6e976b05837d943a5d182464693accfeb242ab95 Mon Sep 17 00:00:00 2001 From: halcyon <864072399@qq.com> Date: Sat, 4 Apr 2015 12:47:07 +0800 Subject: [PATCH] 0406 --- jperm/urls.py | 2 + jperm/views.py | 99 +++++++++++++++++++++----- jumpserver/templatetags/mytags.py | 17 +++++ templates/jasset/host_list.html | 4 +- templates/jperm/perm_apply_exec.html | 37 ++++------ templates/jperm/perm_apply_info.html | 55 ++++++++++++++ templates/jperm/perm_apply_search.html | 42 +++++++++++ templates/jperm/perm_log_offline.html | 49 ++++++++++--- templates/jperm/perm_log_online.html | 47 +++++++++--- templates/nav.html | 2 + 10 files changed, 296 insertions(+), 58 deletions(-) create mode 100644 templates/jperm/perm_apply_info.html create mode 100644 templates/jperm/perm_apply_search.html diff --git a/jperm/urls.py b/jperm/urls.py index 77d0ce5ea..b78c7f2aa 100644 --- a/jperm/urls.py +++ b/jperm/urls.py @@ -27,4 +27,6 @@ urlpatterns = patterns('jperm.views', (r'^apply/$', 'perm_apply'), (r'^apply_show/(\w+)/$', 'perm_apply_log'), (r'^apply_exec/$', 'perm_apply_exec'), + (r'^apply_info/$', 'perm_apply_info'), + (r'^apply_search/$', 'perm_apply_search'), ) diff --git a/jperm/views.py b/jperm/views.py index 2a3c59279..5ac57701b 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -556,7 +556,6 @@ def perm_apply(request): da = User.objects.get(id=da) mail_address = da.email mail_title = '%s - 权限申请' % username - # print da.username, applyer, group, hosts, datetime.datetime.now(), comment, url group_lis = ', '.join(group) hosts_lis = ', '.join(hosts) time_now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') @@ -571,31 +570,42 @@ def perm_apply(request): 申请的主机: %s 申请时间: %s 申请说明: %s - 请及时审批, 审批完成后点击以下链接,告知各位。 + 请及时审批, 审批完成后点击以下链接,告知申请人。 + %s """ % (da.username, applyer, group_lis, hosts_lis, time_now, comment, url) - send_mail(mail_title, mail_msg, 'jkfunshion@fun.tv', [mail_address], fail_silently=False) + send_mail(mail_title, mail_msg, 'jumpserver@163.com', [mail_address], fail_silently=False) smg = "提交成功,已发邮件通知部门管理员。" return render_to_response('jperm/perm_apply.html', locals(), context_instance=RequestContext(request)) return render_to_response('jperm/perm_apply.html', locals(), context_instance=RequestContext(request)) +@require_admin def perm_apply_exec(request): + header_title, path1, path2 = u'主机权限申请', u'权限管理', u'审批完成' uuid = request.GET.get('uuid') - p_apply = Apply.objects.filter(uuid=str(uuid)) - q_apply = Apply.objects.get(uuid=str(uuid)) - if p_apply: - user = User.objects.get(username=q_apply.applyer) - mail_address = user.email - time_now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') - p_apply.update(status=1, date_end=time_now) - mail_title = '%s - 权限审批完成' % q_apply.applyer - mail_msg = """ - Hi,%s: - 您所申请的权限已由 %s 在 %s 审批完成, 请登录验证。 - """ % (q_apply.applyer, q_apply.approver, time_now) - send_mail(mail_title, mail_msg, 'jkfunshion@fun.tv', [mail_address], fail_silently=False) + if uuid: + p_apply = Apply.objects.filter(uuid=str(uuid)) + q_apply = Apply.objects.get(uuid=str(uuid)) + if q_apply.status == 1: + smg = '此权限已经审批完成, 请勿重复审批, 十秒钟后返回首页' + return render_to_response('jperm/perm_apply_exec.html', locals(), context_instance=RequestContext(request)) + else: + user = User.objects.get(username=q_apply.applyer) + mail_address = user.email + time_now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + p_apply.update(status=1, date_end=time_now) + mail_title = '%s - 权限审批完成' % q_apply.applyer + mail_msg = """ + Hi,%s: + 您所申请的权限已由 %s 在 %s 审批完成, 请登录验证。 + """ % (q_apply.applyer, q_apply.approver, time_now) + send_mail(mail_title, mail_msg, 'jkfunshion@fun.tv', [mail_address], fail_silently=False) + smg = '授权完成, 已邮件通知申请人, 十秒钟后返回首页' + return render_to_response('jperm/perm_apply_exec.html', locals(), context_instance=RequestContext(request)) + else: + smg = '没有此授权, 十秒钟后返回首页' return render_to_response('jperm/perm_apply_exec.html', locals(), context_instance=RequestContext(request)) @@ -623,6 +633,7 @@ def get_apply_posts(request, status, username, dept_name, keyword=None): return posts +@require_login def perm_apply_log(request, offset): header_title, path1, path2 = u'权限申请记录', u'权限管理', u'申请记录' keyword = request.GET.get('keyword') @@ -639,3 +650,59 @@ def perm_apply_log(request, offset): posts = get_apply_posts(request, 1, username, dept_name, keyword) contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) return render_to_response('jperm/perm_log_offline.html', locals(), context_instance=RequestContext(request)) + + +def perm_apply_info(request): + uuid = request.GET.get('uuid') + post = Apply.objects.get(uuid=uuid) + return render_to_response('jperm/perm_apply_info.html', locals(), context_instance=RequestContext(request)) + + +def perm_apply_search(request): + keyword = request.GET.get('keyword') + env = request.GET.get('env') + dept_id = get_user_dept(request) + dept_name = DEPT.objects.get(id=dept_id).name + user_id = request.session.get('user_id') + username = User.objects.get(id=user_id).username + if is_super_user(request): + if env == 'online': + posts = Apply.objects.filter(Q(applyer__contains=keyword) | Q(approver__contains=keyword)) \ + .filter(status=0).order_by('-date_add') + elif env == 'offline': + posts = Apply.objects.filter(Q(applyer__contains=keyword) | Q(approver__contains=keyword)) \ + .filter(status=1).order_by('-date_add') + contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) + + elif is_group_admin(request): + if env == 'online': + posts = Apply.objects.filter(Q(applyer__contains=keyword) | Q(approver__contains=keyword)) \ + .filter(status=0).filter(dept_name=dept_name).order_by('-date_add') + elif env == 'offline': + posts = Apply.objects.filter(Q(applyer__contains=keyword) | Q(approver__contains=keyword)) \ + .filter(status=1).filter(dept_name=dept_name).order_by('-date_add') + contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) + + elif is_common_user(request): + if env == 'online': + posts = Apply.objects.filter(Q(applyer__contains=keyword) | Q(approver__contains=keyword)) \ + .filter(status=0).filter(user=username).order_by('-date_add') + elif env == 'offline': + posts = Apply.objects.filter(Q(applyer__contains=keyword) | Q(approver__contains=keyword)) \ + .filter(status=1).filter(applyer=username).order_by('-date_add') + contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) + return render_to_response('jperm/perm_apply_search.html', locals(), context_instance=RequestContext(request)) + + + + + + + + + + + + + + diff --git a/jumpserver/templatetags/mytags.py b/jumpserver/templatetags/mytags.py index b414dfc3d..83740631f 100644 --- a/jumpserver/templatetags/mytags.py +++ b/jumpserver/templatetags/mytags.py @@ -56,6 +56,18 @@ def groups_str2(group_list): return '%s ...' % ' '.join([group.name for group in group_list[0:2]]) +@register.filter(name='group_str2_all') +def groups_str2(group_list): + group_lis = [] + for i in group_list: + if str(i) != 'ALL': + group_lis.append(i) + if len(group_lis) < 3: + return ' '.join([group.name for group in group_lis]) + else: + return '%s ...' % ' '.join([group.name for group in group_lis[0:2]]) + + @register.filter(name='group_manage_str') def group_manage_str(username): user = User.objects.get(username=username) @@ -163,6 +175,11 @@ def group_type_to_str(type_name): @register.filter(name='ast_to_list') def ast_to_list(lis): + return ast.literal_eval(lis)[0:2] + + +@register.filter(name='ast_to_list_1') +def ast_to_list_1(lis): return ast.literal_eval(lis) diff --git a/templates/jasset/host_list.html b/templates/jasset/host_list.html index c57546abf..e443bb396 100644 --- a/templates/jasset/host_list.html +++ b/templates/jasset/host_list.html @@ -56,7 +56,6 @@
申请人 | +所属部门 | +申请主机组 | +申请主机 | +批准人 | +申请时间 | + +备注 | +详情 | + +
---|---|---|---|---|---|---|---|
{{ post.applyer }} | +{{ post.dept }} | +{% for i in post.bisgroup|ast_to_list %} {{ i }} {% endfor %}... | +{% for i in post.asset|ast_to_list %} {{ i }} {% endfor %}... | +{{ post.approver }} | +{{ post.date_add|date:"Y-m-d H:i:s"}} | + +{{ post.comment }} | ++ 详情 + | +