From c25e0764feeeb8abd43fc161163c8accda0f05ef Mon Sep 17 00:00:00 2001 From: Lynne Date: Tue, 3 Sep 2019 11:44:54 +1000 Subject: [PATCH] allow users to stop learning from fedi accounts --- templates/bot_accounts_delete.html | 27 +++++++++++++++++++++++++++ webui.py | 18 ++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 templates/bot_accounts_delete.html diff --git a/templates/bot_accounts_delete.html b/templates/bot_accounts_delete.html new file mode 100644 index 0000000..609d5bd --- /dev/null +++ b/templates/bot_accounts_delete.html @@ -0,0 +1,27 @@ + + + + + FediBooks + {% include 'imports.html' %} + + + +
+

Stop learning from account

+
+ +
+
+
+
+

Are you sure you want {{ bot }} to stop learning from {{ user }}?

+ Cancel + +
+
+
+ + {% include 'footer.html' %} + + diff --git a/webui.py b/webui.py index 6897ad9..95d089f 100644 --- a/webui.py +++ b/webui.py @@ -184,6 +184,24 @@ def bot_accounts_toggle(id): c.close() return redirect("/bot/accounts/{}".format(session['bot']), 303) +@app.route("/bot/accounts/delete/", methods=['GET', 'POST']) +def bot_accounts_delete(id): + if request.method == 'GET': + instance = id.split("@")[2] + return render_template("bot_accounts_delete.html", user = id, instance = instance) + else: + #NOTE: when user credential support is added, we'll need to delete the creds too + c = mysql.connection.cursor() + c.execute("DELETE FROM `bot_learned_accounts` WHERE `fedi_id` = %s AND bot_id = %s", (id, session['bot'])) + # check to see if anyone else is learning from this account + c.execute("SELECT COUNT(*) FROM `bot_learned_accounts` WHERE `fedi_id` = %s", (id,)) + if c.fetchone()[0] == 0: + # nobody else learns from this account, remove it from the db + c.execute("DELETE FROM `fedi_accounts` WHERE `handle` = %s", (id,)) + c.close() + mysql.connection.commit() + + return redirect(url_for("/bot/accounts/{}".format(session['bot'])), 303) @app.route("/bot/create/", methods=['GET', 'POST']) def bot_create():