Using Aristotle permissions in custom code¶
One of the key features in Aristotle is specific access control to items based on a rich matrix of user groups. To make creating extension easier these are exposed through the code in a number of easy to use ways.
Permissions in perms.py¶
Permissions-based ConceptManager¶
All correctly derived concept items should have their default manager set to
the aristotle.models.ConceptManager. For more information on how this works
see the full documentation on the
ConceptManager and ConceptQuerySet.
-
class
aristotle_mdr.models.ConceptManager[source] The
ConceptManageris the default object manager forconceptand_conceptitems, and extends from the django-model-utilsInheritanceManager.It provides access to the
ConceptQuerySetto allow for easy permissions-based filtering of ISO 11179 Concept-based items.
Permissions template tags¶
Tags and filters available in aristotle templates¶
A number of convenience tags are available for performing common actions in custom templates.
Include the aristotle template tags in every template that uses them, like so:
{% load aristotle_tags %}
Available tags and filters¶
-
aristotle_mdr.templatetags.aristotle_tags.can_edit(item, user)[source] A filter that acts as a wrapper around
aristotle_mdr.perms.user_can_edit. Returns true if the user has permission to edit the item, otherwise it returns False. If callinguser_can_editthrows an exception it safely returns False.For example:
{% if myItem|can_edit:request.user %} {{ item }} {% endif %}
-
aristotle_mdr.templatetags.aristotle_tags.can_view(item, user)[source] A filter that acts as a wrapper around
aristotle_mdr.perms.user_can_view. Returns true if the user has permission to view the item, otherwise it returns False. If callinguser_can_viewthrows an exception it safely returns False.For example:
{% if myItem|can_view:request.user %} {{ item }} {% endif %}
-
aristotle_mdr.templatetags.aristotle_tags.can_view_iter(qs, user)[source] A filter that is a simple wrapper that applies the
aristotle_mdr.models.ConceptManager.visible(user)for use in templates. Filtering on a DjangoQuerysetand passing in the current user as the argument returns a list (not aQuerysetat this stage) of only the items from theQuerysetthe user can view.If calling
can_view_iterthrows an exception it safely returns an empty list.For example:
{% for item in myItems|can_view_iter:request.user %} {{ item }} {% endfor %}
There are more template tags available in Aristotle