Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
83a0327b
Commit
83a0327b
authored
4 years ago
by
Troy Sankey
Browse files
Options
Downloads
Patches
Plain Diff
Also exclude libraries from the list_course_keys API
parent
e3cd6d55
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lms/djangoapps/course_api/api.py
+3
-1
3 additions, 1 deletion
lms/djangoapps/course_api/api.py
lms/djangoapps/course_api/tests/test_views.py
+23
-0
23 additions, 0 deletions
lms/djangoapps/course_api/tests/test_views.py
with
26 additions
and
1 deletion
lms/djangoapps/course_api/api.py
+
3
−
1
View file @
83a0327b
...
...
@@ -188,8 +188,10 @@ def list_course_keys(request, username, role):
filtered_course_keys
=
(
CourseAccessRole
.
objects
.
filter
(
user
=
user
,
# Having the instructor role implies staff access.
This fact was reverse-engineered from unit tests.
# Having the instructor role implies staff access.
role__in
=
[
'
staff
'
,
'
instructor
'
],
# We need to check against CourseOverview so that we don't return any Libraries.
course_id__in
=
CourseOverview
.
objects
.
all
(),
)
.
exclude
(
course_id
=
CourseKeyField
.
Empty
)
.
order_by
(
'
course_id
'
)
...
...
This diff is collapsed.
Click to expand it.
lms/djangoapps/course_api/tests/test_views.py
+
23
−
0
View file @
83a0327b
...
...
@@ -22,6 +22,7 @@ from waffle.testutils import override_switch
from
course_modes.models
import
CourseMode
from
course_modes.tests.factories
import
CourseModeFactory
from
opaque_keys.edx.locator
import
LibraryLocator
from
openedx.core.lib.api.view_utils
import
LazySequence
from
openedx.features.content_type_gating.models
import
ContentTypeGatingConfig
from
openedx.features.course_duration_limits.models
import
CourseDurationLimitConfig
...
...
@@ -511,6 +512,28 @@ class CourseIdListViewTestCase(CourseApiTestViewMixin, ModuleStoreTestCase):
self
.
assertEqual
(
len
(
filtered_response
.
data
[
'
results
'
]),
1
)
self
.
assertTrue
(
filtered_response
.
data
[
'
results
'
][
0
].
startswith
(
alternate_course2
.
org
))
def
test_no_libraries
(
self
):
"""
Verify that only Course IDs are returned, not anything else like libraries.
"""
# Make this user a course staff user for a course, AND a library.
course_staff_user
=
self
.
create_user
(
username
=
'
course_staff
'
,
is_staff
=
False
)
add_users
(
self
.
global_admin
,
CourseStaffRole
(
self
.
course
.
id
),
course_staff_user
)
add_users
(
self
.
global_admin
,
CourseStaffRole
(
LibraryLocator
.
from_string
(
'
library-v1:library_org+library_name
'
)),
course_staff_user
,
)
# Requesting the courses should return *only* courses and not libraries.
self
.
setup_user
(
self
.
staff_user
)
filtered_response
=
self
.
verify_response
(
params
=
{
'
username
'
:
course_staff_user
.
username
,
'
role
'
:
'
staff
'
})
self
.
assertEqual
(
len
(
filtered_response
.
data
[
'
results
'
]),
1
)
self
.
assertTrue
(
filtered_response
.
data
[
'
results
'
][
0
].
startswith
(
self
.
course
.
org
))
class
LazyPageNumberPaginationTestCase
(
TestCase
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment