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
edb7dd6f
Unverified
Commit
edb7dd6f
authored
6 years ago
by
Christopher Lee
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #18360 from edx/clee/LEARNER-5166-clean-waffle
Finalize rate limit for enrollment API
parents
285ae08d
f6e0c70f
No related branches found
Branches containing commit
Tags
release-2018-06-01-10.30
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
common/djangoapps/enrollment/__init__.py
+0
-7
0 additions, 7 deletions
common/djangoapps/enrollment/__init__.py
common/djangoapps/enrollment/views.py
+2
-27
2 additions, 27 deletions
common/djangoapps/enrollment/views.py
with
2 additions
and
34 deletions
common/djangoapps/enrollment/__init__.py
+
0
−
7
View file @
edb7dd6f
"""
Enrollment API helpers and settings
"""
from
openedx.core.djangoapps.waffle_utils
import
(
WaffleSwitch
,
WaffleSwitchNamespace
)
WAFFLE_SWITCH_NAMESPACE
=
WaffleSwitchNamespace
(
name
=
'
enrollment_api_rate_limit
'
)
USE_RATE_LIMIT_400_FOR_STAFF_FOR_ENROLLMENT_API
=
WaffleSwitch
(
WAFFLE_SWITCH_NAMESPACE
,
'
staff_rate_limit_400
'
)
USE_RATE_LIMIT_100_FOR_STAFF_FOR_ENROLLMENT_API
=
WaffleSwitch
(
WAFFLE_SWITCH_NAMESPACE
,
'
staff_rate_limit_100
'
)
USE_RATE_LIMIT_40_FOR_ENROLLMENT_API
=
WaffleSwitch
(
WAFFLE_SWITCH_NAMESPACE
,
'
rate_limit_40
'
)
This diff is collapsed.
Click to expand it.
common/djangoapps/enrollment/views.py
+
2
−
27
View file @
edb7dd6f
...
...
@@ -12,11 +12,6 @@ from django.utils.decorators import method_decorator
from
edx_rest_framework_extensions.authentication
import
JwtAuthentication
from
enrollment
import
api
from
enrollment.errors
import
CourseEnrollmentError
,
CourseEnrollmentExistsError
,
CourseModeNotFoundError
from
enrollment
import
(
USE_RATE_LIMIT_100_FOR_STAFF_FOR_ENROLLMENT_API
,
USE_RATE_LIMIT_40_FOR_ENROLLMENT_API
,
USE_RATE_LIMIT_400_FOR_STAFF_FOR_ENROLLMENT_API
,
)
from
opaque_keys
import
InvalidKeyError
from
opaque_keys.edx.keys
import
CourseKey
...
...
@@ -81,34 +76,14 @@ class ApiKeyPermissionMixIn(object):
class
EnrollmentUserThrottle
(
UserRateThrottle
,
ApiKeyPermissionMixIn
):
"""
Limit the number of requests users can make to the enrollment API.
"""
# TODO: After confirming that reducing the throttle is successful, remove
# and clean up waffles. The rate limit has been increased over the course
# of a few months to account for unnecessary calls from the ecommerce
# service. These calls are no longer made and the plan is to set the
# rate limit back to its original state. LEARNER-5148
# To see how the staff rate limit was selected, see https://github.com/edx/edx-platform/pull/18360
THROTTLE_RATES
=
{
'
user
'
:
'
40/minute
'
,
'
staff
'
:
'
2
00
0/minute
'
,
'
staff
'
:
'
1
20/minute
'
,
}
def
allow_request
(
self
,
request
,
view
):
if
USE_RATE_LIMIT_400_FOR_STAFF_FOR_ENROLLMENT_API
.
is_enabled
():
self
.
THROTTLE_RATES
=
{
'
user
'
:
'
40/minute
'
,
'
staff
'
:
'
400/minute
'
,
}
elif
USE_RATE_LIMIT_100_FOR_STAFF_FOR_ENROLLMENT_API
.
is_enabled
():
self
.
THROTTLE_RATES
=
{
'
user
'
:
'
40/minute
'
,
'
staff
'
:
'
100/minute
'
,
}
elif
USE_RATE_LIMIT_40_FOR_ENROLLMENT_API
.
is_enabled
():
self
.
THROTTLE_RATES
=
{
'
user
'
:
'
40/minute
'
,
'
staff
'
:
'
40/minute
'
,
}
# Use a special scope for staff to allow for a separate throttle rate
user
=
request
.
user
if
user
.
is_authenticated
and
(
user
.
is_staff
or
user
.
is_superuser
):
...
...
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