Exemplo n.º 1
0
def node_register_template_page_post(auth, node, **kwargs):
    data = request.json

    if settings.DISK_SAVING_MODE:
        raise HTTPError(
            http.METHOD_NOT_ALLOWED,
            redirect_url=node.url
        )

    # Sanitize payload data
    clean_data = process_payload(data)

    template = kwargs['template']
    # TODO: Using json.dumps because node_to_use.registered_meta's values are
    # expected to be strings (not dicts). Eventually migrate all these to be
    # dicts, as this is unnecessary
    schema = MetaSchema.find(
        Q('name', 'eq', template)
    ).sort('-schema_version')[0]
    register = node.register_node(
        schema, auth, template, json.dumps(clean_data),
    )

    return {
        'status': 'success',
        'result': register.url,
    }, http.CREATED
Exemplo n.º 2
0
def node_register_template_page_post(auth, **kwargs):
    node = kwargs['node'] or kwargs['project']
    data = request.json

    if settings.DISK_SAVING_MODE:
        raise HTTPError(http.METHOD_NOT_ALLOWED, redirect_url=node.url)

    # Sanitize payload data
    clean_data = process_payload(data)

    template = kwargs['template']
    # TODO: Using json.dumps because node_to_use.registered_meta's values are
    # expected to be strings (not dicts). Eventually migrate all these to be
    # dicts, as this is unnecessary
    schema = MetaSchema.find(Q('name', 'eq',
                               template)).sort('-schema_version')[0]
    register = node.register_node(
        schema,
        auth,
        template,
        json.dumps(clean_data),
    )

    return {
        'status': 'success',
        'result': register.url,
    }, http.CREATED
Exemplo n.º 3
0
def node_register_template_page_post(auth, node, **kwargs):
    data = request.json

    if settings.DISK_SAVING_MODE:
        raise HTTPError(http.METHOD_NOT_ALLOWED, redirect_url=node.url)

    # Sanitize payload data
    clean_data = process_payload(data)

    template = kwargs['template']
    # TODO: Using json.dumps because node_to_use.registered_meta's values are
    # expected to be strings (not dicts). Eventually migrate all these to be
    # dicts, as this is unnecessary
    schema = MetaSchema.find(Q('name', 'eq',
                               template)).sort('-schema_version')[0]

    # Create the registration
    register = node.register_node(
        schema,
        auth,
        template,
        json.dumps(clean_data),
    )

    if data.get('registrationChoice', 'immediate') == 'embargo':
        embargo_end_date = parse_date(data['embargoEndDate'], ignoretz=True)

        # Initiate embargo
        try:
            register.embargo_registration(auth.user, embargo_end_date)
            register.save()
        except ValidationValueError as err:
            raise HTTPError(http.BAD_REQUEST,
                            data=dict(message_long=err.message))
        if settings.ENABLE_ARCHIVER:
            register.archive_job.meta = {
                'embargo_urls': {
                    contrib._id:
                    project_utils.get_embargo_urls(register, contrib)
                    for contrib in node.active_contributors()
                }
            }
            register.archive_job.save()
    else:
        register.set_privacy('public', auth, log=False)
        for child in register.get_descendants_recursive(lambda n: n.primary):
            child.set_privacy('public', auth, log=False)

    push_status_message(
        'Files are being copied to the newly created registration, and you will receive an email '
        'notification containing a link to the registration when the copying is finished.',
        kind='info',
        trust=False)

    return {
        'status': 'initiated',
        'urls': {
            'registrations': node.web_url_for('node_registrations')
        }
    }, http.CREATED
Exemplo n.º 4
0
def node_register_template_page_post(auth, node, **kwargs):
    data = request.json

    if settings.DISK_SAVING_MODE:
        raise HTTPError(
            http.METHOD_NOT_ALLOWED,
            redirect_url=node.url
        )

    # Sanitize payload data
    clean_data = process_payload(data)

    template = kwargs['template']
    # TODO: Using json.dumps because node_to_use.registered_meta's values are
    # expected to be strings (not dicts). Eventually migrate all these to be
    # dicts, as this is unnecessary
    schema = MetaSchema.find(
        Q('name', 'eq', template)
    ).sort('-schema_version')[0]

    # Create the registration
    register = node.register_node(
        schema, auth, template, json.dumps(clean_data),
    )

    if data.get('registrationChoice', 'immediate') == 'embargo':
        embargo_end_date = parse_date(data['embargoEndDate'], ignoretz=True)

        # Initiate embargo
        try:
            register.embargo_registration(auth.user, embargo_end_date)
            register.save()
        except ValidationValueError as err:
            raise HTTPError(http.BAD_REQUEST, data=dict(message_long=err.message))
        if settings.ENABLE_ARCHIVER:
            register.archive_job.meta = {
                'embargo_urls': {
                    contrib._id: project_utils.get_embargo_urls(register, contrib)
                    for contrib in node.active_contributors()
                }
            }
            register.archive_job.save()
    else:
        register.set_privacy('public', auth, log=False)
        for child in register.get_descendants_recursive(lambda n: n.primary):
            child.set_privacy('public', auth, log=False)

    push_status_message('Files are being copied to the newly created registration, and you will receive an email '
                        'notification containing a link to the registration when the copying is finished.',
                        kind='info',
                        trust=False)

    return {
        'status': 'initiated',
        'urls': {
            'registrations': node.web_url_for('node_registrations')
        }
    }, http.CREATED
