Skip to content
This repository was archived by the owner on Aug 26, 2025. It is now read-only.
This repository was archived by the owner on Aug 26, 2025. It is now read-only.

Allow custom impersonation permission #4

@fopina

Description

@fopina

Instead of allowing only superuser to impersonate, create a custom permission (can_impersonate) and use a configurable function to check permissions for impersonation.

Function should receive impersonator and impersonee and return True if allowed to impersonate.

Default implementation is the current behavior (if superuser, return True, regardless of who is the target) but apps can override the function in settings.py with one of their own such as:

def can_impersonate(impersonator, impersonee):
    if impersonator.is_superuser : return True
    if impersonator has group `SupportEngineer` and impersonee has group `Developer` : return True
    return False

UPDATE: following up on #1, add this new permission to https://github.com/surface-security/django-impersonate/blob/main/impersonate/admin.py#L7. It's not required for security but needed for UX (hide action from those that cannot use it)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions