Django REST Framework integration¶
-
class
bridgekeeper.rest_framework.
BridgekeeperRESTMixin
[source]¶ Mixin for Django REST Framework integration classes.
-
get_action
(request, view, obj=None)[source]¶ Return the action that a particular request is performing.
Usually, this is one of
'view'
,'add'
,'change'
or'delete'
. This is used byget_permission_name()
to generate the name of the appropriate permission.- Returns
Name of an action.
- Return type
-
get_operand_name
(request, view, obj=None)[source]¶ Return the name of the thing that a request is acting on.
The default implementation works if
obj
is a model instance (when it is provided), or ifview
is a view that has either aqueryset
attribute orget_queryset()
method (otherwise).This is used by
get_permission_name()
to generate the name of the appropriate permission.
-
get_permission
(request, view, obj=None)[source]¶ Return a rule object to check against for this request.
The default implementation just looks up the name returned by
get_permission_name()
.- Returns
Rule object.
- Return type
-
get_permission_name
(request, view, obj=None)[source]¶ Return the name of the permission to use for a request.
The default implementation returns a name of the form
'{app_label}.{action}_{operand_name}'
, which will result in something like'shrubberies.view_shrubber'
or'shrubberies.delete_shrubbery'
.app_label
andoperand_name
are provided byget_operand_name()
, andaction
is provided byget_action()
, so if you need to override this behaviour, it may be easier to override those methods instead.- Returns
Permission name.
- Return type
-
skip_permission_checks
(request, view, obj=None)[source]¶ Skips all permission checks for certain requests.
The default implementation will skip permission checks for the
APIRootView
view class used by the built-inDefaultRouter
.- Returns
Whether to skip permission checks for the given request.
- Return type
-
-
class
bridgekeeper.rest_framework.
RuleFilter
[source]¶ Django REST Framework filter class for Bridgekeeper.
This filter class doesn’t expect any client interaction or present any UI to the API explorer; it’s simply a mechanism for automatically filtering QuerySets according to Bridgekeeper permissions.
Note that this filter will always check the
view
permission; this means that if a particular user has permissions to edit but not view something, they’ll get 404s on everything. That said, it doesn’t make much sense for users to have edit but not view permissions on something anyway.
-
class
bridgekeeper.rest_framework.
RulePermissions
[source]¶ Django REST Framework permission class for Bridgekeeper.
Note that this class does not, by itself, perform queryset filtering on list views, since Django REST Framework doesn’t provide an API for permission classes to do so.