Django REST Framework integration

class bridgekeeper.rest_framework.BridgekeeperRESTMixin

Mixin for Django REST Framework integration classes.

get_action(request, view, obj=None)

Return the action that a particular request is performing.

Usually, this is one of 'view', 'add', 'change' or 'delete'. This is used by get_permission_name() to generate the name of the appropriate permission.

Returns:Name of an action.
Return type:str
get_operand_name(request, view, obj=None)

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 if view is a view that has either a queryset attribute or get_queryset() method (otherwise).

This is used by get_permission_name() to generate the name of the appropriate permission.

Returns:A tuple in the form (app_label, operand_name).
Return type:(str, str)
get_permission(request, view, obj=None)

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:bridgekeeper.rules.Rule
get_permission_name(request, view, obj=None)

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 and operand_name are provided by get_operand_name(), and action is provided by get_action(), so if you need to override this behaviour, it may be easier to override those methods instead.

Returns:Permission name.
Return type:str
skip_permission_checks(request, view, obj=None)

Skips all permission checks for certain requests.

The default implementation will skip permission checks for the APIRootView view class used by the built-in DefaultRouter.

Returns:Whether to skip permission checks for the given request.
Return type:bool
class bridgekeeper.rest_framework.RuleFilter

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

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.