Skip to content

Commit

Permalink
fix: set include_staff to False by default for course list api
Browse files Browse the repository at this point in the history
  • Loading branch information
tehreem-sadat committed Jan 9, 2025
1 parent b3d66a6 commit 54f441d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions futurex_openedx_extensions/dashboard/details/courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from django.db.models.functions import Coalesce
from django.db.models.query import QuerySet
from eox_nelp.course_experience.models import FeedbackCourse
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from lms.djangoapps.certificates.models import GeneratedCertificate

from futurex_openedx_extensions.helpers.querysets import (
Expand Down Expand Up @@ -106,11 +107,11 @@ def get_courses_queryset(
queryset = annotate_courses_rating_queryset(queryset)

if include_staff:
is_staff_queryset = Q(Value(False, output_field=BooleanField()))
else:
is_staff_queryset = check_staff_exist_queryset(
ref_user_id='user_id', ref_org='course__org', ref_course_id='course_id',
)
else:
is_staff_queryset = Q(Value(False, output_field=BooleanField()))

queryset = queryset.annotate(
enrolled_count=Coalesce(Subquery(
Expand Down Expand Up @@ -143,6 +144,12 @@ def get_courses_queryset(
GeneratedCertificate.objects.filter(
course_id=OuterRef('id'),
status='downloadable'
).annotate(
course__org=Subquery(
CourseOverview.objects.filter(id=OuterRef('course_id')).values('org')
)
).filter(
~is_staff_queryset
).values('course_id').annotate(count=Count('id')).values('count'),
output_field=IntegerField(),
), 0),
Expand Down
2 changes: 1 addition & 1 deletion futurex_openedx_extensions/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class CoursesView(ExportCSVMixin, FXViewRoleInfoMixin, ListAPIView):
def get_queryset(self) -> QuerySet:
"""Get the list of learners"""
search_text = self.request.query_params.get('search_text')
include_staff = self.request.query_params.get('include_staff', '0') == '1'
include_staff = self.request.query_params.get('include_staff')

return get_courses_queryset(
fx_permission_info=self.fx_permission_info,
Expand Down

0 comments on commit 54f441d

Please sign in to comment.