From bfba05cfae4e7f0d3a2d264a112b88ae1e6e28e9 Mon Sep 17 00:00:00 2001 From: Eva Date: Fri, 4 Apr 2025 08:50:04 +0200 Subject: [PATCH] server/comments: allow anonymous users to leave comments --- client/html/comment.tpl | 2 +- server/szurubooru/api/comment_api.py | 2 +- server/szurubooru/model/comment.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/html/comment.tpl b/client/html/comment.tpl index 6bea7045..df7b3664 100644 --- a/client/html/comment.tpl +++ b/client/html/comment.tpl @@ -26,7 +26,7 @@ %>'><% %><% } %><% - %><%- ctx.user ? ctx.user.name : 'Deleted user' %><% + %><%- ctx.user ? ctx.user.name : 'Anonymous' %><% %><% if (ctx.user && ctx.user.name && ctx.canViewUsers) { %><% %><% diff --git a/server/szurubooru/api/comment_api.py b/server/szurubooru/api/comment_api.py index d60d23ed..0dbc93de 100644 --- a/server/szurubooru/api/comment_api.py +++ b/server/szurubooru/api/comment_api.py @@ -48,7 +48,7 @@ def create_comment( text = ctx.get_param_as_string("text") post_id = ctx.get_param_as_int("postId") post = posts.get_post_by_id(post_id) - comment = comments.create_comment(ctx.user, post, text) + comment = comments.create_comment(ctx.user if ctx.user.name else None, post, text) ctx.session.add(comment) ctx.session.commit() return _serialize(ctx, comment) diff --git a/server/szurubooru/model/comment.py b/server/szurubooru/model/comment.py index e64961e6..d35c5af1 100644 --- a/server/szurubooru/model/comment.py +++ b/server/szurubooru/model/comment.py @@ -46,7 +46,7 @@ class Comment(Base): user_id = sa.Column( "user_id", sa.Integer, - sa.ForeignKey("user.id"), + sa.ForeignKey("user.id", ondelete="SET NULL"), nullable=True, index=True, )