aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/proxy/web_ui/prompts.py
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-09-08 17:59:40 +0200
committerWojtek Kosior <koszko@koszko.org>2022-09-28 14:03:18 +0200
commit45e5cf8dc3ca936e2db8e7e45689d0a3331aad43 (patch)
tree83f0b13f0fbb6d29862ac91ac0597e1c5c64719e /src/hydrilla/proxy/web_ui/prompts.py
parent04853ff19450c5925a7c9bacc11abe90e75f8510 (diff)
downloadhaketilo-hydrilla-45e5cf8dc3ca936e2db8e7e45689d0a3331aad43.tar.gz
haketilo-hydrilla-45e5cf8dc3ca936e2db8e7e45689d0a3331aad43.zip
[proxy] make package auto-installation work
Diffstat (limited to 'src/hydrilla/proxy/web_ui/prompts.py')
-rw-r--r--src/hydrilla/proxy/web_ui/prompts.py115
1 files changed, 115 insertions, 0 deletions
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)