Exemplo n.º 1
0
    def create(self, request, workspace_id):

        workspace = get_object_or_404(Workspace, pk=workspace_id)
        data = parse_json_request(request)

        if 'name' not in data and 'title' not in data:
            return build_error_response(
                request, 422,
                _('Malformed tab JSON: expecting tab name or title.'))

        if not (request.user.is_superuser
                or workspace.creator == request.user):
            return build_error_response(
                request, 403,
                _('You are not allowed to create new tabs for this workspace'))

        tab_title = data.get('title')
        tab_name = data.get('name')
        try:
            tab = createTab(tab_title, workspace, name=tab_name)
        except IntegrityError:
            msg = _(
                'A tab with the given name already exists for the workspace')
            return build_error_response(request, 409, msg)

        return HttpResponse(json.dumps(get_tab_data(tab, user=request.user)),
                            status=201,
                            content_type='application/json; charset=UTF-8')
Exemplo n.º 2
0
    def read(self, request, workspace_id, tab_id):

        tab = get_object_or_404(Tab.objects.select_related('workspace'), workspace__pk=workspace_id, pk=tab_id)
        if not tab.workspace.is_available_for(request.user):
            return build_error_response(request, 403, _("You don't have permission to access this workspace"))

        data = json.dumps(get_tab_data(tab, user=request.user), sort_keys=True)
        return HttpResponse(data, status=200, content_type='application/json; charset=UTF-8')
Exemplo n.º 3
0
    def read(self, request, workspace_id, tab_id):

        tab = get_object_or_404(Tab.objects.select_related('workspace'), workspace__pk=workspace_id, pk=tab_id)
        if not tab.workspace.is_available_for(request.user):
            return build_error_response(request, 403, _("You don't have permission to access this workspace"))

        data = json.dumps(get_tab_data(tab, user=request.user), sort_keys=True)
        return HttpResponse(data, status=200, content_type='application/json; charset=UTF-8')
Exemplo n.º 4
0
    def create(self, request, workspace_id):

        workspace = get_object_or_404(Workspace, pk=workspace_id)
        data = parse_json_request(request)

        if 'name' not in data:
            return build_error_response(request, 422, _('Malformed tab JSON: expecting tab name.'))

        tab_name = data['name']
        if not (request.user.is_superuser or workspace.creator == request.user):
            return build_error_response(request, 403, _('You are not allowed to create new tabs for this workspace'))

        try:
            tab = createTab(tab_name, workspace)
        except IntegrityError:
            msg = _('A tab with the given name already exists for the workspace')
            return build_error_response(request, 409, msg)

        return HttpResponse(json.dumps(get_tab_data(tab, user=request.user)), status=201, content_type='application/json; charset=UTF-8')