From b8bd5bdeba2433fb66fba7deaad2a9a393706b99 Mon Sep 17 00:00:00 2001 From: Luke Watts Date: Sun, 19 Oct 2025 15:23:22 +0200 Subject: [PATCH] feat: drop stale checkout user notification --- src/aggregator/logic.py | 11 ------ src/aggregator/logic_tests.py | 74 ----------------------------------- src/aggregator/messages.py | 27 ------------- 3 files changed, 112 deletions(-) diff --git a/src/aggregator/logic.py b/src/aggregator/logic.py index 4d1a3e9..f55a8cd 100644 --- a/src/aggregator/logic.py +++ b/src/aggregator/logic.py @@ -2,7 +2,6 @@ import random from collections import defaultdict -from functools import partial from .bots.bot_logic import BotLogic from .messages import ( @@ -13,7 +12,6 @@ ProblemMachineLeftOnBySomeoneElse, ProblemMachineLeftOnByUser, ProblemsLeavingSpaceNotification, - StaleCheckoutNotification, TestNotification, ) from .model import ( @@ -323,15 +321,6 @@ def _check_out_stale_user(self, user_id, ts_checkin, elapsed_time_in_hours, logg if self.crm_adapter: self.crm_adapter.user_checkout(user_id, logger) - notification = StaleCheckoutNotification( - user, ts_checkin, self.urls.notification_settings(), self.urls.space_state() - ) - self.task_scheduler.schedule_task_at_time( - self.clock.now().replace(hour=8, minute=0), - partial(self.send_user_notification, user, notification), - logger, - ) - def send_user_notification(self, user, notification, logger): if self.telegram_bot and user.uses_telegram_bot(): chat_id = None diff --git a/src/aggregator/logic_tests.py b/src/aggregator/logic_tests.py index e08e1b1..a76a6b4 100644 --- a/src/aggregator/logic_tests.py +++ b/src/aggregator/logic_tests.py @@ -55,80 +55,6 @@ def test_enter_and_leave_space(self): ], ) - def test_stale_checkout_detection(self): - # Check in at 11pm - self.clock.set_time_of_day("23:00") - self.aggregator.user_entered_space(STEFANO.user_id, self.logger) - - # After an hour (at midnight) - self.clock.add(1, "hour") - space_state = self.aggregator.get_space_state_for_json(self.logger) - self.assertEqual( - space_state["users_in_space"], - [ - { - "ts_checkin": "23:00:00 03/02/2019", - "ts_checkin_human": "an hour ago", - "user": { - "email": "stefano@stefanomasini.com", - "first_name": "Stefano", - "full_name": "Stefano Masini", - "last_name": "Masini", - "user_id": 1, - }, - "machines_on": [], - }, - ], - ) - - # At 5 am - self.clock.add(5, "hour") - space_state = self.aggregator.get_space_state_for_json(self.logger) - self.assertEqual( - space_state["users_in_space"], - [ - { - "ts_checkin": "23:00:00 03/02/2019", - "ts_checkin_human": "6 hours ago", - "user": { - "email": "stefano@stefanomasini.com", - "first_name": "Stefano", - "full_name": "Stefano Masini", - "last_name": "Masini", - "user_id": 1, - }, - "machines_on": [], - }, - ], - ) - - # Detect stale checkins - self.aggregator.clean_stale_user_checkins(self.logger) - space_state = self.aggregator.get_space_state_for_json(self.logger) - self.assertEqual(space_state["users_in_space"], []) - self.assertEqual(self.bot_messages, []) - - # At 9 am - self.clock.add(4, "hour") - self.task_scheduler.actually_execute_due_tasks(self.logger) - self.assertEqual( - self.bot_messages, - [ - (1, "StaleCheckoutNotification"), - ], - ) - self.bot_messages = [] - self.assertEqual( - self.emails_sent, - [ - (1, "StaleCheckoutNotification"), - ], - ) - - # No more messages after that - self.task_scheduler.actually_execute_due_tasks(self.logger) - self.assertEqual(self.bot_messages, []) - def test_warn_user_when_he_leaves_and_his_machine_is_on(self): self.aggregator.user_entered_space(STEFANO.user_id, self.logger) diff --git a/src/aggregator/messages.py b/src/aggregator/messages.py index 67e100a..7693778 100644 --- a/src/aggregator/messages.py +++ b/src/aggregator/messages.py @@ -146,33 +146,6 @@ class MessageCancelAction(BaseBotMessage): # -- Notifications ---- -class StaleCheckoutNotification(BaseBotMessage): - def __init__(self, user, ts_checkin, notification_settings_url, space_state_url): - self.user = user - self.ts_checkin = ts_checkin - self.notification_settings_url = notification_settings_url - self.space_state_url = space_state_url - - def get_text(self): - return f"Did you forget to checkout yesterday?\nYou entered the Space at {self.ts_checkin.human_str()}" - - def get_email_text(self): - return ( - f"Hello {self.user.first_name},\n\n" - "It looks like you might have forgotten to checkout at the space yesterday?\n" - f"According to the logs you entered the space at {self.ts_checkin.human_str()}, but there's no trace of a checkout.\n\n" - "Checking out is useful so that other people know when to expect other fellow makers at the space, and it allows me to provide useful reminders, " - "like if the lights are still on when the last person leaves.\n\n" - "Checking out can be done when you leave, by simply swiping your card again, while you hold the door open on your way out.\n" - f"Or it can also be done via the Space State page: {self.space_state_url}\n" - f"page: {self.notification_settings_url}\n\n" - "The MakerSpace BOT\n\n" - ) - - def get_subject_for_email(self): - return "Forgot to checkout" - - class MachineLeftOnNotification(BaseBotMessage): def __init__(self, machine): self.machine = machine