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
Admin message
code.vt.edu will be down for maintenance from 0530-0630 EDT Wednesday, March 26th
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
9b5ab66a
Unverified
Commit
9b5ab66a
authored
4 years ago
by
Dillon Dumesnil
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Revert "Update the LMS courses API for staff permissions"
parent
b45ac858
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
+1
-5
1 addition, 5 deletions
lms/djangoapps/course_api/api.py
lms/djangoapps/course_api/tests/test_api.py
+7
-19
7 additions, 19 deletions
lms/djangoapps/course_api/tests/test_api.py
with
8 additions
and
24 deletions
lms/djangoapps/course_api/api.py
+
1
−
5
View file @
9b5ab66a
...
...
@@ -38,13 +38,9 @@ def get_effective_user(requesting_user, target_username):
"""
if
target_username
==
requesting_user
.
username
:
return
requesting_user
# This is the default behavior if username is not specified as a query parameter
# which is why the is_staff check is happening inside of here.
elif
target_username
==
''
:
if
requesting_user
.
is_staff
:
return
requesting_user
return
AnonymousUser
()
elif
target_username
and
can_view_courses_for_username
(
requesting_user
,
target_username
):
elif
can_view_courses_for_username
(
requesting_user
,
target_username
):
return
User
.
objects
.
get
(
username
=
target_username
)
else
:
raise
PermissionDenied
()
...
...
This diff is collapsed.
Click to expand it.
lms/djangoapps/course_api/tests/test_api.py
+
7
−
19
View file @
9b5ab66a
...
...
@@ -46,7 +46,7 @@ class CourseDetailTestMixin(CourseApiTestMixin):
"""
ENABLED_SIGNALS
=
[
'
course_published
'
]
def
_make_api_call
(
self
,
requesting_user
,
target_user
name
,
course_key
):
def
_make_api_call
(
self
,
requesting_user
,
target_user
,
course_key
):
"""
Call the `course_detail` api endpoint to get information on the course
identified by `course_key`.
...
...
@@ -54,7 +54,7 @@ class CourseDetailTestMixin(CourseApiTestMixin):
request
=
Request
(
self
.
request_factory
.
get
(
'
/
'
))
request
.
user
=
requesting_user
with
check_mongo_calls
(
0
):
return
course_detail
(
request
,
target_username
,
course_key
)
return
course_detail
(
request
,
target_
user
.
username
,
course_key
)
class
TestGetCourseDetail
(
CourseDetailTestMixin
,
SharedModuleStoreTestCase
):
...
...
@@ -71,37 +71,25 @@ class TestGetCourseDetail(CourseDetailTestMixin, SharedModuleStoreTestCase):
cls
.
staff_user
=
cls
.
create_user
(
'
staff
'
,
is_staff
=
True
)
def
test_get_existing_course
(
self
):
course
=
self
.
_make_api_call
(
self
.
honor_user
,
self
.
honor_user
.
username
,
self
.
course
.
id
)
self
.
verify_course
(
course
)
def
test_get_existing_course_as_anonymous_user
(
self
):
course
=
self
.
_make_api_call
(
self
.
honor_user
,
''
,
self
.
course
.
id
)
course
=
self
.
_make_api_call
(
self
.
honor_user
,
self
.
honor_user
,
self
.
course
.
id
)
self
.
verify_course
(
course
)
def
test_get_nonexistent_course
(
self
):
course_key
=
CourseKey
.
from_string
(
u
'
edX/toy/nope
'
)
with
self
.
assertRaises
(
Http404
):
self
.
_make_api_call
(
self
.
honor_user
,
self
.
honor_user
.
username
,
course_key
)
self
.
_make_api_call
(
self
.
honor_user
,
self
.
honor_user
,
course_key
)
def
test_hidden_course_for_honor
(
self
):
with
self
.
assertRaises
(
Http404
):
self
.
_make_api_call
(
self
.
honor_user
,
self
.
honor_user
.
username
,
self
.
hidden_course
.
id
)
self
.
_make_api_call
(
self
.
honor_user
,
self
.
honor_user
,
self
.
hidden_course
.
id
)
def
test_hidden_course_for_staff
(
self
):
course
=
self
.
_make_api_call
(
self
.
staff_user
,
self
.
staff_user
.
username
,
self
.
hidden_course
.
id
)
self
.
verify_course
(
course
,
course_id
=
u
'
edX/hidden/2012_Fall
'
)
def
test_hidden_course_for_staff_no_target_username
(
self
):
course
=
self
.
_make_api_call
(
self
.
staff_user
,
''
,
self
.
hidden_course
.
id
)
course
=
self
.
_make_api_call
(
self
.
staff_user
,
self
.
staff_user
,
self
.
hidden_course
.
id
)
self
.
verify_course
(
course
,
course_id
=
u
'
edX/hidden/2012_Fall
'
)
def
test_hidden_course_for_staff_as_honor
(
self
):
with
self
.
assertRaises
(
Http404
):
self
.
_make_api_call
(
self
.
staff_user
,
self
.
honor_user
.
username
,
self
.
hidden_course
.
id
)
def
test_permission_denied
(
self
):
with
self
.
assertRaises
(
PermissionDenied
):
self
.
_make_api_call
(
self
.
staff_user
,
None
,
self
.
hidden_course
.
id
)
self
.
_make_api_call
(
self
.
staff_user
,
self
.
honor_user
,
self
.
hidden_course
.
id
)
class
CourseListTestMixin
(
CourseApiTestMixin
):
...
...
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