Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Provides a set of pluggable permission policies. """
""" A base class from which all permission classes should inherit. """
""" Return `True` if permission is granted, `False` otherwise. """
""" Return `True` if permission is granted, `False` otherwise. """ warnings.warn( 'The `obj` argument in `has_permission` is deprecated. ' 'Use `has_object_permission()` instead for object permissions.', DeprecationWarning, stacklevel=2 ) return self.has_permission(request, view, obj)
""" Allow any access. This isn't strictly required, since you could use an empty permission_classes list, but it's useful because it makes the intention more explicit. """
""" Allows access only to authenticated users. """
""" Allows access only to admin users. """
if request.user and request.user.is_staff: return True return False
""" The request is authenticated as a user, or is a read-only request. """
if (request.method in SAFE_METHODS or request.user and request.user.is_authenticated()): return True return False
""" The request is authenticated using `django.contrib.auth` permissions. See: https://docs.djangoproject.com/en/dev/topics/auth/#permissions
It ensures that the user is authenticated, and has the appropriate `add`/`change`/`delete` permissions on the model.
This permission can only be applied against view classes that provide a `.model` or `.queryset` attribute. """
# Map methods into required permission codes. # Override this if you need to also provide 'view' permissions, # or if you want to provide custom permission codes. 'GET': [], 'OPTIONS': [], 'HEAD': [], 'POST': ['%(app_label)s.add_%(model_name)s'], 'PUT': ['%(app_label)s.change_%(model_name)s'], 'PATCH': ['%(app_label)s.change_%(model_name)s'], 'DELETE': ['%(app_label)s.delete_%(model_name)s'], }
""" Given a model and an HTTP method, return the list of permission codes that the user is required to have. """ 'app_label': model_cls._meta.app_label, 'model_name': model_cls._meta.module_name }
model_cls = queryset.model
# Workaround to ensure DjangoModelPermissions are not applied # to the root view when using DefaultRouter. return True
' does not have `.model` or `.queryset` property.')
(request.user.is_authenticated() or not self.authenticated_users_only) and request.user.has_perms(perms)):
""" Similar to DjangoModelPermissions, except that anonymous users are allowed read-only access. """
""" The request is authenticated as a user and the token used has the right scope """
return False
assert False, ('TokenHasReadWriteScope requires either the' '`OAuthAuthentication` or `OAuth2Authentication` authentication ' 'class to be used.') |