Skip to content

Commit

Permalink
Merge pull request #650 from bounswe/BACKEND-649
Browse files Browse the repository at this point in the history
fix(backend): profile update profile serializer request check
  • Loading branch information
arastasci authored Nov 24, 2024
2 parents 79ebf06 + 4e4bf8c commit 39e0f7a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions backend/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ class Meta:

def get_posts(self, obj):
"""Get posts created by the user, similar to get_post_details."""

request = self.context.get('request')

if not request or not request.user.is_authenticated:
return []

posts = Post.objects.filter(author=obj.user)
user = self.context['request'].user

user = request.user

post_data = []
for post in posts:
is_liked = post.liked_by.filter(id=self.context['request'].user.id).exists()
is_liked = post.liked_by.filter(id=request.user.id).exists()
is_bookmarked = Bookmark.objects.filter(user=user, post=post).exists()

comments_data = [
Expand All @@ -35,7 +42,7 @@ def get_posts(self, obj):
"content": comment.body,
"author": comment.author.username,
"created_at": comment.created_at,
"is_liked": comment.liked_by.filter(id=self.context['request'].user.id).exists(),
"is_liked": comment.liked_by.filter(id=request.user.id).exists(),
"like_count": comment.liked_by.count(),
}
for comment in post.comments.all().order_by("-created_at")
Expand Down
2 changes: 1 addition & 1 deletion backend/app/views_directory/profileviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def view_profile(request):
@permission_classes([IsAuthenticated])
def update_profile(request):
user = request.user
profile = get_object_or_404(Profile, user=user)
profile = get_object_or_404(Profile, user=user
serializer = ProfileSerializer(profile, data=request.data, partial=True, context={'request': request})
if serializer.is_valid():
serializer.save()
Expand Down

0 comments on commit 39e0f7a

Please sign in to comment.