crash on profile for anon users

This commit is contained in:
rimu 2024-01-12 13:49:40 +13:00
parent b9c468d437
commit dff156fd12
3 changed files with 4 additions and 4 deletions

View file

@ -383,7 +383,7 @@ class User(UserMixin, db.Model):
if self.is_authenticated: if self.is_authenticated:
return self.id return self.id
else: else:
return None return 0
def display_name(self): def display_name(self):
if self.deleted is False: if self.deleted is False:

View file

@ -44,7 +44,7 @@ def show_profile(user):
posts = Post.query.filter_by(user_id=user.id).order_by(desc(Post.posted_at)).paginate(page=post_page, per_page=50, error_out=False) posts = Post.query.filter_by(user_id=user.id).order_by(desc(Post.posted_at)).paginate(page=post_page, per_page=50, error_out=False)
moderates = Community.query.filter_by(banned=False).join(CommunityMember).filter(CommunityMember.user_id == user.id)\ moderates = Community.query.filter_by(banned=False).join(CommunityMember).filter(CommunityMember.user_id == user.id)\
.filter(or_(CommunityMember.is_moderator, CommunityMember.is_owner)) .filter(or_(CommunityMember.is_moderator, CommunityMember.is_owner))
if user.id == current_user.id or current_user.is_admin(): if current_user.is_authenticated and (user.id == current_user.get_id() or current_user.is_admin()):
upvoted = Post.query.join(PostVote, PostVote.post_id == Post.id).filter(PostVote.effect > 0, PostVote.user_id == user.id).order_by(desc(PostVote.created_at)).limit(10).all() upvoted = Post.query.join(PostVote, PostVote.post_id == Post.id).filter(PostVote.effect > 0, PostVote.user_id == user.id).order_by(desc(PostVote.created_at)).limit(10).all()
else: else:
upvoted = [] upvoted = []

View file

@ -553,7 +553,7 @@ def user_filters_replies(user_id):
@cache.memoize(timeout=300) @cache.memoize(timeout=300)
def moderating_communities(user_id): def moderating_communities(user_id):
if user_id is None: if user_id is None or user_id == 0:
return [] return []
return Community.query.join(CommunityMember, Community.id == CommunityMember.community_id).\ return Community.query.join(CommunityMember, Community.id == CommunityMember.community_id).\
filter(Community.banned == False).\ filter(Community.banned == False).\
@ -563,7 +563,7 @@ def moderating_communities(user_id):
@cache.memoize(timeout=300) @cache.memoize(timeout=300)
def joined_communities(user_id): def joined_communities(user_id):
if user_id is None: if user_id is None or user_id == 0:
return [] return []
return Community.query.join(CommunityMember, Community.id == CommunityMember.community_id).\ return Community.query.join(CommunityMember, Community.id == CommunityMember.community_id).\
filter(Community.banned == False). \ filter(Community.banned == False). \