Skip to content

Commit

Permalink
Add user update throttling
Browse files Browse the repository at this point in the history
  • Loading branch information
jespino committed Aug 23, 2017
1 parent a0f83fe commit 1fb61df
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@
"login-fail": None,
"register-success": None,
"user-detail": None,
"user-update": None,
},
"DEFAULT_THROTTLE_WHITELIST": [],
"FILTER_BACKEND": "taiga.base.filters.FilterBackend",
Expand Down
1 change: 1 addition & 0 deletions settings/local.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ DATABASES = {
# "login-fail": None,
# "register-success": None,
# "user-detail": None,
# "user-update": None,
#}

# This list should containt:
Expand Down
1 change: 1 addition & 0 deletions settings/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"login-fail": None,
"register-success": None,
"user-detail": None,
"user-update": None,
}


Expand Down
4 changes: 2 additions & 2 deletions taiga/users/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from . import utils as user_utils
from .signals import user_cancel_account as user_cancel_account_signal
from .signals import user_change_email as user_change_email_signal
from .throttling import UserDetailRateThrottle
from .throttling import UserDetailRateThrottle, UserUpdateRateThrottle

class UsersViewSet(ModelCrudViewSet):
permission_classes = (permissions.UserPermission,)
Expand All @@ -58,7 +58,7 @@ class UsersViewSet(ModelCrudViewSet):
admin_validator_class = validators.UserAdminValidator
validator_class = validators.UserValidator
filter_backends = (MembersFilterBackend,)
throttle_classes = (UserDetailRateThrottle,)
throttle_classes = (UserDetailRateThrottle, UserUpdateRateThrottle)
model = models.User

def get_serializer_class(self):
Expand Down
5 changes: 5 additions & 0 deletions taiga/users/throttling.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@
class UserDetailRateThrottle(throttling.GlobalThrottlingMixin, throttling.ThrottleByActionMixin, throttling.SimpleRateThrottle):
scope = "user-detail"
throttled_actions = ["by_username", "retrieve"]


class UserUpdateRateThrottle(throttling.UserRateThrottle, throttling.ThrottleByActionMixin):
scope = "user-update"
throttled_actions = ["update", "partial_update"]

0 comments on commit 1fb61df

Please sign in to comment.