aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/proxy/web_ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/hydrilla/proxy/web_ui')
-rw-r--r--src/hydrilla/proxy/web_ui/items.py6
-rw-r--r--src/hydrilla/proxy/web_ui/prompts.py115
-rw-r--r--src/hydrilla/proxy/web_ui/root.py3
-rw-r--r--src/hydrilla/proxy/web_ui/templates/prompts/auto_install_error.html.jinja60
4 files changed, 183 insertions, 1 deletions
diff --git a/src/hydrilla/proxy/web_ui/items.py b/src/hydrilla/proxy/web_ui/items.py
index 1a56d7d..a7e497b 100644
--- a/src/hydrilla/proxy/web_ui/items.py
+++ b/src/hydrilla/proxy/web_ui/items.py
@@ -238,6 +238,12 @@ def alter_item_version(item_version_id: str, item_type: item_infos.ItemType) \
return show_item_version(item_version_id, item_type)
else:
raise ValueError()
+ except st.RepoCommunicationError:
+ return show_item_version(
+ item_version_id = item_version_id,
+ item_type = item_type,
+ errors = {'repo_communication_error': True}
+ )
except st.FileInstallationError:
return show_item_version(
item_version_id = item_version_id,
diff --git a/src/hydrilla/proxy/web_ui/prompts.py b/src/hydrilla/proxy/web_ui/prompts.py
new file mode 100644
index 0000000..b546e47
--- /dev/null
+++ b/src/hydrilla/proxy/web_ui/prompts.py
@@ -0,0 +1,115 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# Proxy web UI pages that may be shown to the user without manual navigation to
+# Haketilo meta-site.
+#
+# This file is part of Hydrilla&Haketilo.
+#
+# Copyright (C) 2022 Wojtek Kosior
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+#
+# I, Wojtek Kosior, thereby promise not to sue for violation of this
+# file's license. Although I request that you do not make use this code
+# in a proprietary program, I am not going to enforce this in court.
+
+# Enable using with Python 3.7.
+from __future__ import annotations
+
+import typing as t
+
+from urllib.parse import urlencode
+
+from itsdangerous.url_safe import URLSafeSerializer
+import flask
+import werkzeug
+
+from .. import state as st
+from . import _app
+
+
+bp = flask.Blueprint('prompts', __package__)
+
+@bp.route('/auto_install_error', methods=['GET'])
+def auto_install_error_prompt() -> werkzeug.Response:
+ state = _app.get_haketilo_state()
+
+ serializer = URLSafeSerializer(
+ state.get_secret(),
+ salt = 'auto_install_error'
+ )
+
+ try:
+ details: t.Mapping[str, str] = \
+ serializer.loads(flask.request.args['details'])
+ except:
+ return flask.redirect(flask.url_for('home'))
+
+ try:
+ payload_ref = state.payload_store().get(details['payload_id'])
+
+ display_info = payload_ref.get_display_info()
+
+ html = flask.render_template(
+ 'prompts/auto_install_error.html.jinja',
+ display_info = display_info,
+ next_url = details['next_url']
+ )
+ return flask.make_response(html, 200)
+ except st.MissingItemError:
+ flask.abort(404)
+
+@bp.route('/auto_install_error', methods=['POST'])
+def auto_install_error_prompt_post() -> werkzeug.Response:
+ form_data = flask.request.form
+ action = form_data['action']
+
+ mapping_ver_id = str(int(form_data['mapping_ver_id']))
+ payload_id = str(int(form_data['payload_id']))
+ next_url = form_data['next_url']
+
+ state = _app.get_haketilo_state()
+
+ try:
+ mapping_ver_store = state.mapping_version_store()
+ mapping_ver_ref = mapping_ver_store.get(mapping_ver_id)
+
+ payload_store = _app.get_haketilo_state().payload_store()
+ payload_ref = payload_store.get(payload_id)
+
+ if action == 'disable_mapping':
+ mapping_ver_ref.update_mapping_status(st.EnabledStatus.DISABLED)
+ elif action == 'retry_install':
+ payload_ref.ensure_items_installed()
+ else:
+ raise ValueError()
+ except (st.RepoCommunicationError, st.FileInstallationError):
+ params = {'payload_id': payload_id, 'next_url': next_url}
+
+ serializer = URLSafeSerializer(
+ state.get_secret(),
+ salt = 'auto_install_error'
+ )
+ query = urlencode({'details': params})
+ redirect_url = flask.url_for(
+ '.auto_install_error_prompt',
+ details = serializer.dumps(params)
+ )
+
+ return flask.redirect(redirect_url)
+ except st.MissingItemError:
+ flask.abort(404)
+
+ return flask.redirect(next_url)
diff --git a/src/hydrilla/proxy/web_ui/root.py b/src/hydrilla/proxy/web_ui/root.py
index eac3be7..ff7c1f7 100644
--- a/src/hydrilla/proxy/web_ui/root.py
+++ b/src/hydrilla/proxy/web_ui/root.py
@@ -46,6 +46,7 @@ from .. import state as st
from .. import http_messages
from . import repos
from . import items
+from . import prompts
from . import _app
@@ -91,7 +92,7 @@ class WebUIAppImpl(_app.WebUIApp):
self.before_request(authenticate_by_referrer)
- for blueprint in [repos.bp, items.bp]:
+ for blueprint in [repos.bp, items.bp, prompts.bp]:
self.register_blueprint(blueprint)
# Flask app is not thread-safe and has to be accompanied by an ugly lock. This
diff --git a/src/hydrilla/proxy/web_ui/templates/prompts/auto_install_error.html.jinja b/src/hydrilla/proxy/web_ui/templates/prompts/auto_install_error.html.jinja
new file mode 100644
index 0000000..01f5c19
--- /dev/null
+++ b/src/hydrilla/proxy/web_ui/templates/prompts/auto_install_error.html.jinja
@@ -0,0 +1,60 @@
+{#
+SPDX-License-Identifier: GPL-3.0-or-later OR CC-BY-SA-4.0
+
+Proxy web UI page that informs about failure of automatic package installation.
+
+This file is part of Hydrilla&Haketilo.
+
+Copyright (C) 2022 Wojtek Kosior
+
+Dual licensed under
+* GNU General Public License v3.0 or later and
+* Creative Commons Attribution Share Alike 4.0 International.
+
+You can choose to use either of these licenses or both.
+
+
+I, Wojtek Kosior, thereby promise not to sue for violation of this
+file's licenses. Although I request that you do not make use this code
+in a proprietary work, I am not going to enforce this in court.
+#}
+{% extends "base.html.jinja" %}
+
+{% block title %}
+ {{ _('web_ui.prompts.auto_install_error.title') }}
+{% endblock %}
+
+{% macro button_form(action, button_class, button_text) %}
+ <form class="flex-row" method="POST">
+ <input name="next_url" value="{{ next_url }}" type="hidden">
+ <input name="payload_id" value="{{ display_info.ref.id }}" type="hidden">
+ {% set mapping_ver_id = display_info.mapping_info.ref.id %}
+ <input name="mapping_ver_id" value="{{ mapping_ver_id }}" type="hidden">
+
+ <input name="action" value="{{ action }}" type="hidden">
+ <button class="{{ button_class }}">{{ button_text }}</button>
+ </form>
+{% endmacro %}
+
+{% block main %}
+ <h3>
+ {{ _('web_ui.prompts.auto_install_error.heading') }}
+ </h3>
+
+ <p>
+ {{
+ _('web_ui.prompts.auto_install_error.package_{}_failed_to_install')
+ .format(display_info.mapping_info.info.long_name)
+ }}
+ </p>
+
+ <div class="flex-row">
+ {% set but_text = _('web_ui.prompts.auto_install_error.disable_button') %}
+ {{ button_form('disable_mapping', 'red-button', but_text) }}
+
+ <div class="button-row-separator"></div>
+
+ {% set but_text = _('web_ui.prompts.auto_install_error.retry_button') %}
+ {{ button_form('retry_install', 'green-button', but_text) }}
+ </div>
+{% endblock %}