From ba580db6b07d6fcb4877259f13052ddee34afb90 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 27 Sep 2022 11:03:55 +0200 Subject: [proxy] make some (possibly confusing) web UI parts only display to advanced users --- src/hydrilla/proxy/web_ui/items.py | 1 - src/hydrilla/proxy/web_ui/options.py | 10 +-- src/hydrilla/proxy/web_ui/root.py | 6 +- .../proxy/web_ui/templates/base.html.jinja | 21 +++-- .../templates/items/item_viewversion.html.jinja | 91 ++++++++++------------ .../templates/items/library_viewversion.html.jinja | 32 ++++---- .../templates/items/package_viewversion.html.jinja | 38 ++++----- .../proxy/web_ui/templates/options.html.jinja | 26 +++++++ .../web_ui/templates/repos/show_single.html.jinja | 21 +++-- 9 files changed, 135 insertions(+), 111 deletions(-) (limited to 'src/hydrilla/proxy/web_ui') diff --git a/src/hydrilla/proxy/web_ui/items.py b/src/hydrilla/proxy/web_ui/items.py index ec394ee..6195107 100644 --- a/src/hydrilla/proxy/web_ui/items.py +++ b/src/hydrilla/proxy/web_ui/items.py @@ -177,7 +177,6 @@ def show_item_version( f'items/{item_type.alt_name}_viewversion.html.jinja', display_info = display_info, version_display_info = this_info, - settings = state.get_settings(), **errors ) return flask.make_response(html, 200) diff --git a/src/hydrilla/proxy/web_ui/options.py b/src/hydrilla/proxy/web_ui/options.py index 9be1ae0..7d59375 100644 --- a/src/hydrilla/proxy/web_ui/options.py +++ b/src/hydrilla/proxy/web_ui/options.py @@ -41,11 +41,7 @@ bp = flask.Blueprint('options', __package__) @bp.route('/options', methods=['GET']) def options(errors: t.Mapping[str, bool] = {}) -> werkzeug.Response: - html = flask.render_template( - 'options.html.jinja', - settings = _app.get_haketilo_state().get_settings(), - **errors - ) + html = flask.render_template('options.html.jinja', **errors) return flask.make_response(html, 200) @bp.route('/options', methods=['POST']) @@ -64,6 +60,10 @@ def options_post() -> werkzeug.Response: state.update_settings(default_allow_scripts=True) elif action == 'block_scripts': state.update_settings(default_allow_scripts=False) + elif action == 'user_make_advanced': + state.update_settings(advanced_user=True) + elif action == 'user_make_simple': + state.update_settings(advanced_user=False) else: raise ValueError() diff --git a/src/hydrilla/proxy/web_ui/root.py b/src/hydrilla/proxy/web_ui/root.py index ed030d2..21c491b 100644 --- a/src/hydrilla/proxy/web_ui/root.py +++ b/src/hydrilla/proxy/web_ui/root.py @@ -64,11 +64,14 @@ def authenticate_by_referrer() -> t.Optional[werkzeug.Response]: flask.abort(403) -def get_current_endpoint() -> t.Optional[str]: +def get_current_endpoint() -> str: endpoint = flask.request.endpoint assert endpoint is not None return endpoint +def get_settings() -> st.HaketiloGlobalSettings: + return _app.get_haketilo_state().get_settings() + class WebUIAppImpl(_app.WebUIApp): def __init__(self): @@ -87,6 +90,7 @@ class WebUIAppImpl(_app.WebUIApp): } self.jinja_env.globals['get_current_endpoint'] = get_current_endpoint + self.jinja_env.globals['get_settings'] = get_settings self.jinja_env.globals['EnabledStatus'] = st.EnabledStatus self.jinja_env.globals['FrozenStatus'] = st.FrozenStatus self.jinja_env.globals['InstalledStatus'] = st.InstalledStatus diff --git a/src/hydrilla/proxy/web_ui/templates/base.html.jinja b/src/hydrilla/proxy/web_ui/templates/base.html.jinja index ff9fd71..493398a 100644 --- a/src/hydrilla/proxy/web_ui/templates/base.html.jinja +++ b/src/hydrilla/proxy/web_ui/templates/base.html.jinja @@ -20,6 +20,8 @@ code in a proprietary work, I am not going to enforce this in court. -#} +{% set settings = get_settings() %} + {% macro button_row(buttons_data, common_fields={}) %}
{% for classes, text, extra_fields in buttons_data %} @@ -236,17 +238,20 @@ code in a proprietary work, I am not going to enforce this in court. {% set active_endpoint = get_current_endpoint() %} {% set navigation_bar = [ - ('home', _('web_ui.base.nav.home')), - ('options.options', _('web_ui.base.nav.options')), - ('rules.rules', _('web_ui.base.nav.rules')), - ('items.packages', _('web_ui.base.nav.packages')), - ('items.libraries', _('web_ui.base.nav.libraries')), - ('repos.repos', _('web_ui.base.nav.repos')), - ('items.load_from_disk', _('web_ui.base.nav.load')) + ('home', _('web_ui.base.nav.home'), false), + ('options.options', _('web_ui.base.nav.options'), false), + ('rules.rules', _('web_ui.base.nav.rules'), false), + ('items.packages', _('web_ui.base.nav.packages'), false), + ('items.libraries', _('web_ui.base.nav.libraries'), true), + ('repos.repos', _('web_ui.base.nav.repos'), false), + ('items.load_from_disk', _('web_ui.base.nav.load'), false) ] %}