From baec179b5a2627a34cf3418680a25cb44f6bb423 Mon Sep 17 00:00:00 2001 From: Cassidy Symons Date: Thu, 28 Sep 2023 16:00:37 -0700 Subject: [PATCH] Add perk fulfillment toggle to Admin UI --- microsetta_interface/implementation.py | 30 +++++++++++++++++++ microsetta_interface/routes.yaml | 30 +++++++++++++++++++ .../admin_perk_fulfillment_state.jinja2 | 14 +++++++++ .../templates/sitebase.jinja2 | 5 ++-- 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 microsetta_interface/templates/admin_perk_fulfillment_state.jinja2 diff --git a/microsetta_interface/implementation.py b/microsetta_interface/implementation.py index 8ef6e1e9..e76918fe 100644 --- a/microsetta_interface/implementation.py +++ b/microsetta_interface/implementation.py @@ -2689,6 +2689,36 @@ def post_account_delete(body): return get_rootpath() +def get_perk_fulfillment_state(): + if not session.get(ADMIN_MODE_KEY, False): + raise Unauthorized() + + do_return, diagnostics, _ = ApiRequest.get( + '/admin/perk_fulfillment_state' + ) + if do_return: + return diagnostics + + pf_state = diagnostics['pf_state'] + + return _render_with_defaults('admin_perk_fulfillment_state.jinja2', + pf_state=pf_state) + + +def update_perk_fulfillment_state(perk_fulfillment_state): + if not session.get(ADMIN_MODE_KEY, False): + raise Unauthorized() + + do_return, diagnostics, _ = ApiRequest.put( + '/admin/perk_fulfillment_state?perk_fulfillment_state=%s' % ( + perk_fulfillment_state,) + ) + if do_return: + return diagnostics + + return get_perk_fulfillment_state() + + def get_interested_users(email=None): if not session.get(ADMIN_MODE_KEY, False): raise Unauthorized() diff --git a/microsetta_interface/routes.yaml b/microsetta_interface/routes.yaml index 91c98c8a..1bce82df 100644 --- a/microsetta_interface/routes.yaml +++ b/microsetta_interface/routes.yaml @@ -1038,6 +1038,36 @@ paths: schema: type: string + '/admin/perk_fulfillment_state': + get: + operationId: microsetta_interface.implementation.get_perk_fulfillment_state + tags: + - Admin + responses: + '200': + description: Current state of whether perk fulfillment tasks are running + content: + text/html: + schema: + type: string + post: + operationId: microsetta_interface.implementation.update_perk_fulfillment_state + tags: + - Admin + parameters: + - in: query + name: perk_fulfillment_state + description: New state of perk fulfillment tasks + schema: + type: boolean + responses: + '200': + description: Updated state of whether perk fulfillment tasks are running + content: + text/html: + schema: + type: string + '/admin/interested_users': get: operationId: microsetta_interface.implementation.get_interested_users diff --git a/microsetta_interface/templates/admin_perk_fulfillment_state.jinja2 b/microsetta_interface/templates/admin_perk_fulfillment_state.jinja2 new file mode 100644 index 00000000..4fa5cb45 --- /dev/null +++ b/microsetta_interface/templates/admin_perk_fulfillment_state.jinja2 @@ -0,0 +1,14 @@ +{% extends "sitebase.jinja2" %} +{% set page_title = _("Perk Fulfillment State") %} +{% set show_breadcrumbs = False %} +{% block content %} +
+ Current state of perk_fulfillment_active setting: {{ pf_state }} + +
+ +
+ +
+
+{% endblock %} diff --git a/microsetta_interface/templates/sitebase.jinja2 b/microsetta_interface/templates/sitebase.jinja2 index bd96202d..8bba799b 100644 --- a/microsetta_interface/templates/sitebase.jinja2 +++ b/microsetta_interface/templates/sitebase.jinja2 @@ -119,9 +119,10 @@ {% if admin_mode %}