Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link creator's name to search #855

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<span class="label text-muted"> | Version {{ record.ui.version }}</span>
</div>
<div class="right floated right aligned column">
<span class="ui label small grey">{{ record.ui.resource_type }}</span>
<span class="ui label small grey">{{ record.ui.resource_type.title_l10n }}</span>
<span class="ui label small access-status {{ record.ui.access_status.id }}" data-tooltip="{{ record.ui.access_status.description_l10n }}" data-inverted="">
{% if record.ui.access_status.icon %}<i class="icon {{ record.ui.access_status.icon }}"></i>{% endif %}
{{ record.ui.access_status.title_l10n }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<dt><b>{{ _('Details')}}</b></dt>
<hr class="thin-line"></hr>
<dd class="top-bottom-padded">
{{ show_detail(_('Resource type'), record.ui.resource_type) if record.ui.resource_type }}
{{ show_detail(_('Resource type'), record.ui.resource_type.title_l10n) if record.ui.resource_type }}
{{ show_detail(_('Publication date'), record.ui.publication_date_l10n) if record.ui.publication_date_l10n }}
{{ show_detail(_('Publisher'), metadata.publisher) if metadata.publisher }}
{{ show_detail(_('Additional titles'), show_add_titles(metadata.additional_titles)) if metadata.additional_titles }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
{% macro show_creatibutors(creatibutors, show_affiliations=False) %}
{% for creatibutor in creatibutors %}
{{ creatibutor_icon(creatibutor) }}
<span
<a
class="ui tooltip-popup text-muted"
{% if show_affiliations and creatibutor.affiliations %}
data-content="{{ creatibutor.affiliations|join('; ', attribute='1') }}"
{% endif %}
>
href="{{ url_for('invenio_search_ui.search', q='metadata.creators.person_or_org.name:') }}{{ creatibutor.person_or_org.name}}">
{{ creatibutor.person_or_org.name }}
</span>
</a>
<sup class="font-tiny">
{% for affiliation in creatibutor.affiliations %}
{{ affiliation[0] }}{{ ", " if not loop.last }}
Expand Down
22 changes: 21 additions & 1 deletion invenio_app_rdm/records_ui/views/deposits.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@

from flask import current_app, render_template
from flask_login import login_required
from invenio_access.permissions import system_identity
from invenio_i18n.ext import current_i18n
from invenio_rdm_records.proxies import current_rdm_records
from invenio_rdm_records.resources.serializers import UIJSONSerializer
from invenio_rdm_records.services.schemas import RDMRecordSchema
from invenio_rdm_records.services.schemas.utils import dump_empty
from invenio_rdm_records.vocabularies import Vocabularies
from invenio_vocabularies.proxies import current_service as vocabulary_service

from ..utils import set_default_value
from .decorators import pass_draft, pass_draft_files
Expand Down Expand Up @@ -65,10 +67,28 @@ def get_form_pids_config():
return pids_providers


def _dump_resource_type_vocabulary():
"""Dump resource type vocabulary."""
# TODO: invenio-vocabularies needs to implement read_all before it can be
# used here.
results = vocabulary_service.search(
system_identity, type='resource_types', size=100)
return [
{
"icon": r["props"].get("type_icon", ""),
"id": r["id"],
"subtype_name": r["props"].get("subtype_name", ""),
"type_name": r["props"]["type_name"],
} for r in results.to_dict()["hits"]["hits"]
]


def get_form_config(**kwargs):
"""Get the react form configuration."""
vocabularies = Vocabularies.dump()
vocabularies["resource_type"] = _dump_resource_type_vocabulary()
return dict(
vocabularies=Vocabularies.dump(),
vocabularies=vocabularies,
current_locale=str(current_i18n.locale),
pids=get_form_pids_config(),
**kwargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export const RDMRecordResultsListItem = ({ result, index }) => {
"ui.publication_date_l10n_long",
"No publication date found."
);
const resource_type = _get(result, "ui.resource_type", "No resource type");
const resource_type = _get(
result, "ui.resource_type.title_l10n", "No resource type");
const subjects = _get(result, "metadata.subjects", []);
const title = _get(result, "metadata.title", "No title");
const version = _get(result, "ui.version", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ export const RDMRecordResultsListItem = ({ result, index }) => {
"ui.publication_date_l10n_long",
"No publication date found."
);
const resource_type = _get(result, "ui.resource_type", "No resource type");
const resource_type = _get(
result, "ui.resource_type.title_l10n", "No resource type");
const title = _get(result, "metadata.title", "No title");
const subjects = _get(result, "metadata.subjects", []);
const version = _get(result, "ui.version", null);
Expand Down
6 changes: 3 additions & 3 deletions invenio_app_rdm/theme/webpack.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019-2020 CERN.
# Copyright (C) 2019-2020 Northwestern University.
# Copyright (C) 2019-2021 CERN.
# Copyright (C) 2019-2021 Northwestern University.
# Copyright (C) 2021 TU Wien.
#
# Invenio App RDM is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -36,7 +36,7 @@
'prop-types': '^15.7.2',
'react-dnd': '^11.1.3',
'react-dnd-html5-backend': '^11.1.3',
'react-invenio-deposit': '^0.13.5',
'react-invenio-deposit': '^0.14.0',
'react-invenio-forms': '^0.7.0',
'react-dropzone': "^11.0.3",
'yup': '^0.27.0',
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
'CairoSVG>=1.0.20',
'flask>=1.1,<2.0',
f'invenio[base,auth,metadata,files]{invenio_version}',
'invenio-rdm-records>=0.30.1,<0.31.0',
'invenio-rdm-records>=0.30.4,<0.31.0',
'invenio-communities>=2.3.0.dev1,<2.4.0',
]

Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_protect_files_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def commit_file(client, recid, headers):
# NOTE: It seems like it was already the case that a logged in user wouldn't be
# able to access files-rest. We are just making doubly-clear.
def test_files_rest_endpoint_is_protected(
app, client_with_login, headers, es_clear, location, minimal_record):
running_app, client_with_login, headers, es_clear, minimal_record):
client = client_with_login

# Create draft with file
Expand Down
6 changes: 3 additions & 3 deletions tests/api/test_record_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_record_read_non_existing_pid(client, location, minimal_record,


def test_record_draft_create_and_read(
client_with_login, location, minimal_record, es_clear
client_with_login, running_app, minimal_record, es_clear
):
"""Test draft creation of a non-existing record."""
# create a record
Expand All @@ -54,7 +54,7 @@ def test_record_draft_create_and_read(


def test_record_draft_publish(
client_with_login, headers, location, minimal_record, es_clear
client_with_login, headers, running_app, minimal_record, es_clear
):
"""Test draft publication of a non-existing record.

Expand Down Expand Up @@ -105,7 +105,7 @@ def test_record_draft_publish(


def test_read_record_with_redirected_pid(
client_with_login, headers, location, minimal_record, es_clear
client_with_login, headers, running_app, minimal_record, es_clear
):
"""Test read a record with a redirected pid."""
# Create dummy record
Expand Down
54 changes: 50 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
# Copyright (C) 2019 Northwestern University.
# Copyright (C) 2019-2021 CERN.
# Copyright (C) 2019-2021 Northwestern University.
#
# Invenio App RDM is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Common pytest fixtures and plugins."""

from collections import namedtuple

import pytest
from flask_security import login_user
from flask_security.utils import hash_password
from invenio_access.models import ActionUsers
from invenio_access.permissions import system_identity
from invenio_access.proxies import current_access
from invenio_accounts.proxies import current_datastore
from invenio_accounts.testutils import login_user_via_session
from invenio_db import db
from invenio_vocabularies.proxies import current_service as vocabulary_service

pytest_plugins = ("celery.contrib.pytest", )

Expand All @@ -34,8 +38,7 @@ def minimal_record(users):
"metadata": {
"publication_date": "2020-06-01",
"resource_type": {
"type": "image",
"subtype": "image-photo"
"id": "image-photo",
},
# Technically not required
"creators": [{
Expand Down Expand Up @@ -109,3 +112,46 @@ def client_with_login(client, users):
login_user(user, remember=True)
login_user_via_session(client, email=user.email)
return client


@pytest.fixture(scope="module")
def resource_type_type(app):
"""Resource type vocabulary type."""
return vocabulary_service.create_type(
system_identity, "resource_types", "rsrct")


@pytest.fixture(scope="module")
def resource_type_item(app, resource_type_type):
"""Resource type vocabulary record."""
return vocabulary_service.create(system_identity, {
"id": "image-photo",
"props": {
"csl": "graphic",
"datacite_general": "Image",
"datacite_type": "Photo",
"openaire_resourceType": "25",
"openaire_type": "dataset",
"schema.org": "https://schema.org/Photograph",
"subtype": "image-photo",
"subtype_name": "Photo",
"type": "image",
"type_icon": "chart bar outline",
"type_name": "Image",
},
"title": {
"en": "Photo"
},
"type": "resource_types"
})


RunningApp = namedtuple("RunningApp", [
"app", "location", "resource_type_item"
])


@pytest.fixture
def running_app(app, location, resource_type_item):
"""Fixture mimicking a running app."""
return RunningApp(app, location, resource_type_item)
31 changes: 31 additions & 0 deletions tests/ui/test_deposits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 Northwestern University.
#
# Invenio-App-RDM is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.

"""Test deposit views."""

from invenio_vocabularies.proxies import current_service as vocabulary_service

from invenio_app_rdm.records_ui.views.deposits import \
_dump_resource_type_vocabulary


def test_dump_resource_type_vocabulary(running_app):
# Make sure the indexed values are in ES before we start.
# Don't know why just this test requires this...
vocabulary_service.record_cls.index.refresh()
expected = [
{
"icon": "chart bar outline",
"id": "image-photo",
"subtype_name": "Photo",
"type_name": "Image",
}
]

result = _dump_resource_type_vocabulary()

assert expected == result