Skip to content

Commit

Permalink
fix: before_app_first_request deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
utnapischtim committed Mar 19, 2024
1 parent 5e6b665 commit 0a226d0
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 74 deletions.
73 changes: 73 additions & 0 deletions invenio_oauthclient/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This file is part of Invenio.
# Copyright (C) 2015-2018 CERN.
# Copyright (C) 2024 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.
Expand All @@ -10,6 +11,7 @@

import warnings

from flask import request
from flask_login import user_logged_out
from flask_principal import identity_loaded

Expand Down Expand Up @@ -205,3 +207,74 @@ def init_app(self, app):

app.extensions["invenio-oauthclient"] = state
return state


def finalize_app(app):
"""Finalize app."""
override_template_configuration(app)
init_index_menu(app)
post_ext_init(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",
)


def init_index_menu(app):
"""Init index menu."""
menu = app.extensions["menu"]

def active_when():
return request.endpoint.startswith("invenio_oauthclient_settings.")

def visible_when():
return bool(app.config.get("OAUTHCLIENT_REMOTE_APPS")) is not False

menu.submenu("settings.oauthclient").register(
"invenio_oauthclient_settings.index",
_(
"%(icon)s Linked accounts",
icon=make_lazy_string(
lambda: f'<i class="{current_theme_icons.link}"></i>'
),
),
order=3,
active_when=active_when,
visible_when=visible_when,
)

menu.submenu("breadcrumbs.settings.oauthclient").register(
"invenio_oauthclient_settings.index",
_("Linked accounts"),
)


def post_ext_init(app):
"""Setup blueprint."""
app.config.setdefault(
"OAUTHCLIENT_SITENAME",
app.config.get("THEME_SITENAME", "Invenio"),
)
app.config.setdefault(
"OAUTHCLIENT_BASE_TEMPLATE",
app.config.get("BASE_TEMPLATE", "invenio_oauthclient/base.html"),
)
app.config.setdefault(
"OAUTHCLIENT_COVER_TEMPLATE",
app.config.get("COVER_TEMPLATE", "invenio_oauthclient/base_cover.html"),
)
app.config.setdefault(
"OAUTHCLIENT_SETTINGS_TEMPLATE",
app.config.get("SETTINGS_TEMPLATE", "invenio_oauthclient/settings/base.html"),
)
30 changes: 0 additions & 30 deletions invenio_oauthclient/finalize_app.py

This file was deleted.

22 changes: 0 additions & 22 deletions invenio_oauthclient/views/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,6 @@
)


@blueprint.record_once
def post_ext_init(state):
"""Setup blueprint."""
app = state.app

app.config.setdefault(
"OAUTHCLIENT_SITENAME", app.config.get("THEME_SITENAME", "Invenio")
)
app.config.setdefault(
"OAUTHCLIENT_BASE_TEMPLATE",
app.config.get("BASE_TEMPLATE", "invenio_oauthclient/base.html"),
)
app.config.setdefault(
"OAUTHCLIENT_COVER_TEMPLATE",
app.config.get("COVER_TEMPLATE", "invenio_oauthclient/base_cover.html"),
)
app.config.setdefault(
"OAUTHCLIENT_SETTINGS_TEMPLATE",
app.config.get("SETTINGS_TEMPLATE", "invenio_oauthclient/settings/base.html"),
)


@blueprint.route("/login")
def auto_redirect_login(*args, **kwargs):
"""Handles automatic redirect to external auth service.
Expand Down
23 changes: 2 additions & 21 deletions invenio_oauthclient/views/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This file is part of Invenio.
# Copyright (C) 2015-2018 CERN.
# Copyright (C) 2024 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.
Expand All @@ -10,13 +11,8 @@

from operator import itemgetter

from flask import Blueprint, current_app, render_template, request
from flask_breadcrumbs import register_breadcrumb
from flask import Blueprint, current_app, render_template
from flask_login import current_user, login_required
from flask_menu import register_menu
from invenio_i18n import lazy_gettext as _
from invenio_theme.proxies import current_theme_icons
from speaklater import make_lazy_string

from ..models import RemoteAccount
from ..proxies import current_oauthclient
Expand All @@ -32,21 +28,6 @@

@blueprint.route("/", methods=["GET", "POST"])
@login_required
@register_menu(
blueprint,
"settings.oauthclient",
_(
"%(icon)s Linked accounts",
icon=make_lazy_string(lambda: f'<i class="{current_theme_icons.link}"></i>'),
),
order=3,
active_when=lambda: request.endpoint.startswith("invenio_oauthclient_settings."),
visible_when=lambda: bool(current_app.config.get("OAUTHCLIENT_REMOTE_APPS"))
is not False,
)
@register_breadcrumb(
blueprint, "breadcrumbs.settings.oauthclient", _("Linked accounts")
)
def index():
"""List linked accounts."""
oauth = current_oauthclient.oauth
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ invenio_base.secret_key =
invenio_i18n.translations =
invenio_oauthclient = invenio_oauthclient
invenio_base.finalize_app =
invenio_oauthclient = invenio_oauthclient.finalize_app:finalize_app
invenio_oauthclient = invenio_oauthclient.ext:finalize_app

[build_sphinx]
source-dir = docs/
Expand Down

0 comments on commit 0a226d0

Please sign in to comment.