Skip to content

Commit

Permalink
menu: use current_menu
Browse files Browse the repository at this point in the history
  • Loading branch information
utnapischtim authored and kpsherva committed Mar 21, 2024
1 parent dba7fa8 commit 7160892
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
29 changes: 28 additions & 1 deletion invenio_accounts/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This file is part of Invenio.
# Copyright (C) 2015-2024 CERN.
# Copyright (C) 2021 TU Wien.
# Copyright (C) 2023 Graz University of Technology.
# Copyright (C) 2023-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 @@ -16,9 +16,12 @@
from flask import Blueprint, abort, current_app, request_finished, session
from flask_kvsession import KVSessionExtension
from flask_login import LoginManager, user_logged_in, user_logged_out
from flask_menu import current_menu
from flask_principal import AnonymousIdentity
from flask_security import Security, user_confirmed
from invenio_db import db
from invenio_i18n import lazy_gettext as _
from invenio_theme.proxies import current_theme_icons
from passlib.registry import register_crypt_handler
from werkzeug.utils import cached_property

Expand Down Expand Up @@ -335,6 +338,7 @@ def finalize_app(app):
"""Finalize app."""
set_default_config(app)
check_security_settings(app)
init_menu(app)


def set_default_config(app):
Expand Down Expand Up @@ -365,3 +369,26 @@ def check_security_settings(app):
"SESSION_COOKIE_SECURE setting must be set to True to prevent the "
"session cookie from being leaked over an insecure channel."
)


def init_menu(app):
"""init menu."""
current_menu.submenu("settings.security").register(
endpoint="invenio_accounts.security",
text=_(
"%(icon)s Security", icon=f'<i class="{current_theme_icons.shield}"></i>'
),
order=2,
)

# - Register menu
# - Change password
if app.config.get("SECURITY_CHANGEABLE", True):
current_menu.submenu("settings.change_password").register(
endpoint=f"{app.config['SECURITY_BLUEPRINT_NAME']}.change_password",
text=_(
"%(icon)s Change password",
icon=f'<i class="{current_theme_icons.key}"></i>',
),
order=1,
)
19 changes: 0 additions & 19 deletions invenio_accounts/views/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
from flask import Blueprint, abort, current_app, request
from flask_security.views import anonymous_user_required
from flask_security.views import login as base_login
from invenio_i18n import lazy_gettext as _
from invenio_theme import menu

from .security import revoke_session, security

Expand Down Expand Up @@ -42,8 +40,6 @@ def create_settings_blueprint(app):
static_folder="static",
)

icons = app.extensions["invenio-theme"].icons

blueprint.add_url_rule("/login", view_func=login)

if app.config["ACCOUNTS_SESSION_ACTIVITY_ENABLED"]:
Expand All @@ -52,19 +48,4 @@ def create_settings_blueprint(app):
"/sessions/revoke", view_func=revoke_session, methods=["POST"]
)

menu.submenu("settings.security").register(
endpoint="invenio_accounts.security",
text=_("%(icon)s Security", icon=f'<i class="{icons.shield}"></i>'),
order=2,
)

# - Register menu
# - Change password
if app.config.get("SECURITY_CHANGEABLE", True):
menu.submenu("settings.change_password").register(
endpoint=f"{app.config['SECURITY_BLUEPRINT_NAME']}.change_password",
text=_("%(icon)s Change password", icon=f'<i class="{icons.key}"></i>'),
order=1,
)

return blueprint

0 comments on commit 7160892

Please sign in to comment.