Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
a27e7479
Commit
a27e7479
authored
Feb 10, 2015
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6490 from edx/clintonb/oauth2-course-finder-improvements
Updated _get_courses_with_access_type
parents
45b7c205
2945b923
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
13 deletions
+18
-13
lms/djangoapps/oauth2_handler/handlers.py
+18
-13
No files found.
lms/djangoapps/oauth2_handler/handlers.py
View file @
a27e7479
...
@@ -2,14 +2,14 @@
...
@@ -2,14 +2,14 @@
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.cache
import
cache
from
django.core.cache
import
cache
from
xmodule.modulestore.django
import
modulestore
from
courseware.access
import
has_access
from
courseware.access
import
has_access
from
openedx.core.djangoapps.user_api.models
import
UserPreference
from
student.models
import
anonymous_id_for_user
from
student.models
import
anonymous_id_for_user
from
student.models
import
UserProfile
from
student.models
import
UserProfile
from
openedx.core.djangoapps.user_api.models
import
UserPreference
from
lang_pref
import
LANGUAGE_KEY
from
lang_pref
import
LANGUAGE_KEY
from
xmodule.modulestore.django
import
modulestore
from
student.roles
import
GlobalStaff
,
CourseStaffRole
,
CourseInstructorRole
from
xmodule.course_module
import
CourseDescriptor
class
OpenIDHandler
(
object
):
class
OpenIDHandler
(
object
):
...
@@ -134,7 +134,7 @@ class CourseAccessHandler(object):
...
@@ -134,7 +134,7 @@ class CourseAccessHandler(object):
# TODO: unfortunately there is not a faster and still correct way to
# TODO: unfortunately there is not a faster and still correct way to
# check if a user is instructor of at least one course other than
# check if a user is instructor of at least one course other than
# checking the access type against all known courses.
# checking the access type against all known courses.
course_ids
=
self
.
find_courses
(
data
[
'user'
],
'instructor'
)
course_ids
=
self
.
find_courses
(
data
[
'user'
],
CourseInstructorRole
.
ROLE
)
return
[
'instructor_courses'
]
if
course_ids
else
None
return
[
'instructor_courses'
]
if
course_ids
else
None
def
scope_course_staff
(
self
,
data
):
def
scope_course_staff
(
self
,
data
):
...
@@ -144,7 +144,7 @@ class CourseAccessHandler(object):
...
@@ -144,7 +144,7 @@ class CourseAccessHandler(object):
"""
"""
# TODO: see :method:CourseAccessHandler.scope_course_instructor
# TODO: see :method:CourseAccessHandler.scope_course_instructor
course_ids
=
self
.
find_courses
(
data
[
'user'
],
'staff'
)
course_ids
=
self
.
find_courses
(
data
[
'user'
],
CourseStaffRole
.
ROLE
)
return
[
'staff_courses'
]
if
course_ids
else
None
return
[
'staff_courses'
]
if
course_ids
else
None
...
@@ -155,7 +155,7 @@ class CourseAccessHandler(object):
...
@@ -155,7 +155,7 @@ class CourseAccessHandler(object):
"""
"""
return
self
.
find_courses
(
data
[
'user'
],
'instructor'
,
data
.
get
(
'values'
))
return
self
.
find_courses
(
data
[
'user'
],
CourseInstructorRole
.
ROLE
,
data
.
get
(
'values'
))
def
claim_staff_courses
(
self
,
data
):
def
claim_staff_courses
(
self
,
data
):
"""
"""
...
@@ -164,7 +164,7 @@ class CourseAccessHandler(object):
...
@@ -164,7 +164,7 @@ class CourseAccessHandler(object):
"""
"""
return
self
.
find_courses
(
data
[
'user'
],
'staff'
,
data
.
get
(
'values'
))
return
self
.
find_courses
(
data
[
'user'
],
CourseStaffRole
.
ROLE
,
data
.
get
(
'values'
))
def
find_courses
(
self
,
user
,
access_type
,
values
=
None
):
def
find_courses
(
self
,
user
,
access_type
,
values
=
None
):
"""
"""
...
@@ -192,17 +192,22 @@ class CourseAccessHandler(object):
...
@@ -192,17 +192,22 @@ class CourseAccessHandler(object):
# pylint: disable=missing-docstring
# pylint: disable=missing-docstring
def
_get_courses_with_access_type
(
self
,
user
,
access_type
):
def
_get_courses_with_access_type
(
self
,
user
,
access_type
):
# Check the application cache and update if not present. The application
# Check the application cache and update if not present. The application
# cache is useful since there are calls to different endpoints in close
# cache is useful since there are calls to different endpoints in close
# succession, for example the id_token and user_info endpoins.
# succession, for example the id_token and user_info endpoin
t
s.
key
=
'-'
.
join
([
str
(
self
.
__class__
),
str
(
user
.
id
),
access_type
])
key
=
'-'
.
join
([
str
(
self
.
__class__
),
str
(
user
.
id
),
access_type
])
course_ids
=
cache
.
get
(
key
)
course_ids
=
cache
.
get
(
key
)
if
course_ids
is
None
:
if
not
course_ids
:
course_ids
=
[
unicode
(
course
.
id
)
for
course
in
_get_all_courses
()
courses
=
_get_all_courses
()
if
has_access
(
user
,
access_type
,
course
)]
# Global staff have access to all courses. Filter courses for non-global staff.
if
not
GlobalStaff
()
.
has_user
(
user
):
courses
=
[
course
for
course
in
courses
if
has_access
(
user
,
access_type
,
course
)]
course_ids
=
[
unicode
(
course
.
id
)
for
course
in
courses
]
cache
.
set
(
key
,
course_ids
,
self
.
COURSE_CACHE_TIMEOUT
)
cache
.
set
(
key
,
course_ids
,
self
.
COURSE_CACHE_TIMEOUT
)
return
course_ids
return
course_ids
...
@@ -235,6 +240,6 @@ def _get_all_courses():
...
@@ -235,6 +240,6 @@ def _get_all_courses():
""" Utility function to list all available courses. """
""" Utility function to list all available courses. """
ms_courses
=
modulestore
()
.
get_courses
()
ms_courses
=
modulestore
()
.
get_courses
()
courses
=
[
c
for
c
in
ms_courses
if
isinstance
(
c
,
CourseDescriptor
)
]
courses
=
[
c
ourse
for
course
in
ms_courses
if
course
.
scope_ids
.
block_type
==
'course'
]
return
courses
return
courses
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment