def with_environment_permissions(
    environment: Environment, staff_user: FFAdminUser
) -> WithEnvironmentPermissionsCallable:
    """
    Add environment permissions to the staff_user fixture.
    Defaults to associating to the environment fixture.
    """

    def _with_environment_permissions(
        permission_keys: list[str] | None = None,
        environment_id: int | None = None,
        admin: bool = False,
    ) -> UserEnvironmentPermission:
        environment_id = environment_id or environment.id
        uep, __ = UserEnvironmentPermission.objects.get_or_create(
            environment_id=environment_id, user=staff_user, defaults={"admin": admin}
        )
        if permission_keys:
            uep.permissions.add(*permission_keys)  # type: ignore[arg-type]

        return uep

    return _with_environment_permissions

    Add environment permissions to the staff_user fixture.
    Defaults to associating to the environment fixture.
    
api/conftest.py