allow users to stop learning from fedi accounts

This commit is contained in:
Lynne Megido 2019-09-03 11:44:54 +10:00
parent 8f476ca981
commit c25e0764fe
2 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>FediBooks</title>
{% include 'imports.html' %}
</head>
<body>
<div class="container centred">
<h1 class="thin centred">Stop learning from account</h1>
</div>
<div class="container centred">
<form method='POST'>
<div class="panel-icon large"></div>
<div class="container centred">
<p>Are you sure you want {{ bot }} to stop learning from {{ user }}?</p>
<a class="button btn-secondary" href="/"><i class="fas fa-times"></i> Cancel</a>
<button class="button btn-dangerous"><i class="fas fa-trash"></i> Stop learning</button>
</div>
</form>
</div>
{% include 'footer.html' %}
</body>
</html>

View File

@ -184,6 +184,24 @@ def bot_accounts_toggle(id):
c.close()
return redirect("/bot/accounts/{}".format(session['bot']), 303)
@app.route("/bot/accounts/delete/<id>", 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():