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
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
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
43779814
Commit
43779814
authored
9 years ago
by
Sven Marnach
Browse files
Options
Downloads
Patches
Plain Diff
Optimise getting list of courses from Enrollment API for global staff.
parent
dd021841
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
common/djangoapps/enrollment/tests/test_views.py
+6
-2
6 additions, 2 deletions
common/djangoapps/enrollment/tests/test_views.py
common/djangoapps/enrollment/views.py
+3
-2
3 additions, 2 deletions
common/djangoapps/enrollment/views.py
with
9 additions
and
4 deletions
common/djangoapps/enrollment/tests/test_views.py
+
6
−
2
View file @
43779814
...
...
@@ -32,7 +32,7 @@ from openedx.core.djangoapps.user_api.models import UserOrgTag
from
openedx.core.lib.django_test_client_utils
import
get_absolute_url
from
student.models
import
CourseEnrollment
from
student.roles
import
CourseStaffRole
from
student.tests.factories
import
User
Factory
,
CourseModeFactory
from
student.tests.factories
import
Admin
Factory
,
CourseModeFactory
,
UserFactory
from
embargo.test_utils
import
restrict_course
...
...
@@ -353,11 +353,15 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase):
self
.
client
.
login
(
username
=
self
.
OTHER_USERNAME
,
password
=
self
.
PASSWORD
)
self
.
_assert_enrollments_visible_in_list
([])
# Create a staff user for self.course (but nor for other_course) and log her in.
staff_user
=
UserFactory
.
create
(
username
=
'
staff
'
,
email
=
'
staff@example.com
'
,
password
=
self
.
PASSWORD
,
)
staff_user
=
UserFactory
.
create
(
username
=
'
staff
'
,
email
=
'
staff@example.com
'
,
password
=
self
.
PASSWORD
)
CourseStaffRole
(
self
.
course
.
id
).
add_users
(
staff_user
)
self
.
client
.
login
(
username
=
'
staff
'
,
password
=
self
.
PASSWORD
)
# Verify that she can see only the enrollment in the course she has staff privileges for.
self
.
_assert_enrollments_visible_in_list
([
self
.
course
])
# Create a global staff user, and verify she can see all enrollments.
AdminFactory
(
username
=
'
global_staff
'
,
email
=
'
global_staff@example.com
'
,
password
=
self
.
PASSWORD
)
self
.
client
.
login
(
username
=
'
global_staff
'
,
password
=
self
.
PASSWORD
)
self
.
_assert_enrollments_visible_in_list
([
self
.
course
,
other_course
])
# Verify the server can see all enrollments.
self
.
client
.
logout
()
self
.
_assert_enrollments_visible_in_list
([
self
.
course
,
other_course
],
use_server_key
=
True
)
...
...
This diff is collapsed.
Click to expand it.
common/djangoapps/enrollment/views.py
+
3
−
2
View file @
43779814
...
...
@@ -32,7 +32,7 @@ from enrollment.errors import (
)
from
student.auth
import
user_has_role
from
student.models
import
User
from
student.roles
import
CourseStaffRole
from
student.roles
import
CourseStaffRole
,
GlobalStaff
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -472,7 +472,8 @@ class EnrollmentListView(APIView, ApiKeyPermissionMixIn):
).
format
(
username
=
username
)
}
)
if
username
==
request
.
user
.
username
or
self
.
has_api_key_permissions
(
request
):
if
username
==
request
.
user
.
username
or
GlobalStaff
().
has_user
(
request
.
user
)
or
\
self
.
has_api_key_permissions
(
request
):
return
Response
(
enrollment_data
)
filtered_data
=
[]
for
enrollment
in
enrollment_data
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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