diff --git a/app.py b/app.py index 3445429..cda5edb 100644 --- a/app.py +++ b/app.py @@ -778,6 +778,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/models/HabitList.py b/models/HabitList.py index 0770075..b04f07c 100644 --- a/models/HabitList.py +++ b/models/HabitList.py @@ -3,7 +3,7 @@ from dataclasses import dataclass from models.Habit import Habit from models.User import User from db.SQLiteClient import (create_habitList, get_habitList, get_habits, get_users, add_user, remove_user, - update_habitList, delete_habitList, accept_List) + update_habitList, delete_habitList) @dataclass @@ -66,9 +66,6 @@ class HabitList: else: return None - def accept_List(self, user:User): - accept_List(self.id, user.id) - # Removes a User from the HabitList def remove_user(self, user_id): remove_user(self.id, user_id) diff --git a/models/User.py b/models/User.py index 22a2e3d..8df5cfb 100644 --- a/models/User.py +++ b/models/User.py @@ -2,7 +2,7 @@ from datetime import datetime from flask_login import UserMixin from db.SQLiteClient import (create_user, get_user, get_user_by_email, update_user, delete_user, - get_habitLists, get_heatmap_value) + get_habitLists, get_heatmap_value, accept_List) class User(UserMixin): @@ -75,4 +75,7 @@ class User(UserMixin): heatmap.append(value) heatmap.reverse() day = 27-weekday - return heatmap, day \ No newline at end of file + return heatmap, day + + def accept_List(self, HabitList_id): + accept_List(self.id, HabitList_id) 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 %} -
+
+ + + +
{% endif %}