169 lines
6.3 KiB
Python
169 lines
6.3 KiB
Python
# Copyright (c) 2025 Patrick Motsch
|
|
# All rights reserved.
|
|
"""
|
|
Automation 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 = "automation"
|
|
FEATURE_LABEL = {"en": "Automation", "de": "Automatisierung", "fr": "Automatisation"}
|
|
FEATURE_ICON = "mdi-cog-clockwise"
|
|
|
|
# UI Objects for RBAC catalog
|
|
UI_OBJECTS = [
|
|
{
|
|
"objectKey": "ui.feature.automation.definitions",
|
|
"label": {"en": "Automation Definitions", "de": "Automatisierungs-Definitionen", "fr": "Définitions d'automatisation"},
|
|
"meta": {"area": "definitions"}
|
|
},
|
|
{
|
|
"objectKey": "ui.feature.automation.templates",
|
|
"label": {"en": "Templates", "de": "Vorlagen", "fr": "Modèles"},
|
|
"meta": {"area": "templates"}
|
|
},
|
|
{
|
|
"objectKey": "ui.feature.automation.logs",
|
|
"label": {"en": "Execution Logs", "de": "Ausführungsprotokolle", "fr": "Journaux d'exécution"},
|
|
"meta": {"area": "logs"}
|
|
},
|
|
]
|
|
|
|
# Resource Objects for RBAC catalog
|
|
RESOURCE_OBJECTS = [
|
|
{
|
|
"objectKey": "resource.feature.automation.create",
|
|
"label": {"en": "Create Automation", "de": "Automatisierung erstellen", "fr": "Créer automatisation"},
|
|
"meta": {"endpoint": "/api/automations", "method": "POST"}
|
|
},
|
|
{
|
|
"objectKey": "resource.feature.automation.update",
|
|
"label": {"en": "Update Automation", "de": "Automatisierung aktualisieren", "fr": "Modifier automatisation"},
|
|
"meta": {"endpoint": "/api/automations/{automationId}", "method": "PUT"}
|
|
},
|
|
{
|
|
"objectKey": "resource.feature.automation.delete",
|
|
"label": {"en": "Delete Automation", "de": "Automatisierung löschen", "fr": "Supprimer automatisation"},
|
|
"meta": {"endpoint": "/api/automations/{automationId}", "method": "DELETE"}
|
|
},
|
|
{
|
|
"objectKey": "resource.feature.automation.execute",
|
|
"label": {"en": "Execute Automation", "de": "Automatisierung ausführen", "fr": "Exécuter automatisation"},
|
|
"meta": {"endpoint": "/api/automations/{automationId}/execute", "method": "POST"}
|
|
},
|
|
]
|
|
|
|
# Template roles for this feature
|
|
TEMPLATE_ROLES = [
|
|
{
|
|
"roleLabel": "automation-admin",
|
|
"description": {
|
|
"en": "Automation Administrator - Full access to automation configuration and execution",
|
|
"de": "Automatisierungs-Administrator - Vollzugriff auf Automatisierungs-Konfiguration und Ausführung",
|
|
"fr": "Administrateur automatisation - Accès complet à la configuration et exécution"
|
|
},
|
|
"accessRules": [
|
|
# Full UI access
|
|
{"context": "UI", "item": None, "view": True},
|
|
# Full DATA access
|
|
{"context": "DATA", "item": None, "view": True, "read": "a", "create": "a", "update": "a", "delete": "a"},
|
|
]
|
|
},
|
|
{
|
|
"roleLabel": "automation-editor",
|
|
"description": {
|
|
"en": "Automation Editor - Create and modify automations",
|
|
"de": "Automatisierungs-Editor - Automatisierungen erstellen und bearbeiten",
|
|
"fr": "Éditeur automatisation - Créer et modifier les automatisations"
|
|
},
|
|
"accessRules": [
|
|
# UI access to definitions and templates - vollqualifizierte ObjectKeys
|
|
{"context": "UI", "item": "ui.feature.automation.definitions", "view": True},
|
|
{"context": "UI", "item": "ui.feature.automation.templates", "view": True},
|
|
{"context": "UI", "item": "ui.feature.automation.logs", "view": True},
|
|
# Group-level DATA access
|
|
{"context": "DATA", "item": None, "view": True, "read": "g", "create": "g", "update": "g", "delete": "n"},
|
|
]
|
|
},
|
|
{
|
|
"roleLabel": "automation-viewer",
|
|
"description": {
|
|
"en": "Automation Viewer - View automations and execution results",
|
|
"de": "Automatisierungs-Betrachter - Automatisierungen und Ausführungsergebnisse einsehen",
|
|
"fr": "Visualiseur automatisation - Consulter les automatisations et résultats"
|
|
},
|
|
"accessRules": [
|
|
# UI access to view only - vollqualifizierte ObjectKeys
|
|
{"context": "UI", "item": "ui.feature.automation.definitions", "view": True},
|
|
{"context": "UI", "item": "ui.feature.automation.logs", "view": True},
|
|
# Read-only DATA access (my level)
|
|
{"context": "DATA", "item": None, "view": True, "read": "m", "create": "n", "update": "n", "delete": "n"},
|
|
]
|
|
},
|
|
]
|
|
|
|
|
|
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
|