Exemplo n.º 1
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)
Exemplo 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,
                                            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)