diff --git a/app.py b/app.py index 8ddb275..69489ef 100644 --- a/app.py +++ b/app.py @@ -777,6 +777,24 @@ def add_user(): return redirect(url_for('index', habit_list=habit_list.id)) +@app.route('/users-leave') +@login_required +def user_leave(): + list_id = request.args.get('habit_list') + + habit_list = HabitList.get(list_id) + + if habit_list is None: + return {"error": "List not found"} + + # Check if habit belongs to user + if current_user not in habit_list.get_users(): + return {"error": "List does not belong to user"} + + habit_list.remove_user(current_user.id) + return redirect(url_for("index")) + + # Run the application if __name__ == '__main__': app.run(host="0.0.0.0", port=5000, debug=True) diff --git a/templates/components/habit_lists.html b/templates/components/habit_lists.html index 99c722c..bddfd67 100644 --- a/templates/components/habit_lists.html +++ b/templates/components/habit_lists.html @@ -115,7 +115,12 @@ {% endif %} {% else %} -
+