mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
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:
parent
36fd58d7a6
commit
ff0123b54a
2 changed files with 24 additions and 1 deletions
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue