mirror of https://github.com/jumpserver/jumpserver
权限申请
parent
e1b9134d7f
commit
b35f1e6174
|
@ -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)
|
||||
|
|
|
@ -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'),
|
||||
)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
|
@ -45,6 +45,14 @@
|
|||
<div class="col-sm-8"><input type="text" name="dept" value="{{ deptname }}" class="form-control" readonly="readonly"></div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> 部门管理员 </label>
|
||||
<div class="radio">
|
||||
{% for da in dept_da %}
|
||||
<label><input type="radio" value="{{ da.id }}" id="da" name="da"> {{ da }}</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
{% extends 'base.html' %}
|
||||
{% block content %}
|
||||
{% include 'nav_cat_bar.html' %}
|
||||
<!--<h3 class="text-center">项目发布申请</h3>-->
|
||||
<div class="wrapper wrapper-content animated fadeInRight">
|
||||
<div class="row">
|
||||
<div class="col-lg-10">
|
||||
<div id="add_asset" class="ibox float-e-margins">
|
||||
<div id="ibox-content" class="ibox-title">
|
||||
<h5> 填写要申请主机的基本信息 </h5>
|
||||
<div class="ibox-tools">
|
||||
<a class="collapse-link">
|
||||
<i class="fa fa-chevron-up"></i>
|
||||
</a>
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
|
||||
<i class="fa fa-wrench"></i>
|
||||
</a>
|
||||
<ul class="dropdown-menu dropdown-user">
|
||||
<li><a href="#">未启用 1</a>
|
||||
</li>
|
||||
<li><a href="#">未启用 2</a>
|
||||
</li>
|
||||
</ul>
|
||||
<a class="close-link">
|
||||
<i class="fa fa-times"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ibox-content">
|
||||
<h3>授权完成, 已邮件通知申请人, 五秒钟后关闭页面</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
</script>
|
||||
{% endblock content %}
|
Loading…
Reference in New Issue