From b35f1e61740b02a6aa1131ba61e7a514f41cbf59 Mon Sep 17 00:00:00 2001 From: halcyon <864072399@qq.com> Date: Thu, 2 Apr 2015 18:32:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=83=E9=99=90=E7=94=B3=E8=AF=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jperm/models.py | 3 ++ jperm/urls.py | 1 + jperm/views.py | 45 ++++++++++++++++++++++------ jumpserver/settings.py | 13 ++++---- templates/jperm/perm_apply.html | 8 +++++ templates/jperm/perm_apply_exec.html | 40 +++++++++++++++++++++++++ 6 files changed, 95 insertions(+), 15 deletions(-) create mode 100644 templates/jperm/perm_apply_exec.html diff --git a/jperm/models.py b/jperm/models.py index a865d005a..4c21013fd 100644 --- a/jperm/models.py +++ b/jperm/models.py @@ -1,5 +1,7 @@ import datetime +from uuidfield import UUIDField + from django.db import models from juser.models import UserGroup, DEPT from jasset.models import Asset, BisGroup @@ -36,6 +38,7 @@ class SudoPerm(models.Model): class Apply(models.Model): + uuid = UUIDField(auto=True) applyer = models.CharField(max_length=20) approver = models.CharField(max_length=20) dept = models.CharField(max_length=20) diff --git a/jperm/urls.py b/jperm/urls.py index c15807260..77d0ce5ea 100644 --- a/jperm/urls.py +++ b/jperm/urls.py @@ -26,4 +26,5 @@ urlpatterns = patterns('jperm.views', (r'^cmd_edit/$', 'cmd_edit'), (r'^apply/$', 'perm_apply'), (r'^apply_show/(\w+)/$', 'perm_apply_log'), + (r'^apply_exec/$', 'perm_apply_exec'), ) diff --git a/jperm/views.py b/jperm/views.py index e91c8b670..2a3c59279 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -1,6 +1,8 @@ # coding: utf-8 -import ast +import sys +reload(sys) +sys.setdefaultencoding('utf8') import datetime @@ -542,17 +544,25 @@ def perm_apply(request): dept = DEPT.objects.get(id=dept_id) posts = Asset.objects.filter(dept=dept) egroup = dept.bisgroup_set.all() - mail_address = 'wangyong@fun.tv' + dept_da = User.objects.filter(dept_id=dept_id, role='DA') if request.method == 'POST': applyer = request.POST.get('applyer') dept = request.POST.get('dept') + da = request.POST.get('da') group = request.POST.getlist('group') hosts = request.POST.getlist('hosts') comment = request.POST.get('comment') - print applyer, dept, group, hosts, comment - url = 'http://127.0.0.1:8000/jperm/apply/exec/?id=' - mail_title = '权限申请' + 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') + Apply.objects.create(applyer=applyer, dept=dept, bisgroup=group, asset=hosts, status=0, comment=comment) + uuid = Apply.objects.get(applyer=applyer, asset=hosts, comment=comment).uuid + url = "http://127.0.0.1:8000/jperm/apply_exec/?uuid=%s" % uuid mail_msg = """ Hi,%s: 有新的权限申请, 详情如下: @@ -563,15 +573,32 @@ def perm_apply(request): 申请说明: %s 请及时审批, 审批完成后点击以下链接,告知各位。 %s - """ % (u'123', applyer, group, hosts, datetime.datetime.now(), comment, url) - send_mail(mail_title, mail_msg, 'jkfunshion@fun.tv', [mail_address], fail_silently=False) - smg = "提交成功,已转交运维上线。" + """ % (da.username, applyer, group_lis, hosts_lis, time_now, comment, url) - Apply.objects.create(applyer=applyer, dept=dept, bisgroup=group, asset=hosts, status=0, comment=comment) + send_mail(mail_title, mail_msg, 'jkfunshion@fun.tv', [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)) +def perm_apply_exec(request): + 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) + return render_to_response('jperm/perm_apply_exec.html', locals(), context_instance=RequestContext(request)) + + def get_apply_posts(request, status, username, dept_name, keyword=None): if is_super_user(request): if keyword: diff --git a/jumpserver/settings.py b/jumpserver/settings.py index db905dfde..50b6ae0db 100644 --- a/jumpserver/settings.py +++ b/jumpserver/settings.py @@ -23,6 +23,13 @@ DB_USER = config.get('db', 'user') DB_PASSWORD = config.get('db', 'password') DB_DATABASE = config.get('db', 'database') +# mail config +EMAIL_HOST = 'mail.funshion.com' +EMAIL_PORT = '25' +EMAIL_HOST_USER = 'jkfunshion' +EMAIL_HOST_PASSWORD = 'jkmail%' +EMAIL_USE_TLS = False + # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ @@ -121,10 +128,4 @@ USE_TZ = False STATIC_URL = '/static/' -# mail config -EMAIL_HOST = config.get('mail', 'email_host') -EMAIL_PORT = config.get('mail', 'email_port') -EMAIL_HOST_USER = config.get('mail', 'email_host_user') -EMAIL_HOST_PASSWORD = config.get('mail', 'email_host_password') -EMAIL_USE_TLS = config.get('mail', 'email_use_tls') diff --git a/templates/jperm/perm_apply.html b/templates/jperm/perm_apply.html index 181e176cf..52a01fb6c 100644 --- a/templates/jperm/perm_apply.html +++ b/templates/jperm/perm_apply.html @@ -45,6 +45,14 @@
+ +