Ejemplo n.º 1
0
def get_roles_and_personnel(request, biz_cc_id):
    """
    @summary: 获取用户角色和业务人员
    @param request:
    @param biz_cc_id:
    @return:
    """
    use_for = request.GET.get('use_for', '')
    # 模板授权需要去掉运维角色,运维默认有所有权限,并添加职能化人员
    if use_for == 'template_auth':
        role_list = [
            role for role in roles.CC_ROLES if role != roles.MAINTAINERS
        ]
        # 添加职能化人员
        role_list.append(roles.FUNCTOR)
    else:
        role_list = roles.CC_ROLES

    data = []
    for key in role_list:
        name = roles.ROLES_DECS[key]
        group_name = convert_group_name(biz_cc_id, key)
        group = Group.objects.get(name=group_name)
        user_list = group.user_set.all()
        personnel_list = []
        for user in user_list:
            personnel_list.append({
                "text": user.full_name,
                "id": user.username,
            })
        personnel_list.insert(0, {"text": _(u"所有%s") % name, "id": key})
        data.append({"text": name, "children": personnel_list})
    return JsonResponse({"result": True, "data": {'roles': data}})
Ejemplo n.º 2
0
def save_perms(request, biz_cc_id):
    template_id = request.POST.get('template_id')
    try:
        template = TaskTemplate.objects.get(pk=template_id,
                                            business__cc_id=biz_cc_id)
    except TaskTemplate.DoesNotExist:
        return HttpResponseForbidden()
    user_model = get_user_model()
    for perm in [
            CREATE_TASK_PERM_NAME, FILL_PARAMS_PERM_NAME,
            EXECUTE_TASK_PERM_NAME
    ]:
        group_name_list = []
        user_name_list = []
        for data in json.loads(request.POST.get(perm, '[]')):
            if data in ALL_ROLES:
                group_name = convert_group_name(biz_cc_id, data)
                group_name_list.append(group_name)
            else:
                user_name_list.append(data)
        group_set = Group.objects.filter(name__in=group_name_list)
        assign_tmpl_perms(request, [perm], group_set, template)
        user_set = user_model.objects.filter(username__in=user_name_list)
        assign_tmpl_perms_user(request, [perm], user_set, template)
    ctx = {
        'result': True,
        'data': '',
    }
    return JsonResponse(ctx)
Ejemplo n.º 3
0
def save_perms(request):
    """
    @summary: 暴露给业务的接口,业务管理员保存自己业务下的权限
    @param request:
    @return:
    """
    template_id = request.POST.get('template_id')
    biz_cc_id = str(request.POST.get('biz_cc_id'))

    try:
        CommonTemplate.objects.get(pk=template_id, is_deleted=False)
    except CommonTemplate.DoesNotExist:
        return HttpResponseForbidden()
    template_perm, _ = CommonTmplPerm.objects.get_or_create(
        common_template_id=template_id, biz_cc_id=biz_cc_id)
    user_model = get_user_model()
    for perm in PermNm.PERM_LIST:
        group_name_list = []
        user_name_list = []
        for data in json.loads(request.POST.get(perm, '[]')):
            if data in ALL_ROLES:
                group_name = convert_group_name(biz_cc_id, data)
                group_name_list.append(group_name)
            else:
                user_name_list.append(data)
        group_set = Group.objects.filter(name__in=group_name_list)
        assign_tmpl_perms(['common_%s' % perm], group_set, template_perm)
        user_set = user_model.objects.filter(username__in=user_name_list)
        assign_tmpl_perms_user(['common_%s' % perm], user_set, template_perm)
    ctx = {'result': True, 'data': {}, 'message': 'success'}
    return JsonResponse(ctx)
Ejemplo n.º 4
0
def get_biz_person_list(request, biz_cc_id):
    """
    @summary: 获取业务相关人员信息
    @param request:
    @param biz_cc_id:
    @return:
    """
    original = request.GET.get('original', '')
    role_list = CC_ROLES
    # 模板授权需要去掉运维角色,运维默认有所有权限
    if original == 'tasktmpl_list':
        role_list = [role for role in role_list if
                     role != MAINTAINERS]

        # 并添加职能化人员
        role_list.append(FUNCTOR)

    try:
        prepare_business(request, cc_id=biz_cc_id)
    except Exception as e:
        logger.error('get_biz_person_list error, biz_cc_id=%s, error=%s' % (biz_cc_id, e))

    person_list = []
    for key in role_list:
        name = ROLES_DECS[key]
        group_name = convert_group_name(biz_cc_id, key)
        group = Group.objects.get(name=group_name)
        user_list = group.user_set.all()
        data_list = []
        for user in user_list:
            openid = user.username
            data_list.append({
                "text": user.full_name,
                "id": openid,
            })
        # if data_list:
        data_list.insert(0, {
            "text": _(u"所有%s") % name,
            "id": key
        })
        person_list.append({
            "text": name,
            "children": data_list
        })
    return JsonResponse({
        "result": True,
        "data": person_list
    })
Ejemplo n.º 5
0
def save_perms(request, biz_cc_id):
    template_id = request.POST.get('template_id')
    try:
        template = TaskTemplate.objects.get(pk=template_id,
                                            business__cc_id=biz_cc_id,
                                            is_deleted=False)
    except TaskTemplate.DoesNotExist:
        return HttpResponseForbidden()
    user_model = get_user_model()
    for perm in PermNm.PERM_LIST:
        group_name_list = []
        user_name_list = []
        for data in json.loads(request.POST.get(perm, '[]')):
            if data in ALL_ROLES:
                group_name = convert_group_name(biz_cc_id, data)
                group_name_list.append(group_name)
            else:
                user_name_list.append(data)
        group_set = Group.objects.filter(name__in=group_name_list)
        assign_tmpl_perms([perm], group_set, template)
        user_set = user_model.objects.filter(username__in=user_name_list)
        assign_tmpl_perms_user([perm], user_set, template)
    ctx = {'result': True, 'data': {}, 'message': 'success'}
    return JsonResponse(ctx)