From 9cd26e551abebf7b7a48af2608a5cf9d3c2a5bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s=20Rocha?= Date: Fri, 3 Oct 2014 14:15:41 -0400 Subject: [PATCH] List all courses during OAut2/OpenID Connect Previously, only courses respective to the branded instance were returned. AN-3610 --- lms/djangoapps/oauth2_handler/handlers.py | 15 +++++++++++++-- lms/djangoapps/oauth2_handler/tests.py | 1 - 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lms/djangoapps/oauth2_handler/handlers.py b/lms/djangoapps/oauth2_handler/handlers.py index 8ff02f29a1..8ea7a6b54c 100644 --- a/lms/djangoapps/oauth2_handler/handlers.py +++ b/lms/djangoapps/oauth2_handler/handlers.py @@ -2,12 +2,13 @@ from django.conf import settings -import branding from courseware.access import has_access from student.models import anonymous_id_for_user from student.models import UserProfile from user_api.models import UserPreference from lang_pref import LANGUAGE_KEY +from xmodule.modulestore.django import modulestore +from xmodule.course_module import CourseDescriptor class OpenIDHandler(object): @@ -151,7 +152,7 @@ class CourseAccessHandler(object): user = data['user'] values = set(data.get('values', [])) - courses = branding.get_visible_courses() + courses = _get_all_courses() courses = (c for c in courses if has_access(user, access_type, c)) course_ids = (unicode(c.id) for c in courses) @@ -186,3 +187,13 @@ class IDTokenHandler(OpenIDHandler, ProfileHandler, CourseAccessHandler): class UserInfoHandler(OpenIDHandler, ProfileHandler, CourseAccessHandler): """ Configure the UserInfo handler for the LMS. """ pass + + +def _get_all_courses(): + """ + Utitilty function to list all available courses. + + """ + ms_courses = modulestore().get_courses() + courses = [c for c in ms_courses if isinstance(c, CourseDescriptor)] + return courses diff --git a/lms/djangoapps/oauth2_handler/tests.py b/lms/djangoapps/oauth2_handler/tests.py index 4edb9ea254..b358e2648c 100644 --- a/lms/djangoapps/oauth2_handler/tests.py +++ b/lms/djangoapps/oauth2_handler/tests.py @@ -1,5 +1,4 @@ # pylint: disable=missing-docstring -from django.conf import settings from django.test.utils import override_settings from django.test import TestCase