- Moved all hookify configuration files from `.claude/` to `.claude/hooks/` subdirectory for better organization - Added four new blocking hooks to prevent common error handling anti-patterns: - `block-broad-exception-handler`: Prevents catching generic `Exception` with only logging - `block-datetime-now-fallback`: Blocks returning `datetime.now()` as fallback on parse failures to prevent data corruption - `block-default
88 lines
2.5 KiB
Python
88 lines
2.5 KiB
Python
"""Auth integration storage and retrieval."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import TYPE_CHECKING
|
|
from uuid import UUID
|
|
|
|
from noteflow.domain.entities.integration import IntegrationType
|
|
|
|
from .workflows import (
|
|
AuthIntegrationContext,
|
|
get_or_create_auth_integration,
|
|
get_or_create_default_workspace_id,
|
|
get_or_create_user_id,
|
|
store_integration_tokens,
|
|
)
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class AuthUserData:
|
|
"""Bundle of user identity data from OAuth provider."""
|
|
|
|
provider: str
|
|
email: str
|
|
display_name: str
|
|
|
|
if TYPE_CHECKING:
|
|
from noteflow.domain.entities.integration import Integration
|
|
from noteflow.domain.ports.unit_of_work import UnitOfWork
|
|
from noteflow.domain.value_objects import OAuthTokens
|
|
|
|
|
|
class IntegrationManager:
|
|
"""Handle auth integration storage and retrieval."""
|
|
|
|
async def store_auth_user(
|
|
self,
|
|
uow: UnitOfWork,
|
|
user_data: AuthUserData,
|
|
tokens: OAuthTokens,
|
|
) -> tuple[UUID, UUID]:
|
|
"""Create or update user and store auth tokens.
|
|
|
|
Args:
|
|
uow: Unit of work for database operations.
|
|
user_data: User identity data from OAuth provider.
|
|
tokens: OAuth tokens to store.
|
|
|
|
Returns:
|
|
Tuple of (user_id, workspace_id).
|
|
"""
|
|
user_id = await get_or_create_user_id(uow, user_data.email, user_data.display_name)
|
|
workspace_id = await get_or_create_default_workspace_id(uow, user_id)
|
|
integration = await get_or_create_auth_integration(
|
|
uow,
|
|
AuthIntegrationContext(
|
|
provider=user_data.provider,
|
|
workspace_id=workspace_id,
|
|
user_id=user_id,
|
|
provider_email=user_data.email,
|
|
),
|
|
)
|
|
await store_integration_tokens(uow, integration, tokens)
|
|
await uow.commit()
|
|
|
|
return user_id, workspace_id
|
|
|
|
async def load_auth_integration(
|
|
self,
|
|
uow: UnitOfWork,
|
|
provider: str,
|
|
) -> Integration | None:
|
|
"""Load auth integration for a provider."""
|
|
return await uow.integrations.get_by_provider(
|
|
provider=provider,
|
|
integration_type=IntegrationType.AUTH.value,
|
|
)
|
|
|
|
async def delete_integration(
|
|
self,
|
|
uow: UnitOfWork,
|
|
integration_id: UUID,
|
|
) -> None:
|
|
"""Delete an auth integration."""
|
|
await uow.integrations.delete(integration_id)
|
|
await uow.commit()
|