Skip to content

Commit

Permalink
chore: show scores when student but not part of course related to pro…
Browse files Browse the repository at this point in the history
…ject #400
  • Loading branch information
bsilkyn committed May 10, 2024
1 parent 31a51a1 commit 61ae7ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions backend/api/serializers/group_serializer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from api.models.group import Group
from api.models.student import Student
from api.permissions.role_permissions import is_student
from api.models.assistant import Assistant
from api.models.teacher import Teacher
from api.permissions.role_permissions import is_student, is_assistant, is_teacher
from api.serializers.project_serializer import ProjectSerializer
from api.serializers.student_serializer import StudentIDSerializer
from django.utils.translation import gettext
Expand Down Expand Up @@ -30,12 +32,20 @@ class Meta:
def to_representation(self, instance):
data = super().to_representation(instance)

# If you are not a student, you can always see the score
if is_student(self.context["request"].user):
# Student can not see the score if they are not part of the group, or it is not visible yet
if not instance.students.filter(id=self.context["request"].user.student.id).exists() or\
not instance.project.score_visible:
user = self.context["request"].user
course_id = instance.project.course.id

# If you are not a student, you can always see the score
# Same with being a student, but not being part of the course affiliated with this group
if is_student(user) and \
not ((is_assistant(user) or is_teacher(user)) and
not user.student.courses.filter(id=instance.project.course.id).exists()):
student_in_course = user.student.courses.filter(id=instance.project.course.id).exists()
print(student_in_course, flush=True)
# Student can not see the score if they are not part of the course associated with group,
# or it is not visible yet
if not student_in_course or \
not instance.project.score_visible and student_in_course:
data.pop("score")

return data
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/admin/UsersView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const saveItem = async (): Promise<void> => {
if (role === 'student') {
const data: Record<string, any> = {
...editItem.value,
studentId: editItem.value.id,
student_id: editItem.value.id,
};
await func(data);
} else {
Expand Down

0 comments on commit 61ae7ba

Please sign in to comment.