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

documents: add a configuration for links on identifiers #782

Merged
merged 1 commit into from
Mar 7, 2022
Merged
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
15 changes: 15 additions & 0 deletions sonar/config_sonar.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,18 @@

SONAR_APP_SWISSCOVERY_SEARCH_URL = 'https://swisscovery.slsp.ch/view/sru/41SLSP_NETWORK'
SONAR_APP_SWISSCOVERY_SEARCH_VERSION = '1.1'

# Link on document identifier
# Add the source identifier in lowercase (Ex: orcid)
SONAR_APP_DOCUMENT_IDENTIFIER_LINK = {
'bf:Doi': {
'default': 'https://doi.org/_identifier_'
},
'bf:Local': {
'orcid': 'https://orcid.org/_identifier_',
'swisscovery': 'https://swisscovery.slsp.ch/permalink/41SLSP_NETWORK/1ufb5t2/alma_identifier_'
},
'bf:Urn': {
'default': 'https://nbn-resolving.org/_identifier_'
}
}
17 changes: 3 additions & 14 deletions sonar/modules/documents/templates/documents/record.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

{%- extends config.RECORDS_UI_BASE_TEMPLATE %}

{% from 'sonar/macros/macro.html' import thumbnail %}
{% from 'sonar/macros/macro.html' import thumbnail, identifier_link %}

{% set title = record.title[0] | title_format(current_i18n.language) %}
{% set description = record.abstracts[0].value if record.abstracts else None %}
Expand Down Expand Up @@ -97,10 +97,7 @@ <h4 class="m-0">
<li class="creator {{ 'd-none' if loop.index > 3 }}">
{{ contribution | contribution_text }}
{% if contribution.agent.get('identifiedBy', {}).get('value') %}
<a href="https://orcid.org/{{ contribution.agent.identifiedBy.value }}" target="_blank"
class="badge badge-secondary text-light">
ORCID
</a>
{{ identifier_link(contribution.agent.identifiedBy, 'agent')}}
{% endif %}

{% if contribution.get('affiliation') %}
Expand Down Expand Up @@ -261,15 +258,7 @@ <h5 class="d-inline">
<ul class="list-unstyled mb-0">
{% for identifier in record.identifiedBy %}
<li>
<span class="badge badge-secondary text-light mr-1">{{ _(identifier.type) }}</span>
{% if identifier.type == 'bf:Doi' %}
<a href="https://doi.org/{{ identifier.value }}" target="_blank">{{ identifier.value }}</a>
{% else %}
{{ identifier.value }}
{% endif %}
{% if identifier.source %}
<i class="text-muted ml-1">{{ identifier.source }}</i>
{% endif %}
{{ identifier_link(identifier, 'identifiedBy') }}
</li>
{% endfor %}
</ul>
Expand Down
35 changes: 35 additions & 0 deletions sonar/theme/templates/sonar/macros/macro.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,38 @@
<img src="{{ image }}" class="img-fluid" alt="{{ label }}">
{% endif%}
{% endmacro %}

{% macro identifier_link(identifier, field) %}
{% set linkText = _('External link to the source') %}
{% if identifier.type in config.SONAR_APP_DOCUMENT_IDENTIFIER_LINK %}
{% set source = 'default' if not identifier.source else identifier.source|lower %}
{% if source in config.SONAR_APP_DOCUMENT_IDENTIFIER_LINK[identifier.type] %}
{% set link = config.SONAR_APP_DOCUMENT_IDENTIFIER_LINK[identifier.type][source].replace('_identifier_', identifier.value) %}
{% else %}
{% set link = null %}
{% endif %}
{% endif %}

{% if 'identifiedBy' == field %}
<span class="badge badge-secondary text-light mr-1">{{ identifier.source|upper if identifier.source else _(identifier.type)|upper }}</span>
{% if link %}
<a href="{{ link }}" title="{{ linkText }}" target="_blank">{{ identifier.value }}</a>
{% else %}
{% if identifier.value.startswith('http') %}
<a href="{{ link }}" title="{{ linkText }}" target="_blank">{{ identifier.value }}</a>
{% else %}
{{ identifier.value }}
{% endif %}
{% endif %}
{% endif %}

{% if 'agent' == field %}
{% if link %}
<a class="badge badge-secondary text-light mr-1" href="{{ link }}" title="{{ linkText }}" target="_blank">
{{ identifier.source|upper if identifier.source else _(identifier.type) }}
</a>
{% else %}
<span class="badge badge-secondary text-light mr-1">{{ identifier.source|upper if identifier.source else _(identifier.type)|upper }}</span>
{% endif %}
{% endif %}
{% endmacro %}
7 changes: 6 additions & 1 deletion sonar/theme/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ def logged_user():
if user and 'resolve' in request.args:
user = user.replace_refs()

data = {}
data = {
'settings': {
'document_identifier_link': current_app.config \
.get('SONAR_APP_DOCUMENT_IDENTIFIER_LINK')
}
}

if user:
data['metadata'] = user.dumps()
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def test_logged_user(app, client, superuser, admin, moderator, submitter,
assert b'"email":"orgadmin@rero.ch"' in res.data
assert b'"pid":"org"' in res.data

# Check settings
assert 'settings' in res.json

# Logged as superuser
login_user_via_session(client, email=superuser['email'])
res = client.get(url)
Expand Down