Skip to content

Commit

Permalink
communities: config: Update static page URLs to prevent name collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshamarora1 authored and slint committed Nov 19, 2024
1 parent 140ad4e commit 60e0ed1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
6 changes: 4 additions & 2 deletions invenio_communities/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

COMMUNITIES_ROUTES = {
"frontpage": "/communities",
"search": "/communities/search",
"new": "/communities/new",
"search": "/communities-search",
"deprecated_search": "/communities/search",
"new": "/communities-new",
"deprecated_new": "/communities/new",
"upload": "/communities/<pid_value>/upload",
"settings": "/communities/<pid_value>/settings",
"requests": "/communities/<pid_value>/requests",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<h1 class="ui large header m-0">{{_("Communities")}}</h1>

{% if permissions.can_create %}
<a class="ui button positive left labeled icon m-0" href="/communities/new">
<a class="ui button positive left labeled icon m-0" href="{{ config.COMMUNITIES_ROUTES['new'] }}">
<i class="plus icon" aria-hidden="true"></i>
{{ _('New community') }}
</a>
Expand Down
20 changes: 20 additions & 0 deletions invenio_communities/views/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""Decorators."""

from functools import wraps
from warnings import warn

from flask import g, request

Expand Down Expand Up @@ -39,3 +40,22 @@ def view(**kwargs):
return view

return decorator


def warn_deprecation(deprecated_route, new_route):
"""Decorator to log warnings for deprecated routes."""

def decorator(f):
@wraps(f)
def view(**kwargs):
warn(
f"The '{deprecated_route}' route is deprecated and will be removed in future releases. "
f"Please update to use '{new_route}' instead. If you want to keep using the old endpoint, then you can set up redirection separately.",
DeprecationWarning,
stacklevel=2,
)
return f(**kwargs)

return view

return decorator
18 changes: 18 additions & 0 deletions invenio_communities/views/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
invitations,
members,
)
from .decorators import warn_deprecation


#
Expand Down Expand Up @@ -149,11 +150,28 @@ def create_ui_blueprint(app):
strict_slashes=False,
)

blueprint.add_url_rule(
routes["deprecated_search"],
endpoint="deprecated_communities_search",
view_func=warn_deprecation(routes["deprecated_search"], routes["search"])(
communities_search
),
strict_slashes=False,
)

blueprint.add_url_rule(
routes["new"],
view_func=communities_new,
)

blueprint.add_url_rule(
routes["deprecated_new"],
endpoint="deprecated_communities_new",
view_func=warn_deprecation(routes["deprecated_new"], routes["new"])(
communities_new
),
)

blueprint.add_url_rule(
routes["about"],
view_func=communities_about,
Expand Down

0 comments on commit 60e0ed1

Please sign in to comment.