diff --git a/tools/migrations/26-05-14--rename_message_click_time_to_dismissed.sql b/tools/migrations/26-05-14--rename_message_click_time_to_dismissed.sql new file mode 100644 index 00000000..695fd1d8 --- /dev/null +++ b/tools/migrations/26-05-14--rename_message_click_time_to_dismissed.sql @@ -0,0 +1,7 @@ +-- The 26-05-03 migration that created `user_onboarding_message` is already +-- on master and has run on production. Editing that file in place to rename +-- the column does nothing on databases that have already applied it. This +-- forward migration performs the actual rename via ALTER TABLE. + +ALTER TABLE user_onboarding_message + CHANGE COLUMN message_click_time message_dismissed_time DATETIME NULL; diff --git a/zeeguu/api/endpoints/user_onboarding_message.py b/zeeguu/api/endpoints/user_onboarding_message.py index fbc6d719..280ce98b 100644 --- a/zeeguu/api/endpoints/user_onboarding_message.py +++ b/zeeguu/api/endpoints/user_onboarding_message.py @@ -62,10 +62,10 @@ def mark_onboarding_message_shown(): return json_result(onboarding_data) -@api.route("/set_onboarding_message_click_time", methods=["POST"]) +@api.route("/mark_onboarding_message_dismissed", methods=["POST"]) @cross_domain @requires_session -def set_onboarding_message_click_time(): +def mark_onboarding_message_dismissed(): data = flask.request.form onboarding_message_id = data.get("onboarding_message_id", None) @@ -82,7 +82,7 @@ def set_onboarding_message_click_time(): if not user_onboarding_message: return json_result({"error": "not found"}, status=404) - UserOnboardingMessage.update_user_onboarding_message_time(user_onboarding_message.id, db_session) + UserOnboardingMessage.set_message_dismissed_time(user_onboarding_message.id, db_session) db_session.commit() return "OK" \ No newline at end of file diff --git a/zeeguu/api/test/test_onboarding_message.py b/zeeguu/api/test/test_onboarding_message.py index f69f2816..a4765fda 100644 --- a/zeeguu/api/test/test_onboarding_message.py +++ b/zeeguu/api/test/test_onboarding_message.py @@ -45,7 +45,7 @@ def test_click_endpoint_refuses_cross_user_update(app, client): # User 2 tries to click it via a direct DB manipulation attack response = other_logged_in.response_from_post( - "/set_onboarding_message_click_time", + "/mark_onboarding_message_dismissed", data={"onboarding_message_id": 2} ) assert response.status_code == 404 # User 2 doesn't have this message @@ -54,7 +54,7 @@ def test_click_endpoint_refuses_cross_user_update(app, client): from zeeguu.core.model import User user1 = User.find(client.email) user_msg = UserOnboardingMessage.find_by_user_and_message(user1.id, 2) - assert user_msg.message_click_time is None + assert user_msg.message_dismissed_time is None def test_find_or_create_idempotency(app): diff --git a/zeeguu/core/model/user_onboarding_message.py b/zeeguu/core/model/user_onboarding_message.py index 0f56d952..4e0b6f37 100644 --- a/zeeguu/core/model/user_onboarding_message.py +++ b/zeeguu/core/model/user_onboarding_message.py @@ -9,8 +9,8 @@ class UserOnboardingMessage(db.Model): """ An onboarding message that was sent to the user. - If the user clicks it, the message_click_time will have the datetime - when that click was performed. IF not, this field will be null + If the user dismisses it, the `message_dismissed_time` will have the datetime + when that dismissal was performed. If not, this field will be null """ __table_args__ = {"mysql_collate": "utf8_bin"} @@ -20,7 +20,7 @@ class UserOnboardingMessage(db.Model): user_id = db.Column(db.Integer, db.ForeignKey(User.id)) onboarding_message_id = db.Column(db.Integer, db.ForeignKey(OnboardingMessage.id)) message_shown_time = db.Column(db.DateTime) - message_click_time = db.Column(db.DateTime, nullable=True) + message_dismissed_time = db.Column(db.DateTime, nullable=True) def __init__(self, user_id, onboarding_message_id): self.user_id = user_id @@ -79,13 +79,13 @@ def has_message_shown_time(cls, user_id, onboarding_message_id): ) @classmethod - def update_user_onboarding_message_time(cls, user_onboarding_message_id, db_session): - """Set the time when the user clicked/dismissed the message.""" + def set_message_dismissed_time(cls, user_onboarding_message_id, db_session): + """Set the time when the user dismissed the message.""" user_onboarding_message = cls.find_by_id(user_onboarding_message_id) if not user_onboarding_message: return None - user_onboarding_message.message_click_time = datetime.now() + user_onboarding_message.message_dismissed_time = datetime.now() db_session.add(user_onboarding_message) return user_onboarding_message