fix: added a work-around to the issue of regex converter not loaded.

frappe app doesn't load all python modules of all the apps on startup. It
loads the hooks.py only if it is not already cached. Because of this the code
to install the regex coverter to not running, causing errors.

Fixed it by replacing the regex route with a string route. The issue is it
also matches the paths like `socket.io` and `website_script.js` etc. Handled
that by whitelisting those routes.
This commit is contained in:
Anand Chitipothu
2021-04-07 12:41:17 +05:30
parent f1508033a3
commit b8b7673985
2 changed files with 7 additions and 7 deletions

View File

@@ -3,8 +3,5 @@ from __future__ import unicode_literals
__version__ = '0.0.1'
from .routing import install_regex_converter
install_regex_converter()
# load the methods from the lms api
from .lms import api # noqa

View File

@@ -129,9 +129,7 @@ scheduler_events = {
# Add all simple route rules here
primary_rules = [
{"from_route": "/sketches", "to_route": "sketches"},
{"from_route": "/sketches/<sketch>", "to_route": "sketches/sketch"},
{"from_route": "/courses", "to_route": "courses"},
{"from_route": "/courses/<course>", "to_route": "courses/course"},
{"from_route": "/courses/<course>/<topic>", "to_route": "courses/topic"},
{"from_route": "/courses/<course>/<topic>", "to_route": "courses/topic"}
@@ -142,13 +140,18 @@ whitelist = [
"/login",
"/update-password",
"/update-profile",
"/third-party-apps"
"/third-party-apps",
"/website_script.js",
"/courses",
"/sketches",
"/admin",
"/socket.io",
]
whitelist_rules = [{"from_route": p, "to_route": p[1:]} for p in whitelist]
# regex rule to match all profiles
profile_rules = [
{"from_route": "/<regex('[a-z0-9-]{5,}'):username>", "to_route": "profiles/profile"},
{"from_route": "/<string(minlength=5):username>", "to_route": "profiles/profile"},
]
website_route_rules = primary_rules + whitelist_rules + profile_rules