Exemplo n.º 5
0
def node_register_template_page_post(auth, node, **kwargs):
    data = request.json

    if settings.DISK_SAVING_MODE:
        raise HTTPError(http.METHOD_NOT_ALLOWED, redirect_url=node.url)

    # Sanitize payload data
    clean_data = process_payload(data)

    template = kwargs['template']
    # TODO: Using json.dumps because node_to_use.registered_meta's values are
    # expected to be strings (not dicts). Eventually migrate all these to be
    # dicts, as this is unnecessary
    schema = MetaSchema.find(Q('name', 'eq',
                               template)).sort('-schema_version')[0]

    # Create the registration
    register = node.register_node(
        schema,
        auth,
        template,
        json.dumps(clean_data),
    )
    register.is_public = False
    for node in register.get_descendants_recursive():
        node.is_public = False
        node.save()
    try:
        if data.get('registrationChoice', 'immediate') == 'embargo':
            # Initiate embargo
            embargo_end_date = parse_date(data['embargoEndDate'],
                                          ignoretz=True)
            register.embargo_registration(auth.user, embargo_end_date)
        else:
            register.require_approval(auth.user)
        register.save()
    except ValidationValueError as err:
        raise HTTPError(http.BAD_REQUEST, data=dict(message_long=err.message))

    push_status_message(language.AFTER_REGISTER_ARCHIVING,
                        kind='info',
                        trust=False)

    return {
        'status': 'initiated',
        'urls': {
            'registrations': node.web_url_for('node_registrations')
        }
    }, http.CREATED
Exemplo n.º 6
0
def node_register_template_page_post(auth, node, **kwargs):
    data = request.json

    if settings.DISK_SAVING_MODE:
        raise HTTPError(
            http.METHOD_NOT_ALLOWED,
            redirect_url=node.url
        )

    # Sanitize payload data
    clean_data = process_payload(data)

    template = kwargs['template']
    # TODO: Using json.dumps because node_to_use.registered_meta's values are
    # expected to be strings (not dicts). Eventually migrate all these to be
    # dicts, as this is unnecessary
    schema = MetaSchema.find(
        Q('name', 'eq', template)
    ).sort('-schema_version')[0]

    # Create the registration
    register = node.register_node(
        schema, auth, template, json.dumps(clean_data),
    )
    register.is_public = False
    for node in register.get_descendants_recursive():
        node.is_public = False
        node.save()
    try:
        if data.get('registrationChoice', 'immediate') == 'embargo':
            # Initiate embargo
            embargo_end_date = parse_date(data['embargoEndDate'], ignoretz=True)
            register.embargo_registration(auth.user, embargo_end_date)
        else:
            register.require_approval(auth.user)
        register.save()
    except ValidationValueError as err:
        raise HTTPError(http.BAD_REQUEST, data=dict(message_long=err.message))

    push_status_message(language.AFTER_REGISTER_ARCHIVING,
                        kind='info',
                        trust=False)

    return {
        'status': 'initiated',
        'urls': {
            'registrations': node.web_url_for('node_registrations')
        }
    }, http.CREATED
Exemplo n.º 7
0
def node_register_template_page_post(auth, **kwargs):
    node = kwargs['node'] or kwargs['project']
    data = request.json

    # Sanitize payload data
    clean_data = process_payload(data)

    template = kwargs['template']
    # TODO: Using json.dumps because node_to_use.registered_meta's values are
    # expected to be strings (not dicts). Eventually migrate all these to be
    # dicts, as this is unnecessary
    schema = MetaSchema.find(
        Q('name', 'eq', template)
    ).sort('-schema_version')[0]
    register = node.register_node(
        schema, auth, template, json.dumps(clean_data),
    )

    return {
        'status': 'success',
        'result': register.url,
    }, http.CREATED
Exemplo n.º 8
0
 def test_process_whitespace(self):
     processed = process_payload({'foo': 'bar baz'})
     assert_equal(processed['foo'], 'bar baz')
Exemplo n.º 9
0
 def test_process_list(self):
     processed = process_payload({'foo': ['bar', 'baz&bob']})
     assert_equal(processed['foo'][1], 'baz%26bob')
Exemplo n.º 10
0
 def test_process(self):
     processed = process_payload({'foo': 'bar&baz'})
     assert_equal(processed['foo'], 'bar%26baz')
Exemplo n.º 11
0
 def test_process_whitespace(self):
     processed = process_payload({'foo': 'bar baz'})
     assert_equal(processed['foo'], 'bar baz')
Exemplo n.º 12
0
 def test_process_list(self):
     processed = process_payload({'foo': ['bar', 'baz&bob']})
     assert_equal(processed['foo'][1], 'baz%26bob')
Exemplo n.º 13
0
 def test_process(self):
     processed = process_payload({'foo': 'bar&baz'})
     assert_equal(processed['foo'], 'bar%26baz')