Skip to content
Snippets Groups Projects
Commit 6b0109cc authored by Jan Mach's avatar Jan Mach
Browse files

Added ability to disable specific Hawat application endpoints.

This feature can be very usefull for turning off certain unwanted application or module features. For example one might want to use some kind of module implementing password authentication, but block the account registration endpoint provided by that module. (Redmine issue: #4781)
parent 9c6f9419
No related branches found
No related tags found
No related merge requests found
......@@ -67,6 +67,7 @@ import sqlalchemy
import werkzeug.routing
import werkzeug.utils
import flask
import flask.app
import flask.views
import flask_login
from flask_babel import gettext
......@@ -215,6 +216,24 @@ class HawatApp(flask.Flask):
self.view_classes.update(blueprint.view_classes)
@flask.app.setupmethod
def add_url_rule(self, rule, endpoint = None, view_func = None, provide_automatic_options = None, **options):
"""
Reimplementation of :py:func:`flask.Flask.add_url_rule` method. This
method will is capable of disabling selected application endpoints. Keep
in mind, that endpoint for application global 'static' is created during
the __init__ method and cannot be disabled, because at that point the
configuration is not yet loaded.
"""
if self.config.get('DISABLED_ENDPOINTS', None) and self.config['DISABLED_ENDPOINTS'] and endpoint:
if endpoint in self.config['DISABLED_ENDPOINTS']:
self.logger.warning(
"Application endpoint '%s' is disabled by configuration.",
endpoint
)
return
super().add_url_rule(rule, endpoint, view_func, provide_automatic_options, **options)
def register_blueprints(self):
"""
Register all configured application blueprints. The configuration comes
......
......@@ -134,6 +134,9 @@ class Config: # pylint: disable=locally-disabled,too-few-public-methods
]
"""List of requested application blueprints to be loaded during setup."""
DISABLED_ENDPOINTS = []
"""List of endpoints disabled on application level."""
HAWAT_LOGIN_VIEW = 'auth_env.login'
"""Default login view."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment