98eb1d0d89
Check Cross-Plugin Imports / check (push) Has been cancelled
Phase 1: Contracts konsequent nutzen - 12 neue contracts.py erstellt (alle 19 Plugins haben jetzt contracts) - 4 bestehende contracts.py an zentrale ContractRegistry angepasst - Alle 19 Plugins haben on_deactivate mit Contract-Unregister - 0 echte problematische INTER-Plugin Imports Phase 2: Hooks/Filters-System - app/core/hooks.py (HookRegistry mit actions + filters) - 15 Hook-Punkte in Core-Services (contact, auth, mail, calendar, user, dms) - BasePlugin.on_deactivate meldet alle Hooks ab Phase 3: Plugin-Isolation - scripts/check_cross_plugin_imports.py (Linting-Regel) - .github/workflows/check-cross-plugin-imports.yml (CI/CD) - .pre-commit-cross-plugin.yaml (Pre-commit Hook) - 155 Dateien geprueft, 0 Verstoesse Phase 4: Plugin-Versioning - app/plugins/semver.py (SemVer mit Parse, Compare, Pre-release) - migration_runner.py erweitert: run_migration_down, rollback_to_version - manifest.py: min_app_version Feld - registry.py: App-Version-Compatibility-Check bei Installation - GET /api/v1/plugins/updates Endpoint Phase 5: Marketplace-Vorbereitung - app/plugins/signature.py (Ed25519 Signatur-Validierung) - app/plugins/quarantine.py (Plugin-Quarantine mit Validierung) - app/models/plugin_allowlist.py + Migration 0046 - manifest.py: author, license, homepage, icon, screenshots, changelog, marketplace_tags, price - registry.py: discover_external(), discover_all() - POST /api/v1/plugins/install-marketplace (deaktiviert) Phase 6: Manifest-Anpassung - manifest.py: 12 neue Felder + SemVer/Hook-Name Validierung - MANIFEST_SCHEMA_DOC aktualisiert - Alle 19 Plugin-Manifeste aktualisiert - Frontend PluginUiManifest Typ erweitert Zusaetzliche Bug-Fixes: - test_sample-Modul erstellt - conftest.py Deadlock-Prevention - SESSION_COOKIE_SECURE=true - dump.rdb aus Git entfernt + .gitignore - backup.py datetime.utcnow -> func.now() - system_settings.py JSONB-Import nach oben - tax.py Mapped[float] -> Mapped[Decimal] - notification.py type_key-Laengen vereinheitlicht Tests: 91 neue Tests, alle bestanden
81 lines
3.0 KiB
Python
81 lines
3.0 KiB
Python
"""Entity Links plugin — link files to companies/contacts, reverse links, event cleanup."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from app.plugins.base import BasePlugin
|
|
from app.plugins.manifest import PluginManifest, PluginRouteDef, FrontendDetailTab
|
|
|
|
|
|
class EntityLinksPlugin(BasePlugin):
|
|
"""Entity Links plugin for N:M file-to-entity links with event-driven cleanup."""
|
|
|
|
manifest = PluginManifest(
|
|
name="entity_links",
|
|
version="1.0.0",
|
|
display_name="Entity Links",
|
|
description="Link files to companies/contacts (N:M), reverse links, event cleanup on deletion.",
|
|
dependencies=[],
|
|
routes=[
|
|
PluginRouteDef(
|
|
path="/api/v1/entity-links",
|
|
module="app.plugins.builtins.entity_links.routes",
|
|
router_attr="router",
|
|
),
|
|
PluginRouteDef(
|
|
path="/api/v1/contacts",
|
|
module="app.plugins.builtins.entity_links.routes",
|
|
router_attr="contact_router",
|
|
),
|
|
],
|
|
events=["contact.deleted"],
|
|
migrations=["0001_initial.sql", "0002_add_deleted_at.sql"],
|
|
permissions=[
|
|
"entity_links:read",
|
|
"entity_links:write",
|
|
"entity_links:delete",
|
|
],
|
|
is_core=True,
|
|
detail_tabs=[
|
|
FrontendDetailTab(entity_type='contact', label_key='tabs.links', label='Verknüpfungen', component='@/components/contact/ContactLinksTab', icon='Link', order=60, permission='entity_links:read'),
|
|
],
|
|
|
|
author="LeoCRM Team",
|
|
min_app_version="1.0.0",
|
|
contract_version="1.0.0")
|
|
|
|
async def on_contact_deleted(self, payload: dict[str, Any]) -> None:
|
|
"""Handle contact.deleted event — remove all EntityLink rows for that contact."""
|
|
from sqlalchemy import delete
|
|
|
|
from app.core.db import get_session_factory
|
|
from app.plugins.builtins.entity_links.models import EntityLink
|
|
|
|
entity_id = payload.get("entity_id") or payload.get("contact_id")
|
|
tenant_id = payload.get("tenant_id")
|
|
if entity_id is None or tenant_id is None:
|
|
return
|
|
|
|
import uuid as _uuid
|
|
|
|
factory = get_session_factory()
|
|
async with factory() as session:
|
|
await session.execute(
|
|
delete(EntityLink).where(
|
|
EntityLink.tenant_id == _uuid.UUID(tenant_id),
|
|
EntityLink.entity_type == "contact",
|
|
EntityLink.entity_id == _uuid.UUID(str(entity_id)),
|
|
)
|
|
)
|
|
await session.commit()
|
|
|
|
async def on_deactivate(
|
|
self, db, service_container, event_bus
|
|
) -> None:
|
|
"""Deactivate plugin: unregister contract and event listeners."""
|
|
# Contract abmelden
|
|
from app.plugins.builtins.contracts import get_contract_registry
|
|
get_contract_registry().unregister(self.manifest.name)
|
|
await super().on_deactivate(db, service_container, event_bus)
|