Exemplo n.º 1
0
def responser_change(request):
    """
    模板编辑中批量修改责任人
    """
    form = ResponserChangeForm(request.POST)
    if not form.is_valid():
        return render_json({'result': False, "msg": u'参数错误!'})
    responser = form.cleaned_data['responser']
    business_name = form.cleaned_data['business_name']
    template_name = form.cleaned_data['template_name']
    if not check_users_from_paas(responser, request.COOKIES['bk_token'])[0]:
        return render_json({'result': False, 'msg': u'参数不合法!'})
    responser = string_to_users(responser)
    try:
        details = BusinessTemplateStepDetail.objects.filter(
            business_step__business__business_name=business_name,
            business_step__business__template_name=template_name,
        )
        for detail in details:
            detail.responser.clear()
            for i in responser:
                detail.responser.add(i)
            detail.save()
    except Exception, e:
        logger.error(
            u'修改责任人失败,ERROR %s, business_name: %s, template_name: %s' %
            (e, business_name, template_name))
        return render_json({'result': False, "msg": u'批量修改责任人失败,请联系管理员!'})
Exemplo n.º 2
0
def application_create(request):
    """
    增加业务
    """
    form = ApplicationInfoForm(request.POST)
    if not form.is_valid():
        return render_json({'result': False, 'msg': u'参数不合法!'})
    cc_id = form.cleaned_data['cc_id']
    cc_name = form.cleaned_data['cc_name']
    cc_name_abbr = form.cleaned_data['cc_name_abbr']
    operator = form.cleaned_data['operator']
    if not check_users_from_paas(operator, request.COOKIES['bk_token'])[0]:
        return render_json({'result': False, 'msg': u'参数不合法!'})
    n = Application.objects.filter(cc_id=cc_id).count()
    if n > 0:
        return render_json({'result': False, 'msg': u"该业务编码已存在,请修改重试!"})
    n = Application.objects.filter(cc_name=cc_name).count()
    if n > 0:
        return render_json({'result': False, 'msg': u"该业务名称已存在,请修改重试!"})
    try:
        app = Application.objects.create(cc_name=cc_name,
                                         cc_name_abbr=cc_name_abbr,
                                         cc_id=cc_id)
        operator = string_to_users(operator)
        for i in operator:
            app.operator.add(i)
        app.save()
    except Exception, e:
        logger.error(u"增加业务失败%s" % e)
        return render_json({'result': False, 'msg': u"添加业务失败!"})
Exemplo n.º 3
0
def application_change(request):
    """
    修改业务信息
    """
    forms = ApplicationInfoForm(request.POST)
    if not forms.is_valid():
        return render_json({'result': False, 'msg': u'参数不合法!'})
    pk = forms.cleaned_data['pk']
    if pk is None:
        return render_json({'result': False, 'msg': u'参数不合法!'})
    cc_name = forms.cleaned_data['cc_name']
    cc_name_abbr = forms.cleaned_data['cc_name_abbr']
    operator = forms.cleaned_data['operator']
    if not check_users_from_paas(operator, request.COOKIES['bk_token'])[0]:
        return render_json({'result': False, 'msg': u'参数不合法!'})
    n = Application.objects.filter(~Q(pk=pk), cc_name=cc_name).count()
    if n > 0:
        return render_json({'result': False, 'msg': u'业务名已存在,请修改重试!'})
    try:
        app = Application.objects.get(pk=pk)
        app.cc_name = cc_name
        app.cc_name_abbr = cc_name_abbr
        operators = string_to_users(operator)
        app.operator.clear()
        for operator in operators:
            app.operator.add(operator)
        app.save()
    except ObjectDoesNotExist:
        return render_json({'result': False, 'msg': u'修改业务失败!'})
    return render_json({'result': True, 'msg': u'修改业务成功!'})
