TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/rahul-baberwal/django-var-cms/llms.txt
Use this file to discover all available pages before exploring further.
var_cms.permissions module provides a lightweight, framework-independent set of dataclasses and pure-function helpers for role- and user-level access control. All permission evaluation in VarCMSModelAdmin goes through these primitives.
ACTIONS Constant
resolve_permission.
| Action | CMS view gated |
|---|---|
"add" | Add / create form |
"list" | Paginated list view |
"view" | Read-only detail view |
"edit" | Edit form |
"delete" | Delete confirmation |
RolePermission
Maps a role name to a set of allowed actions.The role identifier. Matched against:
"superuser"—request.user.is_superuserisTrue.- Any Django group name the user belongs to (
request.user.groups). - Custom role logic — override
VarCMSModelAdmin._get_user_role()for non-group-based roles.
Permits creating new objects.
Permits viewing the paginated list.
Permits viewing the read-only detail page.
Permits modifying existing objects.
Permits deleting objects.
allows(action: str) → bool
Returns the boolean value of the named action attribute.
Role Matching Details
GroupPermission
An alias forRolePermission that communicates intent — the role value explicitly refers to a Django auth group name.
GroupPermission and RolePermission are interchangeable at runtime. Use whichever makes your intent clearer.
UserPermission
Per-user permission override. Takes priority over all role and group permissions when the authenticated user’s username matches.The username to match against. Resolution uses
get_username() or falls back to the model’s USERNAME_FIELD attribute (configurable via VAR_CMS_USERNAME_FIELD / var_cms_site.username_field).Permits creating new objects for this specific user.
Permits viewing the paginated list.
Permits the read-only detail page.
Permits modifying existing objects.
Permits deleting objects.
allows(action: str) → bool
Returns the boolean value of the named action attribute — identical signature to RolePermission.allows.
Example: per-user override
resolve_permission()
True if the action is allowed.
| Parameter | Type | Description |
|---|---|---|
permissions | List[RolePermission | UserPermission] | The permissions list from the model admin. |
role | str | The resolved role name for the current user (from _get_user_role). |
action | str | One of the values in ACTIONS. Any other value returns False immediately. |
username | str | The current user’s username, used for UserPermission matching. Defaults to "". |
- UserPermission match — iterate the list; the first
UserPermissionwhose.username == usernamewins and itsallows(action)is returned immediately. - RolePermission match — iterate the list; the first
RolePermissionwhose.role == rolewins and itsallows(action)is returned. - Default deny — if no match is found,
Falseis returned.
resolve_editable_fields()
role_editable_fields mapping.
| Parameter | Type | Description |
|---|---|---|
role_editable_fields | Dict[str, List[str] | str] | The role_editable_fields dict from the model admin. |
role | str | The resolved role name for the current user. |
- If
roleis a key inrole_editable_fields, return its value (a list or"__all__"). - If
role == "superuser"and no explicit entry exists, return"__all__"(superusers always get full edit access unless explicitly restricted). - If the key
"*"(wildcard) exists inrole_editable_fields, return its value. - Return
[]— deny all edits for unrecognised roles.
When
role_editable_fields is an empty dict {} and get_editable_fields() falls through to resolve_editable_fields, the superuser fallback in step 2 still applies. Every other role receives [] in that case.permission_summary()
permissions and includes any entry that is an instance of RolePermission or UserPermission (checked via isinstance(p, (RolePermission, UserPermission))). Each included entry is rendered using p.role — this works for RolePermission and GroupPermission instances which have a .role attribute.
Returns: A list of dicts, each containing role, add, list, view, edit, and delete keys.
Complete Permissions Example
Resolution Cheat-Sheet
| Scenario | Result |
|---|---|
UserPermission matches username | That entry wins; no further checks |
RolePermission matches role | That entry’s action value is returned |
| No match in permissions list | False — access denied |
role_editable_fields[role] exists | That value returned (list or "__all__") |
role == "superuser" but no key set | "__all__" returned automatically |
Key "*" in role_editable_fields | Wildcard value returned for unknown roles |
| No match and no wildcard | [] — no fields editable |