diff --git a/backend/pigeonhole/apps/groups/models.py b/backend/pigeonhole/apps/groups/models.py index 6e0029b4..2f9d71ac 100644 --- a/backend/pigeonhole/apps/groups/models.py +++ b/backend/pigeonhole/apps/groups/models.py @@ -65,4 +65,18 @@ def get_other_group(self): del data['final_score'] if 'feedback' in data: del data['feedback'] + return data + + def to_representation(self, instance): + data = super().to_representation(instance) + request = self.context.get('request') + + # Check if the user is a student and the group is not visible + if request and request.user.is_student and not instance.visible: + # Hide sensitive information for students + if 'final_score' in data: + del data['final_score'] + if 'feedback' in data: + del data['feedback'] + return data \ No newline at end of file diff --git a/backend/pigeonhole/apps/groups/views.py b/backend/pigeonhole/apps/groups/views.py index 9282cd49..de01f3c3 100644 --- a/backend/pigeonhole/apps/groups/views.py +++ b/backend/pigeonhole/apps/groups/views.py @@ -15,29 +15,3 @@ class GroupViewSet(viewsets.ModelViewSet): queryset = Group.objects.all() serializer_class = GroupSerializer permission_classes = [IsAuthenticated and CanAccessGroup] - - """ - def list(self, request, *args, **kwargs): - course_id = kwargs.get('course_id') - project_id = kwargs.get('project_id') - - # Check whether the course exists - get_object_or_404(Course, course_id=course_id) - # Check whether the project exists - project = get_object_or_404(Project, project=project_id) - - # Ensure the project is associated with the course - if project.course_id != int(course_id): - return Response({'detail': 'Project not found in the specified course.'}, status=status.HTTP_404_NOT_FOUND) - - queryset = self.queryset.filter(project_id=project_id) - serializer = self.get_serializer(queryset, many=True) - - if request.user.is_student: - for group in serializer.data: - if request.user.id not in group["users"]: - del group["final_score"] - del group["feedback"] - - return Response(serializer.data, status=status.HTTP_200_OK) - """ \ No newline at end of file