c25356c257
Check Cross-Plugin Imports / check (push) Has been cancelled
- workspace_scopes() Contract-Hook (document_placeholders-Muster): Plugins deklarieren Scope-Dimensionen inkl. Wertequellen
- Deklarationen: contacts (Ordner/Typen/Saved-View), dms (Ordner/Datei-Typen), mail (Postfächer), calendar (Kalender/Standard-Ansicht)
- Pydantic fail-closed (schemas/workspace.py): ScopeOption, ScopeValueSource (nur interne /api/v1-Pfade, SSRF-sicher), WorkspaceScopeDimension, WorkspaceModuleScopes
- Aggregator workspace_scope_service.py: discovered-Plugins, ARCH-014-safe, Crash-sicher, ungültige Deklarationen verworfen
- GET /api/v1/workspaces/scope-definitions (workspaces:configure_modules) vor /{workspace_id} registriert
- Security-Invariante: Scope = reine UND-Einschränkung (Workspace ∧ RLS ∧ ABAC ∧ Permissions)
- Tests: 18/18 neu (TDD rot→grün), Regression 17/17, Checker 0 Verstöße, Ruff clean
- Doku: api-documentation.md Workspaces-Sektion, PROGRESS.md Phase N1
108 lines
3.5 KiB
Python
108 lines
3.5 KiB
Python
"""Calendar plugin contract — public interface for cross-plugin access."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.plugins.builtins.calendar.models import Calendar, CalendarEntry, CalendarEntryLink
|
|
from app.plugins.builtins.contracts import get_contract_registry
|
|
|
|
|
|
class CalendarContract:
|
|
"""Public contract for the calendar plugin."""
|
|
|
|
contract_name = "calendar"
|
|
|
|
Calendar = Calendar
|
|
CalendarEntry = CalendarEntry
|
|
CalendarEntryLink = CalendarEntryLink
|
|
|
|
@staticmethod
|
|
async def dsar_collect(
|
|
db: AsyncSession, tenant_id: Any, user_id: Any
|
|
) -> dict[str, Any]:
|
|
"""GDPR Art. 15: collect calendar entries owned by the user."""
|
|
cal_entries = (
|
|
await db.execute(
|
|
select(CalendarEntry).where(
|
|
CalendarEntry.tenant_id == tenant_id,
|
|
CalendarEntry.owner_id == user_id,
|
|
CalendarEntry.deleted_at.is_(None),
|
|
).limit(1000)
|
|
)
|
|
).scalars().all()
|
|
return {
|
|
"calendar_entries": [
|
|
{
|
|
"id": str(e.id),
|
|
"title": e.title,
|
|
"entry_type": e.entry_type,
|
|
"start_at": e.start_at.isoformat() if e.start_at else None,
|
|
"end_at": e.end_at.isoformat() if e.end_at else None,
|
|
}
|
|
for e in cal_entries
|
|
]
|
|
}
|
|
|
|
# ─── Workspace Scopes contribution (Phase N1, #359 pattern) ───
|
|
|
|
@staticmethod
|
|
def workspace_scopes() -> list[dict]:
|
|
"""Scope-Dimensionen des calendar-Moduls für den Workspace-Editor (N1)."""
|
|
return [
|
|
{
|
|
"module_key": "calendar",
|
|
"dimensions": [
|
|
{
|
|
"key": "calendar_ids",
|
|
"label": "Kalender",
|
|
"control": "multiselect",
|
|
"value_source": {
|
|
"endpoint": "/api/v1/calendars",
|
|
"items_path": "",
|
|
"value_key": "id",
|
|
"label_key": "name",
|
|
},
|
|
},
|
|
{
|
|
"key": "default_view",
|
|
"label": "Standard-Ansicht",
|
|
"control": "select",
|
|
"options": [
|
|
{"value": "day", "label": "Tag"},
|
|
{"value": "week", "label": "Woche"},
|
|
{"value": "month", "label": "Monat"},
|
|
{"value": "range", "label": "Zeitraum"},
|
|
],
|
|
},
|
|
],
|
|
}
|
|
]
|
|
|
|
@classmethod
|
|
def get_function(cls, name: str):
|
|
"""Return a callable exposed by this contract, or None if absent."""
|
|
return getattr(cls, name, None)
|
|
|
|
|
|
# ─── self-registration ───
|
|
|
|
_contract = CalendarContract()
|
|
get_contract_registry().register("calendar", _contract)
|
|
|
|
# Backward-compatible local accessor
|
|
_contract_instance: CalendarContract | None = None
|
|
|
|
|
|
def get_contract() -> CalendarContract:
|
|
global _contract_instance
|
|
if _contract_instance is None:
|
|
_contract_instance = CalendarContract()
|
|
return _contract_instance
|
|
|
|
|
|
__all__ = ["CalendarContract", "Calendar", "CalendarEntry", "CalendarEntryLink"]
|