def test_get_or_http_error_by_query_found(self): n = factories.NodeFactory() found = get_or_http_error( Node, (Q('title', 'eq', n.title) & Q('_id', 'eq', n._id)) ) assert found == n
def wrapped(*args, **kwargs): node = get_or_http_error(AbstractNode, kwargs.get('nid', kwargs.get('pid')), allow_deleted=True) if node.sanction and node.sanction.is_rejected: raise HTTPError(http.GONE, data=dict( message_long='This registration has been rejected' )) return func(*args, **kwargs)
from api.base.utils import rapply from website.exceptions import NodeStateError from website.project.decorators import ( must_be_valid_project, must_have_permission, http_error_if_disk_saving_mode ) from website import language, settings from website.prereg import utils as prereg_utils from website.project import utils as project_utils from website.project.metadata.schemas import LATEST_SCHEMA_VERSION, METASCHEMA_ORDERING from website.project.metadata.utils import serialize_meta_schema, serialize_draft_registration from website.project.utils import serialize_node get_schema_or_fail = lambda query: get_or_http_error(MetaSchema, query) autoload_draft = functools.partial(autoload, DraftRegistration, 'draft_id', 'draft') def must_be_branched_from_node(func): @autoload_draft @must_be_valid_project @functools.wraps(func) def wrapper(*args, **kwargs): node = kwargs['node'] draft = kwargs['draft'] if draft.deleted: raise HTTPError(http.GONE) if not draft.branched_from._id == node._id: raise HTTPError( http.BAD_REQUEST, data={
def test_get_or_http_error_by_query_not_unique(self): title = 'TITLE' factories.NodeFactory(title=title) factories.NodeFactory(title=title) with pytest.raises(HTTPError): get_or_http_error(Node, Q(title=title))
def test_get_or_http_error_by_query_not_found(self): with pytest.raises(HTTPError): get_or_http_error(Node, Q(guids___id='blah'))
def test_get_or_http_error_by_query_found(self): n = factories.NodeFactory() found = get_or_http_error(Node, Q(title=n.title, guids___id=n._id)) assert found == n
def test_get_or_http_error_by_pk_not_found(self): with pytest.raises(HTTPError): get_or_http_error(Node, 'blah')
from furl import furl from flask import request from framework import status from framework.auth import Auth, cas from framework.flask import redirect # VOL-aware redirect from framework.exceptions import HTTPError, TemplateHTTPError from framework.auth.decorators import collect_auth from framework.database import get_or_http_error from osf.models import AbstractNode, Guid, Preprint, OSFGroup from osf.utils.permissions import WRITE from website import language from website.util import web_url_for _load_node_or_fail = lambda pk: get_or_http_error(AbstractNode, pk) def _kwargs_to_nodes(kwargs): """Retrieve project and component objects from keyword arguments. :param dict kwargs: Dictionary of keyword arguments :return: Tuple of parent and node """ node = kwargs.get('node') or kwargs.get('project') parent = kwargs.get('parent') if node: return parent, node pid = kwargs.get('pid')
from furl import furl from flask import request from framework import status from framework.auth import Auth, cas from framework.flask import redirect # VOL-aware redirect from framework.exceptions import HTTPError, TemplateHTTPError from framework.auth.decorators import collect_auth from framework.database import get_or_http_error from osf.models import AbstractNode, Guid from website import settings, language from website.util import web_url_for _load_node_or_fail = lambda pk: get_or_http_error(AbstractNode, pk) def _kwargs_to_nodes(kwargs): """Retrieve project and component objects from keyword arguments. :param dict kwargs: Dictionary of keyword arguments :return: Tuple of parent and node """ node = kwargs.get('node') or kwargs.get('project') parent = kwargs.get('parent') if node: return parent, node pid = kwargs.get('pid')
def test_get_or_http_error_by_query_not_unique(self): title = 'TITLE' factories.NodeFactory(title=title) factories.NodeFactory(title=title) with pytest.raises(HTTPError): get_or_http_error(Node, Q('title', 'eq', title))
def test_get_or_http_error_by_query_not_found(self): with pytest.raises(HTTPError): get_or_http_error(Node, Q('_id', 'eq', 'blah'))
def test_get_or_http_error_by_pk_found(self): n = factories.NodeFactory() found = get_or_http_error(Node, n._id) assert found == n
from website.exceptions import NodeStateError from website.project.decorators import ( must_be_valid_project, must_have_permission, http_error_if_disk_saving_mode ) from website import language, settings from website.ember_osf_web.decorators import ember_flag_is_active from website.prereg import utils as prereg_utils from website.project import utils as project_utils from website.project.metadata.schemas import LATEST_SCHEMA_VERSION, METASCHEMA_ORDERING from website.project.metadata.utils import serialize_meta_schema, serialize_draft_registration from website.project.utils import serialize_node get_schema_or_fail = lambda query: get_or_http_error(RegistrationSchema, query) autoload_draft = functools.partial(autoload, DraftRegistration, 'draft_id', 'draft') def must_be_branched_from_node(func): @autoload_draft @must_be_valid_project @functools.wraps(func) def wrapper(*args, **kwargs): node = kwargs['node'] draft = kwargs['draft'] if draft.deleted: raise HTTPError(http.GONE) if not draft.branched_from._id == node._id: raise HTTPError( http.BAD_REQUEST, data={
from website.exceptions import NodeStateError from website.util.permissions import ADMIN from website.project.decorators import (must_be_valid_project, must_have_permission, http_error_if_disk_saving_mode) from website import language, settings from website.prereg import utils as prereg_utils from website.project import utils as project_utils from website.project.metadata.schemas import LATEST_SCHEMA_VERSION, METASCHEMA_ORDERING from website.project.metadata.utils import serialize_meta_schema, serialize_draft_registration from website.project.utils import serialize_node from website.util import rapply from website.util.sanitize import strip_html get_schema_or_fail = lambda query: get_or_http_error(MetaSchema, query) autoload_draft = functools.partial(autoload, DraftRegistration, 'draft_id', 'draft') def must_be_branched_from_node(func): @autoload_draft @must_be_valid_project @functools.wraps(func) def wrapper(*args, **kwargs): node = kwargs['node'] draft = kwargs['draft'] if draft.deleted: raise HTTPError(http.GONE) if not draft.branched_from._id == node._id: raise HTTPError(
from osf.utils.functional import rapply from osf.models import NodeLog, RegistrationSchema, DraftRegistration, Sanction from website.project.decorators import ( must_be_valid_project, must_have_permission, ) from website import language, settings from website.ember_osf_web.decorators import ember_flag_is_active from website.prereg import utils as prereg_utils from website.project import utils as project_utils from website.project.metadata.schemas import LATEST_SCHEMA_VERSION, METASCHEMA_ORDERING from website.project.metadata.utils import serialize_meta_schema, serialize_draft_registration from website.project.utils import serialize_node get_schema_or_fail = lambda query: get_or_http_error(RegistrationSchema, query) autoload_draft = functools.partial(autoload, DraftRegistration, 'draft_id', 'draft') def must_be_branched_from_node(func): @autoload_draft @must_be_valid_project @functools.wraps(func) def wrapper(*args, **kwargs): node = kwargs['node'] draft = kwargs['draft'] if draft.deleted: raise HTTPError(http.GONE) if not draft.branched_from._id == node._id: raise HTTPError(