mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-03 21:24:33 +03:00
Update an example to not use oppressive language (#7439)
* Update an example to use less oppressive language For reference: https://tools.ietf.org/id/draft-knodel-terminology-00.html * Code review update Blocklisted -> blocked.
This commit is contained in:
parent
c252c3dfa5
commit
559088463b
|
@ -243,19 +243,19 @@ Custom permissions will raise a `PermissionDenied` exception if the test fails.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
The following is an example of a permission class that checks the incoming request's IP address against a blacklist, and denies the request if the IP has been blacklisted.
|
The following is an example of a permission class that checks the incoming request's IP address against a blocklist, and denies the request if the IP has been blocked.
|
||||||
|
|
||||||
from rest_framework import permissions
|
from rest_framework import permissions
|
||||||
|
|
||||||
class BlacklistPermission(permissions.BasePermission):
|
class BlocklistPermission(permissions.BasePermission):
|
||||||
"""
|
"""
|
||||||
Global permission check for blacklisted IPs.
|
Global permission check for blocked IPs.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def has_permission(self, request, view):
|
def has_permission(self, request, view):
|
||||||
ip_addr = request.META['REMOTE_ADDR']
|
ip_addr = request.META['REMOTE_ADDR']
|
||||||
blacklisted = Blacklist.objects.filter(ip_addr=ip_addr).exists()
|
blocked = Blocklist.objects.filter(ip_addr=ip_addr).exists()
|
||||||
return not blacklisted
|
return not blocked
|
||||||
|
|
||||||
As well as global permissions, that are run against all incoming requests, you can also create object-level permissions, that are only run against operations that affect a particular object instance. For example:
|
As well as global permissions, that are run against all incoming requests, you can also create object-level permissions, that are only run against operations that affect a particular object instance. For example:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user