Skip to content

Commit

Permalink
Add get_endpoints function and fix itemlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
UlrichB22 committed Jul 1, 2024
1 parent b0f9354 commit 62f70be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/moin/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from moin.utils import monkeypatch # noqa
from moin.utils.clock import Clock
from moin import auth, user, config
from moin.constants.misc import ANON
from moin.constants.misc import ANON, VALID_ITEMLINK_VIEWS
from moin.i18n import i18n_init
from moin.themes import setup_jinja_env, themed_error
from moin.storage.middleware import protecting, indexing, routing
Expand Down Expand Up @@ -156,6 +156,8 @@ class ItemNameConverter(PathConverter):
from moin.apps.serve import serve

app.register_blueprint(serve, url_prefix="/+serve")

app.view_endpoints = get_endpoints(app)
clock.stop("create_app register")
clock.start("create_app flask-cache")
# 'SimpleCache' caching uses a dict and is not thread safe according to the docs.
Expand Down Expand Up @@ -191,6 +193,16 @@ class ItemNameConverter(PathConverter):
return app


def get_endpoints(app):
"""Get dict with views and related endpoints allowed as itemlink"""
view_endpoints = {}
for rule in app.url_map.iter_rules():
view = rule.rule.split("/")[1]
if view in VALID_ITEMLINK_VIEWS and rule.rule == f"/{view}/<itemname:item_name>":
view_endpoints[view] = rule.endpoint
return view_endpoints


def destroy_app(app):
deinit_backends(app)

Expand Down
6 changes: 4 additions & 2 deletions src/moin/converters/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
special wiki links.
"""

from flask import current_app as app
from flask import g as flaskg

from moin.constants.misc import VALID_ITEMLINK_VIEWS
Expand Down Expand Up @@ -202,8 +203,9 @@ def handle_wikilocal_links(self, elem, input, page, to_tag=ConverterBase._tag_xl
item_name = str(page.path[1:]) if page else ""
endpoint, rev, query = self._get_do_rev(input.query)

if view_name == "+meta": # TODO: add other views
endpoint = "frontend.show_item_meta"
if view_name in app.view_endpoints.keys():
# Other views will be shown with class moin-nonexistent as non-existent links
endpoint = app.view_endpoints[view_name]

url = url_for_item(item_name, rev=rev, endpoint=endpoint)
if not page:
Expand Down

0 comments on commit 62f70be

Please sign in to comment.