Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lms/djangoapps/course_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import logging

from edx_django_utils.monitoring import function_trace
from edx_when.api import get_dates_for_course
from django.conf import settings
from django.contrib.auth.models import AnonymousUser, User
Expand Down Expand Up @@ -118,6 +119,7 @@ def _filter_by_search(course_queryset, search_term):
)


@function_trace('list_courses')
def list_courses(request, username, org=None, roles=None, filter_=None, search_term=None):
"""
Yield all available courses.
Expand Down
3 changes: 3 additions & 0 deletions lms/djangoapps/course_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


from django.core.exceptions import ValidationError
from edx_django_utils.monitoring import set_custom_metric
from edx_rest_framework_extensions.paginators import NamespacedPageNumberPagination
from rest_framework.generics import ListAPIView, RetrieveAPIView
from rest_framework.throttling import UserRateThrottle
Expand Down Expand Up @@ -245,6 +246,8 @@ def get_queryset(self):
if not form.is_valid():
raise ValidationError(form.errors)

set_custom_metric('query_param_roles', form.cleaned_data['role'])

return list_courses(
self.request,
form.cleaned_data['username'],
Expand Down
13 changes: 12 additions & 1 deletion lms/djangoapps/courseware/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
from datetime import datetime

import six
from django.conf import settings
from django.conf import settings # pylint: disable=unused-import
from django.contrib.auth.models import AnonymousUser
from edx_django_utils.monitoring import function_trace
from opaque_keys.edx.keys import CourseKey, UsageKey
from pytz import UTC
from six import text_type
Expand Down Expand Up @@ -100,6 +101,7 @@ def has_ccx_coach_role(user, course_key):
return False


@function_trace('has_access')
def has_access(user, action, obj, course_key=None):
"""
Check whether a user has the access to do action on obj. Handles any magic
Expand Down Expand Up @@ -211,6 +213,7 @@ def _is_prerequisites_disabled():
)


@function_trace('_can_load_course_on_mobile')
def _can_load_course_on_mobile(user, course):
"""
Checks if a user can view the given course on a mobile device.
Expand Down Expand Up @@ -284,6 +287,7 @@ def _can_enroll_courselike(user, courselike):
return ACCESS_DENIED


@function_trace('_has_access_course')
def _has_access_course(user, action, courselike):
"""
Check if user has access to a course.
Expand All @@ -305,6 +309,7 @@ def _has_access_course(user, action, courselike):
'see_in_catalog' -- user is able to see the course listed in the course catalog.
'see_about_page' -- user is able to see the course about page.
"""
@function_trace('can_load')
def can_load():
"""
Can this user load this course?
Expand Down Expand Up @@ -358,19 +363,22 @@ def can_load():

return ACCESS_GRANTED

@function_trace('can_enroll')
def can_enroll():
"""
Returns whether the user can enroll in the course.
"""
return _can_enroll_courselike(user, courselike)

@function_trace('see_exists')
def see_exists():
"""
Can see if can enroll, but also if can load it: if user enrolled in a course and now
it's past the enrollment period, they should still see it.
"""
return ACCESS_GRANTED if (can_load() or can_enroll()) else ACCESS_DENIED

@function_trace('can_see_in_catalog')
def can_see_in_catalog():
"""
Implements the "can see course in catalog" logic if a course should be visible in the main course catalog
Expand All @@ -382,6 +390,7 @@ def can_see_in_catalog():
or _has_staff_access_to_descriptor(user, courselike, courselike.id)
)

@function_trace('can_see_about_page')
def can_see_about_page():
"""
Implements the "can see course about page" logic if a course about page should be visible
Expand Down Expand Up @@ -771,6 +780,7 @@ def administrative_accesses_to_course_for_user(user, course_key):
return global_staff, staff_access, instructor_access


@function_trace('_has_instructor_access_to_descriptor')
def _has_instructor_access_to_descriptor(user, descriptor, course_key):
"""Helper method that checks whether the user has staff access to
the course of the location.
Expand All @@ -780,6 +790,7 @@ def _has_instructor_access_to_descriptor(user, descriptor, course_key):
return _has_instructor_access_to_location(user, descriptor.location, course_key)


@function_trace('_has_staff_access_to_descriptor')
def _has_staff_access_to_descriptor(user, descriptor, course_key):
"""Helper method that checks whether the user has staff access to
the course of the location.
Expand Down
2 changes: 2 additions & 0 deletions lms/djangoapps/courseware/courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from django.db.models import Prefetch
from django.http import Http404, QueryDict
from django.urls import reverse
from edx_django_utils.monitoring import function_trace
from fs.errors import ResourceNotFound
from opaque_keys.edx.keys import UsageKey
from path import Path as path
Expand Down Expand Up @@ -457,6 +458,7 @@ def get_course_syllabus_section(course, section_key):
raise KeyError("Invalid about key " + str(section_key))


@function_trace('get_courses')
def get_courses(user, org=None, filter_=None):
"""
Return a LazySequence of courses available, optionally filtered by org code (case-insensitive).
Expand Down
1 change: 0 additions & 1 deletion openedx/core/djangoapps/user_api/accounts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from django.core.validators import ValidationError, validate_email
from django.utils.translation import override as override_language
from django.utils.translation import ugettext as _
from edx_django_utils.monitoring import set_custom_metric
from pytz import UTC
from six import text_type # pylint: disable=ungrouped-imports

Expand Down