Skip to content

Commit

Permalink
don't leak grades in program record before course completed (#1931)
Browse files Browse the repository at this point in the history
* don't get grades in the program record before course is complete

* remove test code
  • Loading branch information
rachellougee authored Oct 3, 2023
1 parent 75d173c commit 24f0f81
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
21 changes: 15 additions & 6 deletions courses/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.templatetags.static import static
from rest_framework import serializers
from rest_framework.exceptions import ValidationError
from django.db.models import CharField
from django.db.models import CharField, Q

from cms.serializers import CoursePageSerializer, ProgramPageSerializer
from courses import models
Expand All @@ -19,6 +19,7 @@
from flexiblepricing.api import is_courseware_flexible_price_approved
from main import features
from main.serializers import StrictFieldsSerializer
from mitol.common.utils.datetime import now_in_utc
from openedx.constants import EDX_ENROLLMENT_AUDIT_MODE, EDX_ENROLLMENT_VERIFIED_MODE
from users.models import User

Expand Down Expand Up @@ -688,12 +689,20 @@ def to_representation(self, instance):
).values_list("course_run__id", flat=True)

if not runs_ids:
# if there are no certificates then show only verified enrollment grades
# if there are no certificates then show verified enrollment grades that either
# certificate available date has passed or course has ended if no certificate available date
runs_ids = models.CourseRunEnrollment.objects.filter(
user=user,
run__course=course,
enrollment_mode=EDX_ENROLLMENT_VERIFIED_MODE,
change_status=None,
Q(user=user)
& Q(run__course=course)
& Q(enrollment_mode=EDX_ENROLLMENT_VERIFIED_MODE)
& Q(change_status=None)
& (
Q(run__certificate_available_date__lt=now_in_utc())
| (
Q(run__certificate_available_date=None)
& Q(run__end_date__lt=now_in_utc())
)
)
).values_list("run__id", flat=True)

grade = (
Expand Down
6 changes: 6 additions & 0 deletions courses/serializers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from flexiblepricing.factories import FlexiblePriceFactory
from main.test_utils import assert_drf_json_equal, drf_datetime
from main import features
from mitol.common.utils.datetime import now_in_utc
from openedx.constants import EDX_ENROLLMENT_AUDIT_MODE, EDX_ENROLLMENT_VERIFIED_MODE

pytestmark = [pytest.mark.django_db]
Expand Down Expand Up @@ -635,6 +636,11 @@ def test_learner_record_serializer(
}
if enrollment_mode == EDX_ENROLLMENT_AUDIT_MODE:
course_0_payload["grade"] = None
if course_runs[0].certificate_available_date >= now_in_utc() or (
not course_runs[0].certificate_available_date
and course_runs[0].end_date >= now_in_utc()
):
course_0_payload["grade"] = None
assert user_info_payload == serialized_data["user"]
assert program_requirements_payload == serialized_data["program"]["requirements"]
assert course_0_payload == serialized_data["program"]["courses"][0]
Expand Down

0 comments on commit 24f0f81

Please sign in to comment.