Skip to content

Commit 2c8b4cf

Browse files
fenekkumax-moser
authored andcommitted
urls: integrate invenio_url_for
1 parent c807b72 commit 2c8b4cf

32 files changed

+236
-205
lines changed

invenio_rdm_records/resources/resources.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from flask import abort, current_app, g, redirect, url_for
1717
from flask_resources import Resource, resource_requestctx, response_handler, route
18+
from invenio_base import invenio_url_for
1819
from invenio_drafts_resources.resources import RecordResource
1920
from invenio_records_resources.resources.errors import ErrorHandlersMixin
2021
from invenio_records_resources.resources.records.resource import (
@@ -29,8 +30,6 @@
2930
from invenio_stats import current_stats
3031
from sqlalchemy.exc import NoResultFound
3132

32-
from .urls import record_url_for
33-
3433

3534
def response_header_signposting(f):
3635
"""Add signposting link to view's reponse headers.
@@ -44,8 +43,7 @@ def response_header_signposting(f):
4443
@wraps(f)
4544
def inner(*args, **kwargs):
4645
pid_value = resource_requestctx.view_args["pid_value"]
47-
signposting_link = record_url_for(_app="api", pid_value=pid_value)
48-
46+
signposting_link = invenio_url_for("records.read", pid_value=pid_value)
4947
response = f(*args, **kwargs)
5048
if response.status_code != 200:
5149
return response

invenio_rdm_records/resources/serializers/datacite/schema.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
#
33
# Copyright (C) 2021-2024 CERN.
4-
# Copyright (C) 2021 Northwestern University.
4+
# Copyright (C) 2021-2025 Northwestern University.
55
# Copyright (C) 2023 Graz University of Technology.
66
# Copyright (C) 2023 Caltech.
77
#
@@ -15,6 +15,7 @@
1515
from flask import current_app
1616
from flask_resources.serializers import BaseSerializerSchema
1717
from invenio_access.permissions import system_identity
18+
from invenio_base import invenio_url_for
1819
from invenio_i18n import lazy_gettext as _
1920
from marshmallow import Schema, ValidationError, fields, missing, post_dump, validate
2021
from marshmallow_utils.fields import SanitizedUnicode
@@ -458,7 +459,9 @@ def get_related_identifiers(self, obj):
458459
communities = obj.get("parent", {}).get("communities", {}).get("entries", [])
459460
for community in communities:
460461
slug = community.get("slug")
461-
url = f"{current_app.config['SITE_UI_URL']}/communities/{slug}"
462+
url = invenio_url_for(
463+
"invenio_app_rdm_communities.communities_home", pid_value=slug
464+
)
462465
serialized_identifiers.append(
463466
{
464467
"relatedIdentifier": url,

invenio_rdm_records/resources/serializers/dcat/schema.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# -*- coding: utf-8 -*-
22
#
33
# Copyright (C) 2023-2024 CERN.
4+
# Copyright (C) 2025 Northwestern University.
45
#
56
# Invenio-RDM-Records is free software; you can redistribute it and/or modify
67
# it under the terms of the MIT License; see LICENSE file for more details.
78

89
"""Dcat based Schema for Invenio RDM Records."""
910

1011
import idutils
11-
from flask import current_app
12+
from invenio_base import invenio_url_for
1213
from marshmallow import ValidationError, fields, missing, validate
1314
from marshmallow_utils.html import sanitize_unicode
1415

@@ -32,7 +33,11 @@ def get_files(self, obj):
3233
file_name = sanitize_unicode(
3334
value["key"]
3435
) # There can be inconsistencies in the file name i.e. if the file name consists of invalid XML characters
35-
url = f"{current_app.config['SITE_UI_URL']}/records/{record_id}/files/{file_name}"
36+
url = invenio_url_for(
37+
"invenio_app_rdm_records.record_file_download",
38+
pid_value=record_id,
39+
filename=file_name,
40+
)
3641
access_url = None
3742
if "doi" in obj["pids"]:
3843
access_url = idutils.to_url(

invenio_rdm_records/resources/serializers/dublincore/schema.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
import bleach
1111
import idutils
12-
from flask import current_app
1312
from flask_resources.serializers import BaseSerializerSchema
13+
from invenio_base import invenio_url_for
1414
from marshmallow import fields, missing
1515
from pydash import py_
1616

@@ -103,7 +103,11 @@ def get_relations(self, obj):
103103
communities = obj.get("parent", {}).get("communities", {}).get("entries", [])
104104
for community in communities:
105105
slug = community["slug"]
106-
url = f"{current_app.config['SITE_UI_URL']}/communities/{slug}"
106+
url = invenio_url_for(
107+
"invenio_app_rdm_communities.communities_home",
108+
pid_value=slug,
109+
)
110+
107111
rels.append(self._transform_identifier(url, "url"))
108112

109113
# Parent doi

invenio_rdm_records/resources/serializers/marcxml/schema.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import bleach
1111
from dateutil.parser import parse
1212
from dojson.contrib.to_marc21.fields.bdleader import to_leader
13-
from flask import current_app
1413
from flask_resources.serializers import BaseSerializerSchema
14+
from invenio_base import invenio_url_for
1515
from marshmallow import fields, missing
1616
from marshmallow_utils.html import sanitize_unicode
1717
from pydash import py_
@@ -134,7 +134,12 @@ def get_files(self, obj):
134134
files = []
135135
for file_entry in files_entries.values():
136136
file_name = sanitize_unicode(file_entry["key"])
137-
url = f"{current_app.config['SITE_UI_URL']}/records/{record_id}/files/{file_name}"
137+
url = invenio_url_for(
138+
"invenio_app_rdm_records.record_file_download",
139+
pid_value=record_id,
140+
filename=file_name,
141+
)
142+
138143
file_ = {
139144
"s": str(file_entry["size"]), # file size
140145
"z": file_entry["checksum"], # check sum

invenio_rdm_records/resources/serializers/signposting/schema.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"""Signposting schemas."""
1010

1111
import idutils
12+
from invenio_base import invenio_url_for
1213
from marshmallow import Schema, fields, missing, post_dump
1314

14-
from ...urls import download_url_for
1515
from ..utils import get_vocabulary_props
1616

1717

@@ -83,7 +83,11 @@ def serialize_item(self, obj, **kwargs):
8383

8484
result = [
8585
{
86-
"href": download_url_for(pid_value=obj["id"], filename=entry["key"]),
86+
"href": invenio_url_for(
87+
"invenio_app_rdm_records.record_file_download",
88+
pid_value=obj["id"],
89+
filename=entry["key"],
90+
),
8791
"type": entry["mimetype"],
8892
}
8993
for entry in file_entries.values()
@@ -197,7 +201,11 @@ class ContentResourceSchema(Schema):
197201
def serialize_anchor(self, obj, **kwargs):
198202
"""Serialize to download url."""
199203
pid_value = self.context["record_dict"]["id"]
200-
return download_url_for(pid_value=pid_value, filename=obj["key"])
204+
return invenio_url_for(
205+
"invenio_app_rdm_records.record_file_download",
206+
pid_value=pid_value,
207+
filename=obj["key"],
208+
)
201209

202210
def serialize_collection(self, obj, **kwargs):
203211
"""Serialize to record landing page url."""

invenio_rdm_records/resources/urls.py

-70
This file was deleted.

invenio_rdm_records/services/access/service.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from flask import current_app
1717
from flask_login import current_user
1818
from invenio_access.permissions import authenticated_user, system_identity
19+
from invenio_base import invenio_url_for
1920
from invenio_drafts_resources.services.records import RecordService
2021
from invenio_drafts_resources.services.records.uow import ParentRecordCommitOp
2122
from invenio_i18n import lazy_gettext as _
@@ -729,14 +730,9 @@ def create_guest_access_request_token(
729730
)
730731

731732
# Create the URL for the email verification endpoint
732-
733-
# TODO ideally this part should be auto generated, but
734-
# due to api app and ui app split, api app does not have the UI
735-
# urls registered
736-
verify_url = (
737-
f"{current_app.config['SITE_UI_URL']}"
738-
f"/access/requests/confirm"
739-
f"?access_request_token={access_token.token}"
733+
verify_url = invenio_url_for(
734+
"invenio_app_rdm_requests.verify_access_request_token",
735+
access_request_token=access_token.token,
740736
)
741737
uow.register(
742738
NotificationOp(

invenio_rdm_records/templates/semantic-ui/invenio_notifications/community-submission.accept.jinja

+6-8
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
ui=config.SITE_UI_URL, id=request_id
1515
)
1616
%}
17-
{% set account_settings_link = "{ui}/account/settings/notifications".format(
18-
ui=config.SITE_UI_URL
19-
)
20-
%}
17+
{% set account_settings_link = invenio_url_for("invenio_notifications_settings.index") %}
18+
2119

2220
{%- block subject -%}
2321
{{ _("✅ Community inclusion accepted for '{record_title}'").format(record_title=record_title) }}
@@ -27,13 +25,13 @@
2725
<table style="font-family:'Lato',Helvetica,Arial,sans-serif;border-spacing:15px">
2826
<tr>
2927
<td>{{ _("The community curator '@{curator_name}' accepted the record '{record_title}' into the community '{community_title}'").format(curator_name=curator_name, community_title=community_title, record_title=record_title) }}
30-
{% if message %}
28+
{% if message %}
3129
{{ _(" with the following message:")}}
3230
{% endif %}
3331
</td>
3432
</tr>
3533
<tr>
36-
{% if message %}
34+
{% if message %}
3735
<td><em>{{message}}</em></td>
3836
{% endif %}
3937
</tr>
@@ -52,7 +50,7 @@
5250
{%- block plain_body -%}
5351
{{ _("The community curator @{curator_name} accepted the record '{record_title}' into the community '{community_title}'").format(curator_name=curator_name, community_title=community_title, record_title=record_title) }}
5452

55-
{% if message %}
53+
{% if message %}
5654
{{ _("with the following message:")}}
5755
{{message}}
5856
{% endif %}
@@ -66,7 +64,7 @@
6664
{%- block md_body -%}
6765
{{ _("The community curator *@{curator_name}* accepted the record *{record_title}* into the community *{community_title}*").format(curator_name=curator_name, community_title=community_title, record_title=record_title) }}
6866

69-
{% if message %}
67+
{% if message %}
7068
{{ _("with the following message:")}}
7169
{{message}}
7270
{% endif %}

invenio_rdm_records/templates/semantic-ui/invenio_notifications/community-submission.cancel.jinja

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
ui=config.SITE_UI_URL, id=request_id
1515
)
1616
%}
17-
{% set account_settings_link = "{ui}/account/settings/notifications".format(
18-
ui=config.SITE_UI_URL
19-
)
20-
%}
17+
{% set account_settings_link = invenio_url_for("invenio_notifications_settings.index") %}
2118

2219
{%- block subject -%}
2320
{{ _("❌ Community inclusion cancelled for '{record_title}'").format(record_title=record_title) }}

invenio_rdm_records/templates/semantic-ui/invenio_notifications/community-submission.decline.jinja

+5-8
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
ui=config.SITE_UI_URL, id=request_id
1515
)
1616
%}
17-
{% set account_settings_link = "{ui}/account/settings/notifications".format(
18-
ui=config.SITE_UI_URL
19-
)
20-
%}
17+
{% set account_settings_link = invenio_url_for("invenio_notifications_settings.index") %}
2118

2219
{%- block subject -%}
2320
{{ _("⛔️ Community inclusion declined for '{record_title}'").format(record_title=record_title) }}
@@ -27,13 +24,13 @@
2724
<table style="font-family:'Lato',Helvetica,Arial,sans-serif;border-spacing:15px">
2825
<tr>
2926
<td>{{ _("The community curator '@{curator_name}' declined the record '{record_title}' into the community '{community_title}'").format(curator_name=curator_name, community_title=community_title, record_title=record_title) }}
30-
{% if message %}
27+
{% if message %}
3128
{{ _(" with the following message:")}}
3229
{% endif %}
3330
</td>
3431
</tr>
3532
<tr>
36-
{% if message %}
33+
{% if message %}
3734
<td><em>{{message}}</em></td>
3835
{% endif %}
3936
</tr>
@@ -52,7 +49,7 @@
5249
{%- block plain_body -%}
5350
{{ _("The community curator @{curator_name} declined the record '{record_title}' into the community '{community_title}'").format(curator_name=curator_name, community_title=community_title, record_title=record_title) }}
5451

55-
{% if message %}
52+
{% if message %}
5653
{{ _("with the following message:")}}
5754
{{message}}
5855
{% endif %}
@@ -66,7 +63,7 @@
6663
{%- block md_body -%}
6764
{{ _("The community curator *@{curator_name}* declined the record *{record_title}* into the community *{community_title}*").format(curator_name=curator_name, community_title=community_title, record_title=record_title) }}
6865

69-
{% if message %}
66+
{% if message %}
7067
{{ _("with the following message:")}}
7168
{{message}}
7269
{% endif %}

invenio_rdm_records/templates/semantic-ui/invenio_notifications/community-submission.expire.jinja

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
ui=config.SITE_UI_URL, id=request_id
1313
)
1414
%}
15-
{% set account_settings_link = "{ui}/account/settings/notifications".format(
16-
ui=config.SITE_UI_URL
17-
)
18-
%}
15+
{% set account_settings_link = invenio_url_for("invenio_notifications_settings.index") %}
1916

2017
{%- block subject -%}
2118
{{ _("⌛️ Community inclusion expired for '{record_title}'").format(record_title=record_title) }}

0 commit comments

Comments
 (0)