Skip to content

Commit

Permalink
fixup: whitespace flakes
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanlandia committed Jul 6, 2023
1 parent 240addf commit f58a23d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions openedx/core/djangoapps/appsembler/openedx_api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
Completion (BlockCompletion.course_id__org)
? Course Experience ()
? Course Home ()
Courses (CourseOverview.org)
Courses (CourseOverview.org)
Courseware (CourseOverview.org)
Discussion (not sure how to handle... discussions aren't Django objs, just gets course via lms.djangoapps.courseware.courses.get_course_with_access)
Enrollment (CourseEnrollment.course__org)
Grades: not sure yet how these are serialized...
...or if they use PersistentGrades.
...or if they use PersistentGrades.
User (User.organizations__contains)
...
Expand Down Expand Up @@ -62,46 +62,46 @@ class AllowedCourseOrgFilterSet(filters.FilterSet):
GeneratedCertificate: 'course_id__startswith',
BlockCompletion: 'context_key__startswith',
}

# have no ForeignKey to CourseOverview or other path to Organization,
# just an OpaqueKeyField subclass so we have to do a string comparison
OPAQUE_KEY_FIELD_LOOKUP_MODELS = (
BlockCompletion,
CourseUserGroup,
GeneratedCertificate,
)

# org field is just a string of the name of the org.
STRING_ORG_NAME_LOOKUP_MODELS = (
CourseEnrollment,
CourseOverview,
)

# TODO: Allow a superuser to bypass filter

allowed_org = filters.BooleanFilter(method="filter_allowed_org")

def filter_allowed_org(self, queryset, name, value):
import pdb; pdb.set_trace()
requesting_user = self.request.user

try:
user_allowed_org = self.request.user.organizations.first()
except Organization.DoesNotExist:
raise # TODO: do something else

try:
lookup = MODEL_COURSE_ORG_LOOKUPS[self.queryset.model]
except KeyError:
raise # TODO: do something else

if model in OPAQUE_KEY_FIELD_LOOKUP_MODELS:
return queryset.filter(**{lookup: "{}{}+".format(COURSE_PREFIX, user_allowed_org)})
elif model in STRING_ORG_NAME_LOOKUP_MODELS:
return queryset.filter(**{lookup: user_allowed_org.short_name})
else:
return queryset.filter(**{lookup: user_allowed_org})

# don't declare an explicit model via Meta


Expand Down

0 comments on commit f58a23d

Please sign in to comment.