Пример #1
0
def template_roles_remove_view(request, template_id):
    try:
        if request.method == 'POST':
            data = request.POST.dict()
            target = data.get('target')
            role_id = data.get('role_id')

            if target == 'user':
                status, msg = UserAndTeamRoleAPI.delete_role_from_user(
                    request.user, int(data.get('user_id')), int(role_id))

                if not status:
                    return HttpResponse(msg)

                return HttpResponseRedirect(
                    reverse('project:template_roles',
                            kwargs={'template_id': template_id}))
            elif target == 'team':
                status, msg = UserAndTeamRoleAPI.delete_role_from_team(
                    request.user, int(data.get('team_id')), int(role_id))

                if not status:
                    return HttpResponse(msg)

                return HttpResponseRedirect(
                    reverse('project:template_roles',
                            kwargs={'template_id': template_id}))
            else:
                return HttpResponse('404')
    except Exception as e:
        return HttpResponse(str(e))
Пример #2
0
def project_roles_remove_view(request, project_id):
    try:
        if request.is_ajax():
            if request.method == 'POST':
                ajax_data = request.POST.get('data')
                data = json.loads(ajax_data)
                target = data.get('target')
                role_id = int(data.get('role_id'))
                if target == 'user':
                    status, errmsg = UserAndTeamRoleAPI.delete_role_from_user(
                        user=request.user,
                        target_user_id=int(data.get('user_id')),
                        role_id=role_id)

                    if not status:
                        return JsonResponse({
                            ARK_STATUS: False,
                            ARK_ERRMSG: errmsg
                        })

                    return JsonResponse({ARK_STATUS: True})
                elif target == 'team':
                    status, errmsg = UserAndTeamRoleAPI.delete_role_from_team(
                        user=request.user,
                        target_team_id=int(data.get('team_id')),
                        role_id=role_id)

                    if not status:
                        return JsonResponse({
                            ARK_STATUS: False,
                            ARK_ERRMSG: errmsg
                        })

                    return JsonResponse({ARK_STATUS: True})
                else:
                    return JsonResponse({
                        ARK_STATUS: False,
                        ARK_ERRMSG: '既不是User也不是Team'
                    })
            else:
                return render(request, 'error.html',
                              {ARK_ERRMSG: 'Method is not post'})
    except Exception as e:
        return JsonResponse({ARK_STATUS: False, ARK_ERRMSG: str(e)})
Пример #3
0
def team_info_role_remove_view(request):
    user = request.user
    try:
        if request.is_ajax():
            if request.method == 'POST':
                ajax_data = request.POST.get('data')
                data = json.loads(ajax_data)
                target_team_id = int(data.get('target_team_id'))
                role_id = int(data.get('role_id'))
                status, errmsg = UserAndTeamRoleAPI.delete_role_from_team(
                    user=user, target_team_id=target_team_id, role_id=role_id)
                if not status:
                    return JsonResponse({
                        ARK_STATUS: False,
                        ARK_ERRMSG: '权限不足'
                    })
                return JsonResponse({ARK_STATUS: True})
    except Exception as e:
        return JsonResponse({ARK_STATUS: False, ARK_ERRMSG: str(e)})