server/comments: allow anonymous users to leave comments

This commit is contained in:
Eva
2025-04-04 08:50:04 +02:00
parent 3c51d1d694
commit bfba05cfae
3 changed files with 3 additions and 3 deletions

View File

@ -26,7 +26,7 @@
%><a href='<%- ctx.formatClientLink('user', ctx.user.name) %>'><% %><a href='<%- ctx.formatClientLink('user', ctx.user.name) %>'><%
%><% } %><% %><% } %><%
%><%- ctx.user ? ctx.user.name : 'Deleted user' %><% %><%- ctx.user ? ctx.user.name : 'Anonymous' %><%
%><% if (ctx.user && ctx.user.name && ctx.canViewUsers) { %><% %><% if (ctx.user && ctx.user.name && ctx.canViewUsers) { %><%
%></a><% %></a><%

View File

@ -48,7 +48,7 @@ def create_comment(
text = ctx.get_param_as_string("text") text = ctx.get_param_as_string("text")
post_id = ctx.get_param_as_int("postId") post_id = ctx.get_param_as_int("postId")
post = posts.get_post_by_id(post_id) 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.add(comment)
ctx.session.commit() ctx.session.commit()
return _serialize(ctx, comment) return _serialize(ctx, comment)

View File

@ -46,7 +46,7 @@ class Comment(Base):
user_id = sa.Column( user_id = sa.Column(
"user_id", "user_id",
sa.Integer, sa.Integer,
sa.ForeignKey("user.id"), sa.ForeignKey("user.id", ondelete="SET NULL"),
nullable=True, nullable=True,
index=True, index=True,
) )