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

Org list #1255

Merged
merged 3 commits into from
Dec 9, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ const OrganizationsList = ({ organizations }) => {
<i className="building outline icon" aria-hidden="true" />
{organizations[0].id ? (
<a
href={`https://ror.org/${organizations[0].id}`}
aria-label={`${organizations[0].name}'s ROR profile`}
title={`${organizations[0].name}'s ROR profile`}
href={organizations[0].url}
aria-label={`${organizations[0].name}'s ${organizations[0].label} profile`}
title={`${organizations[0].name}'s ${organizations[0].label} profile`}
target="_blank"
rel="noreferrer"
>
{organizations[0].name}
<span>&nbsp;</span>
<img
className="inline-id-icon"
src="/static/images/ror-icon.svg"
alt={`${organizations[0].name}'s ROR profile`}
src={organizations[0].icon}
alt={`${organizations[0].name}'s ${organizations[0].label} profile`}
/>
</a>
) : (
Expand All @@ -50,18 +50,18 @@ const OrganizationsList = ({ organizations }) => {
<div key={org.id || org.name} className="inline-computer mt-5">
{org.id ? (
<a
href={`https://ror.org/${org.id}`}
aria-label={`${org.name}'s ROR profile`}
title={`${org.name}'s ROR profile`}
href={org.url}
aria-label={`${org.name}'s ${org.label} profile`}
title={`${org.name}'s ${org.label} profile`}
target="_blank"
rel="noreferrer"
>
{org.name}
<span>&nbsp;</span>
<img
className="inline-id-icon"
src="/static/images/ror-icon.svg"
alt={`${organizations[0].name}'s ROR profile`}
src={org.icon}
alt={`${org.name}'s ${org.label} profile`}
/>
</a>
) : (
Expand Down Expand Up @@ -89,6 +89,9 @@ OrganizationsList.propTypes = {
PropTypes.shape({
id: PropTypes.string,
name: PropTypes.string.isRequired,
label: PropTypes.string,
icon: PropTypes.string,
url: PropTypes.string,
})
).isRequired,
};
Expand Down
2 changes: 1 addition & 1 deletion invenio_communities/communities/records/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Community(Record):
),
organizations=PIDListRelation(
"metadata.organizations",
keys=["name"],
keys=["name", "identifiers"],
pid_field=Affiliation.pid,
cache_key="affiliations",
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
"tokenizer": "standard",
"type": "custom",
"char_filter": ["strip_special_chars"],
"filter": [
"lowercase",
"asciifolding",
"edgegrams"
]
"filter": ["lowercase", "asciifolding", "edgegrams"]
}
},
"filter": {
Expand Down Expand Up @@ -209,6 +205,21 @@
},
"name": {
"type": "text"
},
"identifiers": {
"properties": {
"identifier": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"scheme": {
"type": "keyword"
}
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
"tokenizer": "standard",
"type": "custom",
"char_filter": ["strip_special_chars"],
"filter": [
"lowercase",
"asciifolding",
"edgegrams"
]
"filter": ["lowercase", "asciifolding", "edgegrams"]
}
},
"filter": {
Expand Down Expand Up @@ -209,6 +205,21 @@
},
"name": {
"type": "text"
},
"identifiers": {
"properties": {
"identifier": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"scheme": {
"type": "keyword"
}
}
}
}
},
Expand Down
16 changes: 16 additions & 0 deletions invenio_communities/communities/resources/ui_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from flask import g
from flask_resources import BaseObjectSchema
from idutils import detect_identifier_schemes, to_url
from invenio_i18n import get_locale
from invenio_i18n import lazy_gettext as _
from invenio_records_resources.services.custom_fields import CustomFieldsSchemaUI
Expand Down Expand Up @@ -101,6 +102,8 @@ class UICommunitySchema(BaseObjectSchema):

tombstone = fields.Nested(TombstoneSchema, attribute="tombstone")

organizations = fields.Method("get_organizations", dump_only=True)

theme = fields.Nested(CommunityThemeSchema, dump_only=True, load_default={})

# Custom fields
Expand All @@ -110,6 +113,19 @@ class UICommunitySchema(BaseObjectSchema):

permissions = fields.Method("get_permissions", dump_only=True)

def get_organizations(self, obj):
"""Get organizations with metadata."""
organizations = obj.get("metadata", {}).get("organizations", [])

for org in organizations:
if "id" in org:
scheme = detect_identifier_schemes(org["id"])[0]
org["icon"] = f"/static/images/{scheme}-icon.svg"
org["url"] = to_url(org["id"], scheme)
org["label"] = scheme

return organizations

def get_permissions(self, obj):
"""Get permission."""
if obj == {}:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
{% endif %}

{% if community.metadata.organizations %}
<div class="inline-computer" id="organizations-list" data-organizations='{{ community.metadata.organizations|tojson }}'></div>
<div class="inline-computer" id="organizations-list" data-organizations='{{ community.ui.organizations|tojson }}'></div>
{% endif %}
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions tests/communities/test_relations_organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def test_community_organizations_indexing(
{
"id": "cern",
"name": "CERN",
"identifiers": [
{"scheme": "ror", "identifier": "01ggx4157"},
{"scheme": "isni", "identifier": "000000012156142X"},
],
"@v": dump["metadata"]["organizations"][1]["@v"],
},
]
Expand Down
Loading