diff --git a/aurweb/routers/pkgbase.py b/aurweb/routers/pkgbase.py index 9dab76f8..4e018a64 100644 --- a/aurweb/routers/pkgbase.py +++ b/aurweb/routers/pkgbase.py @@ -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: diff --git a/test/test_pkgbase_routes.py b/test/test_pkgbase_routes.py index a5c93451..0eb85cce 100644 --- a/test/test_pkgbase_routes.py +++ b/test/test_pkgbase_routes.py @@ -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