Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 3 additions & 3 deletions zeeguu/api/endpoints/user_onboarding_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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"
4 changes: 2 additions & 2 deletions zeeguu/api/test/test_onboarding_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions zeeguu/core/model/user_onboarding_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
Loading