def links_factory(pid, record=None, record_hit=None, **kwargs):
    """Deposit links factory."""
    links = {
        'self':
        api_url_for('depid_item', pid),
        'files':
        api_url_for('depid_files', pid),
        'html':
        current_app.config['DEPOSIT_UI_ENDPOINT'].format(
            host=request.host,
            scheme=request.scheme,
            pid_value=pid.pid_value,
        )
    }

    try:
        bucket_link = default_bucket_link_factory(pid)
        if bucket_link:
            links['bucket'] = url_to_api_url(bucket_link)
    except Exception:
        current_app.logger.info(
            f'Bucket link generation error for deposit: {pid.pid_value}')

    for action in extract_actions_from_class(CAPDeposit):
        if action != "review":
            links[action] = api_url_for('depid_actions', pid, action=action)

    return links
Ejemplo n.º 2
0
def deposit_links_factory(pid, deposit_type=None):
    """Factory for links generation."""
    type_exists = deposit_type is not None
    deposit_type = deposit_type or pid.pid_type

    def _url(name, **kwargs):
        """URL builder."""
        endpoint = '.{0}_{1}'.format(deposit_type, name)
        return url_for(endpoint,
                       pid_value=pid.pid_value,
                       _external=True,
                       **kwargs)

    links = {}
    bucket_link = default_bucket_link_factory(pid)
    if bucket_link is not None:
        links['bucket'] = bucket_link
    links['self'] = _url('item')
    links['files'] = _url('files')
    ui_endpoint = current_app.config.get('DEPOSIT_UI_ENDPOINT' if type_exists
                                         else 'DEPOSIT_UI_ENDPOINT_DEFAULT')
    if ui_endpoint is not None:
        links['html'] = ui_endpoint.format(
            host=request.host,
            scheme=request.scheme,
            type=deposit_type,
            pid_value=pid.pid_value,
        )
    for action in ('publish', 'edit', 'discard'):
        links[action] = _url('actions', action=action)
    return links
Ejemplo n.º 3
0
def links_factory(pid):
    """Record links factory with files."""
    links = default_links_factory(pid)

    bucket_link = default_bucket_link_factory(pid)
    if bucket_link is not None:
        links['bucket'] = bucket_link
    return links
Ejemplo n.º 4
0
def links_factory(pid):
    """Record links factory with files."""
    links = default_links_factory(pid)

    bucket_link = default_bucket_link_factory(pid)
    if bucket_link is not None:
        links['bucket'] = bucket_link
    return links
Ejemplo n.º 5
0
def links_factory(pid):
    """Deposit links factory."""
    links = deposit_links_factory(pid)
    links['html'] = links['html'].replace('deposit', 'drafts')
    bucket_link = default_bucket_link_factory(pid)
    if bucket_link is not None:
        links['bucket'] = bucket_link
    return links
def links_factory(pid):
    """Deposit links factory."""
    links = deposit_links_factory(pid)
    links.pop('html', None)
    bucket_link = default_bucket_link_factory(pid)
    if bucket_link is not None:
        links['bucket'] = bucket_link
    return links
def links_factory(pid):
    """Deposit links factory."""
    links = deposit_links_factory(pid)

    bucket_link = default_bucket_link_factory(pid)
    if bucket_link is not None:
        links['bucket'] = bucket_link
    return links
Ejemplo n.º 8
0
def test_bucket_link_factory_has_bucket(app, db, location, bucket):
    """Test bucket link factory retrieval of a bucket."""
    with app.test_request_context():
        with db.session.begin_nested():
            record = RecordMetadata()
            RecordsBuckets.create(record, bucket)
            db.session.add(record)
        pid = mock.Mock()
        pid.get_assigned_object.return_value = record.id
        assert default_bucket_link_factory(pid) == url_for(
            'invenio_files_rest.bucket_api', bucket_id=bucket.id,
            _external=True)
Ejemplo n.º 9
0
def test_bucket_link_factory_has_bucket(app, db, location, bucket):
    """Test bucket link factory retrieval of a bucket."""
    with app.test_request_context():
        with db.session.begin_nested():
            record = RecordMetadata()
            RecordsBuckets.create(record, bucket)
            db.session.add(record)
        pid = mock.Mock()
        pid.get_assigned_object.return_value = record.id
        assert default_bucket_link_factory(pid) == url_for(
            'invenio_files_rest.bucket_api', bucket_id=bucket.id,
            _external=True)
Ejemplo n.º 10
0
def links_factory(pid, record=None):
    """Deposit links factory."""
    links = {
        'self': api_url_for('recid_item', pid),
        'html': current_app.config['RECORDS_UI_ENDPOINT'].format(
            host=request.host,
            scheme=request.scheme,
            pid_value=pid.pid_value,
        )
    }

    bucket_link = default_bucket_link_factory(pid)
    if bucket_link:
        links['bucket'] = url_to_api_url(bucket_link)

    return links
Ejemplo n.º 11
0
def links_factory(pid, record=None):
    """Deposit links factory."""
    links = {
        'self':
        api_url_for('depid_item', pid),
        'files':
        api_url_for('depid_files', pid),
        'html':
        current_app.config['DEPOSIT_UI_ENDPOINT'].format(
            host=request.host,
            scheme=request.scheme,
            pid_value=pid.pid_value,
        )
    }

    bucket_link = default_bucket_link_factory(pid)
    if bucket_link:
        links['bucket'] = url_to_api_url(bucket_link)

    for action in extract_actions_from_class(CAPDeposit):
        links[action] = api_url_for('depid_actions', pid, action=action)

    return links
Ejemplo n.º 12
0
def test_bucket_link_factory_no_bucket(app, db, location, record):
    """Test bucket link factory without a bucket."""
    assert default_bucket_link_factory(None) is None
Ejemplo n.º 13
0
def test_bucket_link_factory_no_bucket(app, db, location, record):
    """Test bucket link factory without a bucket."""
    assert default_bucket_link_factory(None) is None