fix: save notification state for unchanged comments

When we edit a comment we can enable notifications (if not yet enabled).

We should also do this when the comment text is not changed.

Signed-off-by: moson-mo <mo-son@mailbox.org>
This commit is contained in:
moson-mo 2023-01-22 16:32:39 +01:00
parent 36fd58d7a6
commit ff0123b54a
No known key found for this signature in database
GPG key ID: 4A4760AB4EE15296
2 changed files with 24 additions and 1 deletions

View file

@ -312,11 +312,14 @@ async def pkgbase_comment_post(
db_comment.Editor = request.user
db_comment.EditedTS = now
if enable_notifications:
with db.begin():
db_notif = request.user.notifications.filter(
PackageNotification.PackageBaseID == pkgbase.ID
).first()
if enable_notifications and not db_notif:
if not db_notif:
db.create(PackageNotification, User=request.user, PackageBase=pkgbase)
update_comment_render_fastapi(db_comment)
if not next:

View file

@ -512,6 +512,26 @@ def test_pkgbase_comments(
).first()
assert db_notif is not None
# Delete notification for next test.
with db.begin():
db.delete(db_notif)
# Let's edit the comment again; This time we don't change the text.
# However we do enable notifications.
with client as request:
request.cookies = cookies
resp = request.post(
endpoint,
data={"comment": "Edited comment.", "enable_notifications": True},
)
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
# Ensure that a notification was created.
db_notif = pkgbase.notifications.filter(
PackageNotification.UserID == maintainer.ID
).first()
assert db_notif is not None
# Don't supply a comment; should return BAD_REQUEST.
with client as request:
request.cookies = cookies