Skip to content

permissions

django_spire.core.management.commands.spire_startapp_pkg.permissions

PermissionInheritanceHandler

Handles permission inheritance configuration for nested Django apps.

This class manages the interactive collection of permission inheritance settings when creating child apps that may inherit permissions from parent apps.

Initializes the handler with a reporter for user interaction.

Parameters:

  • reporter (Reporter) –

    Reporter instance for displaying prompts and messages.

Source code in django_spire/core/management/commands/spire_startapp_pkg/permissions.py
def __init__(self, reporter: Reporter):
    """
    Initializes the handler with a reporter for user interaction.

    :param reporter: Reporter instance for displaying prompts and messages.
    """

    self.reporter = reporter

reporter = reporter instance-attribute

collect_inheritance_data

Collects permission inheritance configuration from the user.

Prompts the user to determine if the new app should inherit permissions from its parent app, and if so, collects the necessary parent model information.

Parameters:

  • components (list[str]) –

    List of app path components.

Returns:

  • dict[str, Any]

    Dictionary containing inheritance configuration data.

Source code in django_spire/core/management/commands/spire_startapp_pkg/permissions.py
def collect_inheritance_data(self, components: list[str]) -> dict[str, Any]:
    """
    Collects permission inheritance configuration from the user.

    Prompts the user to determine if the new app should inherit permissions
    from its parent app, and if so, collects the necessary parent model information.

    :param components: List of app path components.
    :return: Dictionary containing inheritance configuration data.
    """

    if len(components) <= 2:
        return {
            'inherit_permissions': False,
            'parent_model_instance_name': '',
            'parent_permission_prefix': '',
        }

    if not self._should_inherit_permissions():
        return {
            'inherit_permissions': False,
            'parent_model_instance_name': '',
            'parent_permission_prefix': '',
        }

    return {
        'inherit_permissions': True,
        'parent_model_instance_name': self._collect_parent_model_instance_name(components),
        'parent_model_path': self._collect_parent_model_path(components),
        'parent_permission_prefix': self._collect_parent_permission_prefix(components),
    }