From dff156fd12ab74c2c78339ec384698c2158a087b Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Fri, 12 Jan 2024 13:49:40 +1300 Subject: [PATCH] crash on profile for anon users --- app/models.py | 2 +- app/user/routes.py | 2 +- app/utils.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models.py b/app/models.py index 7eeccdee..31e2c285 100644 --- a/app/models.py +++ b/app/models.py @@ -383,7 +383,7 @@ class User(UserMixin, db.Model): if self.is_authenticated: return self.id else: - return None + return 0 def display_name(self): if self.deleted is False: diff --git a/app/user/routes.py b/app/user/routes.py index 125ba6d5..e778bc09 100644 --- a/app/user/routes.py +++ b/app/user/routes.py @@ -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) moderates = Community.query.filter_by(banned=False).join(CommunityMember).filter(CommunityMember.user_id == user.id)\ .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() else: upvoted = [] diff --git a/app/utils.py b/app/utils.py index 1e0f5816..b3bec172 100644 --- a/app/utils.py +++ b/app/utils.py @@ -553,7 +553,7 @@ def user_filters_replies(user_id): @cache.memoize(timeout=300) def moderating_communities(user_id): - if user_id is None: + if user_id is None or user_id == 0: return [] return Community.query.join(CommunityMember, Community.id == CommunityMember.community_id).\ filter(Community.banned == False).\ @@ -563,7 +563,7 @@ def moderating_communities(user_id): @cache.memoize(timeout=300) def joined_communities(user_id): - if user_id is None: + if user_id is None or user_id == 0: return [] return Community.query.join(CommunityMember, Community.id == CommunityMember.community_id).\ filter(Community.banned == False). \