Exemplo n.º 4
0
def step_change(request):
    """
    编辑指定步骤类别的步骤序号的数据
    """
    form = StepForm(request.POST)
    if not form.is_valid():
        return render_json({'result': False, 'msg': u"参数不合法"})
    b_name = form.cleaned_data['business_name']
    t_name = form.cleaned_data['template_name']
    step_xh = form.cleaned_data['step_xh']
    operate_attention = form.cleaned_data['operate_attention']
    comment = form.cleaned_data['comment']
    responser = form.cleaned_data['responser']
    instance_flag = form.cleaned_data['instance_flag']
    if not check_users_from_paas(responser, request.COOKIES['bk_token'])[0]:
        return render_json({'result': False, 'msg': u'参数不合法!'})
    if instance_flag:
        status = update_task_step("instance", b_name, t_name, step_xh,
                                  request.user.username, operate_attention,
                                  comment, responser)
    else:
        status = update_task_step("template", b_name, t_name, step_xh,
                                  request.user.username, operate_attention,
                                  comment, responser)
    if not status:
        return render_json({'result': False, 'msg': u"修改步骤 %s失败" % step_xh})
    else:
        return render_json({'result': True, 'msg': u"修改步骤%s成功" % step_xh})
Exemplo n.º 5
0
def step_create(request):
    """
    @运维配置——编辑业务模板,新增指定位置步骤
    """
    form = StepForm(request.POST)
    if not form.is_valid():
        return render_json({'result': False, 'msg': u"参数错误"})
    b_name = form.cleaned_data['business_name']
    t_name = form.cleaned_data['template_name']
    step_xh = form.cleaned_data['step_xh']
    operate_attention = form.cleaned_data['operate_attention']
    comment = form.cleaned_data['comment']
    responser = form.cleaned_data['responser']
    instance_flag = form.cleaned_data['instance_flag']
    if not check_users_from_paas(responser, request.COOKIES['bk_token'])[0]:
        return render_json({'result': False, 'msg': u'参数不合法!'})
    if instance_flag:
        business = BUSINESS_MODEL['instance']
    else:
        business = BUSINESS_MODEL['template']
    try:
        business.objects.get(business_name=b_name, template_name=t_name)
    except ObjectDoesNotExist:
        logger.error(
            u'查询任务实例步骤失败,business_name: %s, template_name: %s, step_xh:%s' %
            (b_name, t_name, step_xh))
        return render_json({'result': False, 'msg': u"任务实例不存在"})

    if instance_flag:
        status = create_task_step("instance", b_name, t_name, step_xh,
                                  request.user.username, operate_attention,
                                  comment, responser)
    else:
        status = create_task_step("template", b_name, t_name, step_xh,
                                  request.user.username, operate_attention,
                                  comment, responser)
    if not status:
        return render_json({'result': False, 'msg': u"添加步骤 %s数据时失败" % step_xh})
    else:
        return render_json({'result': True, 'msg': u"添加步骤%s成功" % step_xh})
Exemplo n.º 6
0
def operator_change(request):
    """
    更新模板可操作者
    """
    form = OperatorChangeForm(request.POST)
    if not form.is_valid():
        return render_json({'status': False, 'msg': u"数据不合法!"})
    operator = form.cleaned_data['operator']
    if not check_users_from_paas(operator, request.COOKIES['bk_token'])[0]:
        return render_json({'status': False, 'msg': u'部分可操作者不存在!'})

    template_name = form.cleaned_data['template_name']
    business_name = form.cleaned_data['business_name']

    username = request.user.username
    try:
        template = BusinessTemplate.objects.get(business_name=business_name,
                                                template_name=template_name,
                                                operator__username=username)
    except ObjectDoesNotExist:
        return render_json({'status': False, 'msg': u"权限不足!"})
    try:
        cc_name = template.business_name
        operator_list = string_to_users(operator)
        if operator_list.count() != Application.objects.get(
                cc_name=cc_name).operator.filter(
                    username__in=operator.split(';')).count():
            return render_json({'status': False, 'msg': u"部分可操作者无该app权限!"})
        template.updater = request.user
        template.update_time = datetime.datetime.now()
        template.operator.clear()
        for i in operator_list:
            template.operator.add(i)
        template.save()
    except Exception, e:
        logger.error(u'更新纪录失败,%s; updater: %s, operator: %s pk:%s' %
                     (e, username, operator, template.pk))
        return render_json({'status': False, 'msg': u"更新纪录失败!"})