This commit is contained in:
Eva
2025-05-27 22:09:58 -05:00
committed by GitHub
8 changed files with 40 additions and 7 deletions

View File

@ -26,7 +26,7 @@
%><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) { %><%
%></a><%

View File

@ -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)

View File

@ -794,6 +794,8 @@ def update_post_flags(post: model.Post, flags: List[str]) -> None:
def feature_post(post: model.Post, user: Optional[model.User]) -> None:
assert post
if user and not user.name:
user = None
post_feature = model.PostFeature()
post_feature.time = datetime.utcnow()
post_feature.post = post

View File

@ -107,6 +107,9 @@ def _create(
entity
)
if auth_user and not auth_user.name:
auth_user = None
snapshot = model.Snapshot()
snapshot.creation_time = datetime.utcnow()
snapshot.operation = operation

View File

@ -43,12 +43,14 @@ def get_avatar_path(user_name: str) -> str:
def get_avatar_url(user: model.User) -> str:
assert user
if user.avatar_style == user.AVATAR_GRAVATAR:
assert user.email or user.name
if not user.email and not user.name:
return ""
return "https://gravatar.com/avatar/%s?d=retro&s=%d" % (
util.get_md5((user.email or user.name).lower()),
config.config["thumbnails"]["avatar_width"],
)
assert user.name
if not user.name:
return ""
return "%s/avatars/%s.png" % (
config.config["data_url"].rstrip("/"),
user.name.lower(),

View File

@ -0,0 +1,26 @@
'''
make featuring users nullable
Revision ID: 5b5c940b4e78
Created at: 2025-04-04 08:24:39.000603
'''
import sqlalchemy as sa
from alembic import op
revision = '5b5c940b4e78'
down_revision = 'adcd63ff76a2'
branch_labels = None
depends_on = None
def upgrade():
op.alter_column(
"post_feature", "user_id", nullable=True, existing_nullable=False
)
pass
def downgrade():
op.alter_column(
"post_feature", "user_id", nullable=False, existing_nullable=True
)
pass

View File

@ -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,
)

View File

@ -24,8 +24,8 @@ class PostFeature(Base):
user_id = sa.Column(
"user_id",
sa.Integer,
sa.ForeignKey("user.id"),
nullable=False,
sa.ForeignKey("user.id", ondelete="SET NULL"),
nullable=True,
index=True,
)
time = sa.Column("time", sa.DateTime, nullable=False)