193 lines
7.3 KiB
Python
193 lines
7.3 KiB
Python
# Copyright (c) 2025 Patrick Motsch
|
|
# All rights reserved.
|
|
"""
|
|
Trustee Feature Container - Main Module.
|
|
Handles feature initialization and RBAC catalog registration.
|
|
"""
|
|
|
|
import logging
|
|
from typing import Dict, List, Any
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# Feature metadata
|
|
FEATURE_CODE = "trustee"
|
|
FEATURE_LABEL = {"en": "Trustee", "de": "Treuhand", "fr": "Fiduciaire"}
|
|
FEATURE_ICON = "mdi-briefcase"
|
|
|
|
# UI Objects for RBAC catalog
|
|
UI_OBJECTS = [
|
|
{
|
|
"objectKey": "ui.feature.trustee.organisations",
|
|
"label": {"en": "Organisations", "de": "Organisationen", "fr": "Organisations"},
|
|
"meta": {"area": "organisations"}
|
|
},
|
|
{
|
|
"objectKey": "ui.feature.trustee.contracts",
|
|
"label": {"en": "Contracts", "de": "Verträge", "fr": "Contrats"},
|
|
"meta": {"area": "contracts"}
|
|
},
|
|
{
|
|
"objectKey": "ui.feature.trustee.contracts.tab.documents",
|
|
"label": {"en": "Contract Documents", "de": "Vertragsdokumente", "fr": "Documents contractuels"},
|
|
"meta": {"area": "contracts", "element": "tab.documents"}
|
|
},
|
|
{
|
|
"objectKey": "ui.feature.trustee.contracts.tab.positions",
|
|
"label": {"en": "Contract Positions", "de": "Vertragspositionen", "fr": "Positions contractuelles"},
|
|
"meta": {"area": "contracts", "element": "tab.positions"}
|
|
},
|
|
{
|
|
"objectKey": "ui.feature.trustee.access",
|
|
"label": {"en": "Access Management", "de": "Zugriffsverwaltung", "fr": "Gestion des accès"},
|
|
"meta": {"area": "access"}
|
|
},
|
|
{
|
|
"objectKey": "ui.feature.trustee.roles",
|
|
"label": {"en": "Roles", "de": "Rollen", "fr": "Rôles"},
|
|
"meta": {"area": "roles"}
|
|
},
|
|
]
|
|
|
|
# Resource Objects for RBAC catalog
|
|
RESOURCE_OBJECTS = [
|
|
{
|
|
"objectKey": "resource.feature.trustee.organisations.create",
|
|
"label": {"en": "Create Organisation", "de": "Organisation erstellen", "fr": "Créer organisation"},
|
|
"meta": {"endpoint": "/api/trustee/{instanceId}/organisations", "method": "POST"}
|
|
},
|
|
{
|
|
"objectKey": "resource.feature.trustee.organisations.update",
|
|
"label": {"en": "Update Organisation", "de": "Organisation aktualisieren", "fr": "Modifier organisation"},
|
|
"meta": {"endpoint": "/api/trustee/{instanceId}/organisations/{orgId}", "method": "PUT"}
|
|
},
|
|
{
|
|
"objectKey": "resource.feature.trustee.organisations.delete",
|
|
"label": {"en": "Delete Organisation", "de": "Organisation löschen", "fr": "Supprimer organisation"},
|
|
"meta": {"endpoint": "/api/trustee/{instanceId}/organisations/{orgId}", "method": "DELETE"}
|
|
},
|
|
{
|
|
"objectKey": "resource.feature.trustee.contracts.create",
|
|
"label": {"en": "Create Contract", "de": "Vertrag erstellen", "fr": "Créer contrat"},
|
|
"meta": {"endpoint": "/api/trustee/{instanceId}/contracts", "method": "POST"}
|
|
},
|
|
{
|
|
"objectKey": "resource.feature.trustee.contracts.update",
|
|
"label": {"en": "Update Contract", "de": "Vertrag aktualisieren", "fr": "Modifier contrat"},
|
|
"meta": {"endpoint": "/api/trustee/{instanceId}/contracts/{contractId}", "method": "PUT"}
|
|
},
|
|
{
|
|
"objectKey": "resource.feature.trustee.contracts.delete",
|
|
"label": {"en": "Delete Contract", "de": "Vertrag löschen", "fr": "Supprimer contrat"},
|
|
"meta": {"endpoint": "/api/trustee/{instanceId}/contracts/{contractId}", "method": "DELETE"}
|
|
},
|
|
{
|
|
"objectKey": "resource.feature.trustee.documents.create",
|
|
"label": {"en": "Upload Document", "de": "Dokument hochladen", "fr": "Télécharger document"},
|
|
"meta": {"endpoint": "/api/trustee/{instanceId}/documents", "method": "POST"}
|
|
},
|
|
{
|
|
"objectKey": "resource.feature.trustee.documents.delete",
|
|
"label": {"en": "Delete Document", "de": "Dokument löschen", "fr": "Supprimer document"},
|
|
"meta": {"endpoint": "/api/trustee/{instanceId}/documents/{documentId}", "method": "DELETE"}
|
|
},
|
|
{
|
|
"objectKey": "resource.feature.trustee.positions.create",
|
|
"label": {"en": "Create Position", "de": "Position erstellen", "fr": "Créer position"},
|
|
"meta": {"endpoint": "/api/trustee/{instanceId}/positions", "method": "POST"}
|
|
},
|
|
{
|
|
"objectKey": "resource.feature.trustee.positions.delete",
|
|
"label": {"en": "Delete Position", "de": "Position löschen", "fr": "Supprimer position"},
|
|
"meta": {"endpoint": "/api/trustee/{instanceId}/positions/{positionId}", "method": "DELETE"}
|
|
},
|
|
]
|
|
|
|
# Template roles for this feature
|
|
TEMPLATE_ROLES = [
|
|
{
|
|
"roleLabel": "trustee-admin",
|
|
"description": {
|
|
"en": "Trustee Administrator - Full access to all trustee data and settings",
|
|
"de": "Treuhand-Administrator - Vollzugriff auf alle Treuhand-Daten und Einstellungen",
|
|
"fr": "Administrateur fiduciaire - Accès complet aux données et paramètres fiduciaires"
|
|
}
|
|
},
|
|
{
|
|
"roleLabel": "trustee-accountant",
|
|
"description": {
|
|
"en": "Trustee Accountant - Manage accounting and financial data",
|
|
"de": "Treuhand-Buchhalter - Buchhaltungs- und Finanzdaten verwalten",
|
|
"fr": "Comptable fiduciaire - Gérer les données comptables et financières"
|
|
}
|
|
},
|
|
{
|
|
"roleLabel": "trustee-client",
|
|
"description": {
|
|
"en": "Trustee Client - View own accounting data and documents",
|
|
"de": "Treuhand-Kunde - Eigene Buchhaltungsdaten und Dokumente einsehen",
|
|
"fr": "Client fiduciaire - Consulter ses propres données comptables et documents"
|
|
}
|
|
},
|
|
]
|
|
|
|
|
|
def getFeatureDefinition() -> Dict[str, Any]:
|
|
"""Return the feature definition for registration."""
|
|
return {
|
|
"code": FEATURE_CODE,
|
|
"label": FEATURE_LABEL,
|
|
"icon": FEATURE_ICON
|
|
}
|
|
|
|
|
|
def getUiObjects() -> List[Dict[str, Any]]:
|
|
"""Return UI objects for RBAC catalog registration."""
|
|
return UI_OBJECTS
|
|
|
|
|
|
def getResourceObjects() -> List[Dict[str, Any]]:
|
|
"""Return resource objects for RBAC catalog registration."""
|
|
return RESOURCE_OBJECTS
|
|
|
|
|
|
def getTemplateRoles() -> List[Dict[str, Any]]:
|
|
"""Return template roles for this feature."""
|
|
return TEMPLATE_ROLES
|
|
|
|
|
|
def registerFeature(catalogService) -> bool:
|
|
"""
|
|
Register this feature's RBAC objects in the catalog.
|
|
|
|
Args:
|
|
catalogService: The RBAC catalog service instance
|
|
|
|
Returns:
|
|
True if registration was successful
|
|
"""
|
|
try:
|
|
# Register UI objects
|
|
for uiObj in UI_OBJECTS:
|
|
catalogService.registerUiObject(
|
|
featureCode=FEATURE_CODE,
|
|
objectKey=uiObj["objectKey"],
|
|
label=uiObj["label"],
|
|
meta=uiObj.get("meta")
|
|
)
|
|
|
|
# Register Resource objects
|
|
for resObj in RESOURCE_OBJECTS:
|
|
catalogService.registerResourceObject(
|
|
featureCode=FEATURE_CODE,
|
|
objectKey=resObj["objectKey"],
|
|
label=resObj["label"],
|
|
meta=resObj.get("meta")
|
|
)
|
|
|
|
logger.info(f"Feature '{FEATURE_CODE}' registered {len(UI_OBJECTS)} UI objects and {len(RESOURCE_OBJECTS)} resource objects")
|
|
return True
|
|
|
|
except Exception as e:
|
|
logger.error(f"Failed to register feature '{FEATURE_CODE}': {e}")
|
|
return False
|