fix(audit): P0-P3 audit fixes — 838 ruff errors → 0, 30 F821 bugs fixed, 118 files changed
- P0: hooks.py 3-tuple fix, trigger_dispatcher Contract, contacts/plugin unregister_actions_by_owner - P0: 5 test files — check_permission mocks removed, hardcoded DB credential → env var - P1: attachment_service DmsFile via Contract helper, restore_registry/history_hooks dedup - P1: mail/plugin restore unregister, mcp_client datetime.now(UTC), saved_views/filters patterns - P1: ProtectedRoute fail-closed, 13 test assertion fixes (bcrypt, DB-URLs, SECRET_KEYs) - P2: deprecated notifications → post_system_message (3 files), forgejo Base, report_generator lazy import - P2: webhooks permissions, deps.py/roles.py plugin perms removed, import_export default - P2: address/tags/entity_links patterns removed, worker.py Contract-Umgehungen fixed - P2: 28 frontend TODOs (hardcoded constants, deprecated notification API) - P3: dead code, duplicates, deprecated imports, private attr, __import__ inline - P3: 8 frontend TODOs (LucideIcons, inline styles, XSS, i18n) - ruff: 838 → 0 (612 auto-fix + 246 manual + 27 F821 regression fix) - F821: 30 → 0 (AutomationDefinition, DmsFile, user_id, Path, Any, String) - Contract-Umgehungen: 2 neue gefunden (worker.py:169, worker.py:280) und gefixt
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
from app.plugins.builtins.contacts.plugin import ContactsPlugin
|
||||
|
||||
__all__ = ["ContactsPlugin"]
|
||||
@@ -0,0 +1,95 @@
|
||||
"""Contacts plugin — Core CRM entity lifecycle management.
|
||||
|
||||
Registers Contact entity models, permissions, restore config, and history hooks
|
||||
via the same plugin lifecycle as all other business plugins. No Core special case.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from app.plugins.base import BasePlugin
|
||||
from app.plugins.manifest import PluginManifest
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ContactsPlugin(BasePlugin):
|
||||
"""Contacts plugin — manages Contact entity lifecycle (models, permissions, restore, history).
|
||||
|
||||
Routes remain in app/routes/contacts.py as core routes, but entity lifecycle
|
||||
(permissions, entity models, restore, history) is managed through on_activate/on_deactivate.
|
||||
"""
|
||||
|
||||
manifest = PluginManifest(
|
||||
name="contacts",
|
||||
version="1.0.0",
|
||||
display_name="Contacts",
|
||||
description="Core CRM contacts — persons and companies.",
|
||||
dependencies=[],
|
||||
routes=[], # Routes are registered as core routes in main.py
|
||||
events=[],
|
||||
migrations=[],
|
||||
permissions=[
|
||||
"contacts:read",
|
||||
"contacts:write",
|
||||
"contacts:delete",
|
||||
],
|
||||
is_core=True,
|
||||
author="LeoCRM Team",
|
||||
min_app_version="1.0.0",
|
||||
contract_version="1.0.0",
|
||||
)
|
||||
|
||||
def get_entity_models(self) -> dict[str, type]:
|
||||
from app.models.contact import Contact
|
||||
return {
|
||||
"contact": Contact,
|
||||
"contacts": Contact,
|
||||
"company": Contact,
|
||||
}
|
||||
|
||||
async def on_activate(self, db, service_container, event_bus) -> None:
|
||||
"""Activate: register restore config + history hooks for Contact."""
|
||||
await super().on_activate(db, service_container, event_bus)
|
||||
|
||||
# Register restore config for Contact entities
|
||||
from app.core.restore_registry import RestoreConfig, get_restore_registry
|
||||
from app.models.contact import Contact
|
||||
get_restore_registry().register(RestoreConfig(
|
||||
entity_type="contact",
|
||||
model_class=Contact,
|
||||
restore_permission="contacts:write",
|
||||
excluded_fields=frozenset({
|
||||
"search_tsv", "embedding", "default_person_id", "admin_contactperson_id",
|
||||
}),
|
||||
))
|
||||
|
||||
# Register history hooks for Contact entities
|
||||
from app.core.history_hooks import register_history_hooks
|
||||
from app.core.hooks import get_hook_registry
|
||||
register_history_hooks(
|
||||
get_hook_registry(), "contact",
|
||||
"contact.after_create", "contact.after_update", "contact.after_delete",
|
||||
owner_tag="contacts",
|
||||
)
|
||||
|
||||
logger.info("Contacts plugin activated: restore + history registered")
|
||||
|
||||
async def on_deactivate(self, db, service_container, event_bus) -> None:
|
||||
"""Deactivate: unregister restore config + history hooks for Contact."""
|
||||
from app.core.restore_registry import get_restore_registry
|
||||
get_restore_registry().unregister("contact")
|
||||
|
||||
# Unregister history hooks — use owner_tag to remove only this plugin's hooks
|
||||
from app.core.hooks import get_hook_registry
|
||||
hook_reg = get_hook_registry()
|
||||
hook_reg.unregister_actions_by_owner("contact.after_create", "contacts")
|
||||
hook_reg.unregister_actions_by_owner("contact.after_update", "contacts")
|
||||
hook_reg.unregister_actions_by_owner("contact.after_delete", "contacts")
|
||||
|
||||
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)
|
||||
logger.info("Contacts plugin deactivated: restore + history unregistered")
|
||||
Reference in New Issue
Block a user