Skip to content

Commit

Permalink
fix: before_first_request deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
utnapischtim committed Mar 19, 2024
1 parent 986e9ec commit 5e6b665
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
19 changes: 0 additions & 19 deletions invenio_oauthclient/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ def __init__(self, app=None):

def init_app(self, app):
"""Flask application initialization."""
self.init_config(app)
state = _OAuthClientState(
app,
"OAUTHCLIENT_REMOTE_APPS",
Expand All @@ -179,24 +178,6 @@ def init_app(self, app):
app.extensions["invenio-oauthclient"] = state
return state

def init_config(self, app):
"""Initialize configuration."""

@app.before_first_request
def override_template_configuration():
"""Override template configuration."""
template_key = app.config.get(
"OAUTHCLIENT_TEMPLATE_KEY",
"SECURITY_LOGIN_USER_TEMPLATE", # default template key
)
if template_key is not None:
template = app.config[template_key] # keep the old value
app.config["OAUTHCLIENT_LOGIN_USER_TEMPLATE_PARENT"] = template
app.config[template_key] = app.config.get(
"OAUTHCLIENT_LOGIN_USER_TEMPLATE",
"invenio_oauthclient/login_user.html",
)


class InvenioOAuthClientREST(object):
"""Invenio Oauthclient extension."""
Expand Down
30 changes: 30 additions & 0 deletions invenio_oauthclient/finalize_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2023 Graz University of Technology.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Finalize app."""


def finalize_app(app):
"""Finalize app."""

override_template_configuration(app)


def override_template_configuration(app):
"""Override template configuration."""
template_key = app.config.get(
"OAUTHCLIENT_TEMPLATE_KEY",
"SECURITY_LOGIN_USER_TEMPLATE", # default template key
)
if template_key is not None:
template = app.config[template_key] # keep the old value
app.config["OAUTHCLIENT_LOGIN_USER_TEMPLATE_PARENT"] = template
app.config[template_key] = app.config.get(
"OAUTHCLIENT_LOGIN_USER_TEMPLATE",
"invenio_oauthclient/login_user.html",
)
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ invenio_base.secret_key =
invenio_oauthclient = invenio_oauthclient.utils:rebuild_access_tokens
invenio_i18n.translations =
invenio_oauthclient = invenio_oauthclient
invenio_base.finalize_app =
invenio_oauthclient = invenio_oauthclient.finalize_app:finalize_app

[build_sphinx]
source-dir = docs/
Expand Down

0 comments on commit 5e6b665

Please sign in to comment.