125 lines
4.2 KiB
Python
125 lines
4.2 KiB
Python
# Copyright (c) 2025 Patrick Motsch
|
|
# All rights reserved.
|
|
"""
|
|
Neutralizer 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 = "neutralization"
|
|
FEATURE_LABEL = {"en": "Neutralization", "de": "Neutralisierung", "fr": "Neutralisation"}
|
|
FEATURE_ICON = "mdi-shield-check"
|
|
|
|
# UI Objects for RBAC catalog
|
|
UI_OBJECTS = [
|
|
{
|
|
"objectKey": "ui.feature.neutralizer.playground",
|
|
"label": {"en": "Playground", "de": "Spielwiese", "fr": "Bac à sable"},
|
|
"meta": {"area": "playground"}
|
|
},
|
|
{
|
|
"objectKey": "ui.feature.neutralizer.config",
|
|
"label": {"en": "Configuration", "de": "Konfiguration", "fr": "Configuration"},
|
|
"meta": {"area": "config"}
|
|
},
|
|
{
|
|
"objectKey": "ui.feature.neutralizer.attributes",
|
|
"label": {"en": "Attributes", "de": "Attribute", "fr": "Attributs"},
|
|
"meta": {"area": "attributes"}
|
|
},
|
|
]
|
|
|
|
# Resource Objects for RBAC catalog
|
|
RESOURCE_OBJECTS = [
|
|
{
|
|
"objectKey": "resource.feature.neutralizer.process.text",
|
|
"label": {"en": "Process Text", "de": "Text verarbeiten", "fr": "Traiter texte"},
|
|
"meta": {"endpoint": "/api/neutralization/process/text", "method": "POST"}
|
|
},
|
|
{
|
|
"objectKey": "resource.feature.neutralizer.process.files",
|
|
"label": {"en": "Process Files", "de": "Dateien verarbeiten", "fr": "Traiter fichiers"},
|
|
"meta": {"endpoint": "/api/neutralization/process/files", "method": "POST"}
|
|
},
|
|
{
|
|
"objectKey": "resource.feature.neutralizer.config.update",
|
|
"label": {"en": "Update Config", "de": "Konfiguration aktualisieren", "fr": "Mettre à jour config"},
|
|
"meta": {"endpoint": "/api/neutralization/config", "method": "PUT"}
|
|
},
|
|
]
|
|
|
|
# Template roles for this feature
|
|
TEMPLATE_ROLES = [
|
|
{
|
|
"roleLabel": "neutralization-admin",
|
|
"description": {
|
|
"en": "Neutralization Administrator - Full access to neutralization settings and data",
|
|
"de": "Neutralisierungs-Administrator - Vollzugriff auf Neutralisierungs-Einstellungen und Daten",
|
|
"fr": "Administrateur neutralisation - Accès complet aux paramètres et données"
|
|
}
|
|
},
|
|
{
|
|
"roleLabel": "neutralization-analyst",
|
|
"description": {
|
|
"en": "Neutralization Analyst - Analyze and process neutralization data",
|
|
"de": "Neutralisierungs-Analyst - Neutralisierungsdaten analysieren und verarbeiten",
|
|
"fr": "Analyste neutralisation - Analyser et traiter les données de neutralisation"
|
|
}
|
|
},
|
|
]
|
|
|
|
|
|
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."""
|
|
try:
|
|
for uiObj in UI_OBJECTS:
|
|
catalogService.registerUiObject(
|
|
featureCode=FEATURE_CODE,
|
|
objectKey=uiObj["objectKey"],
|
|
label=uiObj["label"],
|
|
meta=uiObj.get("meta")
|
|
)
|
|
|
|
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
|