6ede33ccdb
Build and Push Docker Images / create_manifest (web, surfsense-web, , cpu) (push) Has been cancelled
Build and Push Docker Images / finalize_release (push) Has been cancelled
Obsidian Plugin Lint / lint (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / compute_version (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / verify_digests (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, , cpu) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda, cuda) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda126, cuda126) (push) Has been cancelled
63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
"""Pure request/response helpers for the notifications API.
|
|
|
|
No DB or framework objects, so these are unit-testable in isolation.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import NamedTuple
|
|
|
|
from app.notifications.api.schemas import NotificationResponse
|
|
from app.notifications.persistence import Notification
|
|
|
|
|
|
class SourceTypeFilter(NamedTuple):
|
|
"""The notification types and JSONB facet a source-type filter selects."""
|
|
|
|
types: tuple[str, ...]
|
|
metadata_key: str
|
|
value: str
|
|
|
|
|
|
def parse_source_type(source_type: str) -> SourceTypeFilter | None:
|
|
"""Decode a `connector:<type>` / `doctype:<type>` filter, or None if unknown."""
|
|
if source_type.startswith("connector:"):
|
|
return SourceTypeFilter(
|
|
types=("connector_indexing", "connector_deletion"),
|
|
metadata_key="connector_type",
|
|
value=source_type[len("connector:") :],
|
|
)
|
|
if source_type.startswith("doctype:"):
|
|
return SourceTypeFilter(
|
|
types=("document_processing",),
|
|
metadata_key="document_type",
|
|
value=source_type[len("doctype:") :],
|
|
)
|
|
return None
|
|
|
|
|
|
def parse_before_date(before_date: str) -> datetime:
|
|
"""Parse an ISO date for pagination; raises ValueError if malformed."""
|
|
return datetime.fromisoformat(before_date.replace("Z", "+00:00"))
|
|
|
|
|
|
def to_response(notification: Notification) -> NotificationResponse:
|
|
"""Map a persisted notification to its API response shape."""
|
|
return NotificationResponse(
|
|
id=notification.id,
|
|
user_id=str(notification.user_id),
|
|
workspace_id=notification.workspace_id,
|
|
type=notification.type,
|
|
title=notification.title,
|
|
message=notification.message,
|
|
read=notification.read,
|
|
metadata=notification.notification_metadata or {},
|
|
created_at=notification.created_at.isoformat()
|
|
if notification.created_at
|
|
else "",
|
|
updated_at=notification.updated_at.isoformat()
|
|
if notification.updated_at
|
|
else None,
|
|
)
|