Exemple #1
0
def create_perm_strategy(request):
    """父账号创建权限策略"""
    msg = ''
    status = False

    res = {
        'status': status,
        'msg': msg
    }

    name = request.POST.get('name', '')
    remark = request.POST.get('remark', '')

    creator_username = request.user.username

    perm_list = request.POST.getlist('perm[]', '')

    try:
        if not name:
            msg = af.PERM_STRATEGY_NAME_EMPTY
            assert False

        if not perm_list:
            msg = af.PERM_LIST_EMPTY
            assert False

        parameter = {
            'name': name,
            'remark': remark,
            'creator_username': creator_username,
            'strategy_type': PermStrategy.PARENT_NUM
        }

        perm_strategy = PermStrategy(**parameter)
        perm_strategy.save()

        perm_list = Perm.objects.filter(code__in=perm_list)
        for perm in perm_list:
            perm_strategy.perm.add(perm)

    except AssertionError:
        res['msg'] = _(msg)
        return json_response(res)

    log_msg = om.CREATE_PERM_STRATEGY % (
        creator_username, name, perm_strategy.id)
    OperateLog.write_operate_log(request, om.ACCOUNTS, log_msg)

    status = True

    res['status'] = status

    return json_response(res)
Exemple #2
0
def parent_child_details_views(request, user_id):
    """父账号获取子账号详情"""
    child = UserProfile.objects.filter(id=user_id).first()

    _, perm_strategy_dict_list = get_user_perm_strategy_list(request)

    user_perm_strategy = UserPermStrategy.objects.filter(user=child).first()

    user_perm_strategy_dict_list = []

    if user_perm_strategy:
        for i in user_perm_strategy.perm_strategy.all():
            perm_strategy_dict = {
                'id': i.id,
                'name': i.name,
                'remark': i.remark,
                'strategy_type_name': i.strategy_type_name
            }
            user_perm_strategy_dict_list.append(perm_strategy_dict)

    res = {
        'user': child,
        'perm_strategy_list': perm_strategy_dict_list,
        'user_perm_strategy_list': user_perm_strategy_dict_list,
        'strategy_type_dict': PermStrategy.strategy_type_dict()
    }
    return render(request, 'user/user_management_details.html', res)
Exemple #3
0
def parent_get_perm_strategy_views(request):
    """父账号策略管理页面"""

    _, perm_strategy_dict_list = get_user_perm_strategy_list(request)

    res = {
        'perm_strategy_list': perm_strategy_dict_list,
        'strategy_type_dict': PermStrategy.strategy_type_dict()
    }
    return render(request, 'user/parent_get_perm_strategy_views.html', res)
Exemple #4
0
def parent_child_list_views(request):
    """父账号管理子账号页面"""

    _, perm_strategy_dict_list = get_user_perm_strategy_list(request)

    res = {
        'perm_strategy_list': perm_strategy_dict_list,
        'strategy_type_dict': PermStrategy.strategy_type_dict()
    }
    return render(request, 'user/user_management_list.html', res)
Exemple #5
0
def parent_create_perm_strategy_views(request):
    """父账号策略创建页面"""

    _, perm_strategy_dict_list = get_user_perm_strategy_list(request)

    perm_user = PermUser.objects.filter(user=request.user).first()
    user_perm = {}
    user_perm_type = []
    if perm_user and perm_user.perm.all():
        user_perm, user_perm_type = handle_perm(perm_user.perm.all())

    res = {
        'user_perm': user_perm,
        'user_perm_type': user_perm_type,
        'perm_strategy_list': perm_strategy_dict_list,
        'strategy_type_dict': PermStrategy.strategy_type_dict()
    }

    return render(request, 'user/parent_create_perm_strategy_views.html', res)
Exemple #6
0
def parent_perm_strategy_details_views(request, perm_strategy_id):
    """父账号策略详情"""

    perm_strategy = PermStrategy.objects.filter(id=perm_strategy_id).first()
    parent_perm = {}
    parent_perm_type = []
    if perm_strategy:
        parent_perm, parent_perm_type = handle_perm(perm_strategy.perm.all())

    all_perm = Perm.objects.filter(content_type__contains='CLIENT')
    all_perm, all_perm_type = handle_perm(all_perm)
    res = {
        'all_perm': all_perm,
        'all_perm_type': all_perm_type,
        'perm_strategy': perm_strategy,

        'parent_perm': parent_perm,
        'parent_perm_type': parent_perm_type,
        'strategy_type_dict': PermStrategy.strategy_type_dict()
    }
    return render(request, 'user/strategy_management_details.html', res)