Skip to content

Commit

Permalink
feat: add user profile_summary
Browse files Browse the repository at this point in the history
  • Loading branch information
AmooHashem committed Jul 18, 2024
1 parent b3da820 commit 9daa2c7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
15 changes: 11 additions & 4 deletions apps/accounts/serializers/user_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,12 @@ class Meta:
read_only_fields = ['id', 'is_document_verified', ]


# TODO - think about the AIC problem of data leak when retrieving list of profiles
class ProfileSerializer(serializers.ModelSerializer):
class UserProfileSerializer(serializers.ModelSerializer):
school_studentship = StudentshipSerializer(read_only=True)
academic_studentship = StudentshipSerializer(read_only=True)

def to_representation(self, instance):
representation = super(
ProfileSerializer, self).to_representation(instance)
representation = super().to_representation(instance)
representation.pop('password')
return representation

Expand All @@ -173,3 +171,12 @@ class Meta:
fields = '__all__'
read_only_fields = ['id', 'school_studentship',
'academic_studentship', 'username', 'phone_number', 'password']


class UserProfileSummarySerializer(serializers.ModelSerializer):

class Meta:
model = User
fields = ['id', 'first_name', 'last_name', 'bio', 'profile_picture']
read_only_fields = ['id', 'first_name',
'last_name', 'bio', 'profile_picture']
4 changes: 0 additions & 4 deletions apps/accounts/views/institute_view.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging

from django.db import transaction
from django_filters.rest_framework import DjangoFilterBackend
from drf_yasg.utils import swagger_auto_schema
Expand All @@ -16,8 +14,6 @@
from apps.accounts.utils import find_user_in_website
from errors.error_codes import serialize_error

logger = logging.getLogger(__name__)


class InstituteViewSet(ModelViewSet):
queryset = EducationalInstitute.objects.all()
Expand Down
16 changes: 10 additions & 6 deletions apps/accounts/views/profile_view.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import logging

from django.db import transaction
from django.contrib.auth.models import AnonymousUser
from rest_framework import permissions
from rest_framework.viewsets import ModelViewSet
from rest_framework.decorators import action
from rest_framework.response import Response

from apps.accounts.models import User
from apps.accounts.serializers.user_serializer import ProfileSerializer

logger = logging.getLogger(__name__)
from apps.accounts.serializers.user_serializer import UserProfileSerializer, UserProfileSummarySerializer


class ProfileViewSet(ModelViewSet):
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
serializer_class = ProfileSerializer
serializer_class = UserProfileSerializer
my_tags = ['accounts']

def get_queryset(self):
Expand All @@ -23,3 +22,8 @@ def get_queryset(self):
return User.objects.all()
else:
return User.objects.filter(id=user.id)

@action(detail=True, methods=['get'])
def profile_summary(self, request, pk=None):
user_profile = self.get_object()
return Response(UserProfileSummarySerializer(user_profile).data)

0 comments on commit 9daa2c7

Please sign in to comment.