From 3470dba301a4a89c914610dedc059ec31703f53f Mon Sep 17 00:00:00 2001 From: bsiggel Date: Tue, 10 Mar 2026 00:10:57 +0100 Subject: [PATCH] Add junction entities and ACL for CAICollection, CAdvowareAkten, and CPulsTeam - Introduced new junction entities: CAICollectionCDokumente, CAdvowareAktenCDokumente, and CPulsTeamZuordnung. - Implemented respective controllers and services for handling CRUD operations. - Added metadata definitions for new entities, including fields, links, and indexes. - Created language files for English and German translations for the new entities. - Developed a script to set ACL permissions for the new junction entities across existing roles. - Updated existing entity definitions to include new relationships and fields related to Advoware and AI Collections. --- .../Controllers/CAICollectionCDokumente.php | 23 +++ .../Controllers/CAdvowareAktenCDokumente.php | 23 +++ .../Resources/i18n/de_DE/CAICollection.json | 12 +- .../i18n/de_DE/CAICollectionCDokumente.json | 31 ++++ .../Resources/i18n/de_DE/CAdvowareAkten.json | 7 +- .../i18n/de_DE/CAdvowareAktenCDokumente.json | 31 ++++ .../Resources/i18n/de_DE/CDokumente.json | 4 +- .../Resources/i18n/de_DE/CMietinkasso.json | 12 +- .../i18n/de_DE/CPulsTeamZuordnung.json | 27 ++++ .../i18n/de_DE/CVmhRumungsklage.json | 12 +- .../Resources/i18n/en_US/CAICollection.json | 9 +- .../i18n/en_US/CAICollectionCDokumente.json | 31 ++++ .../Resources/i18n/en_US/CAdvowareAkten.json | 6 +- .../i18n/en_US/CAdvowareAktenCDokumente.json | 31 ++++ .../Resources/i18n/en_US/CDokumente.json | 4 +- .../Resources/i18n/en_US/CMietinkasso.json | 12 +- .../i18n/en_US/CPulsTeamZuordnung.json | 27 ++++ .../i18n/en_US/CVmhRumungsklage.json | 12 +- .../metadata/entityDefs/CAICollection.json | 36 +++++ .../entityDefs/CAICollectionCDokumente.json | 87 ++++++++++ .../metadata/entityDefs/CAdvowareAkten.json | 36 +++++ .../entityDefs/CAdvowareAktenCDokumente.json | 83 ++++++++++ .../metadata/entityDefs/CDokumente.json | 36 +++++ .../metadata/entityDefs/CMietinkasso.json | 32 +++- .../entityDefs/CPulsTeamZuordnung.json | 68 ++++++++ .../metadata/entityDefs/CVmhRumungsklage.json | 30 ++++ .../scopes/CAICollectionCDokumente.json | 10 ++ .../scopes/CAdvowareAktenCDokumente.json | 10 ++ .../metadata/scopes/CPulsTeamZuordnung.json | 10 ++ .../Services/CAICollectionCDokumente.php | 14 ++ .../Services/CAdvowareAktenCDokumente.php | 14 ++ custom/scripts/set_junction_acl.php | 152 ++++++++++++++++++ data/config.php | 2 +- data/state.php | 4 +- 34 files changed, 920 insertions(+), 18 deletions(-) create mode 100644 custom/Espo/Custom/Controllers/CAICollectionCDokumente.php create mode 100644 custom/Espo/Custom/Controllers/CAdvowareAktenCDokumente.php create mode 100644 custom/Espo/Custom/Resources/i18n/de_DE/CAICollectionCDokumente.json create mode 100644 custom/Espo/Custom/Resources/i18n/de_DE/CAdvowareAktenCDokumente.json create mode 100644 custom/Espo/Custom/Resources/i18n/de_DE/CPulsTeamZuordnung.json create mode 100644 custom/Espo/Custom/Resources/i18n/en_US/CAICollectionCDokumente.json create mode 100644 custom/Espo/Custom/Resources/i18n/en_US/CAdvowareAktenCDokumente.json create mode 100644 custom/Espo/Custom/Resources/i18n/en_US/CPulsTeamZuordnung.json create mode 100644 custom/Espo/Custom/Resources/metadata/entityDefs/CAICollectionCDokumente.json create mode 100644 custom/Espo/Custom/Resources/metadata/entityDefs/CAdvowareAktenCDokumente.json create mode 100644 custom/Espo/Custom/Resources/metadata/entityDefs/CPulsTeamZuordnung.json create mode 100644 custom/Espo/Custom/Resources/metadata/scopes/CAICollectionCDokumente.json create mode 100644 custom/Espo/Custom/Resources/metadata/scopes/CAdvowareAktenCDokumente.json create mode 100644 custom/Espo/Custom/Resources/metadata/scopes/CPulsTeamZuordnung.json create mode 100644 custom/Espo/Custom/Services/CAICollectionCDokumente.php create mode 100644 custom/Espo/Custom/Services/CAdvowareAktenCDokumente.php create mode 100755 custom/scripts/set_junction_acl.php diff --git a/custom/Espo/Custom/Controllers/CAICollectionCDokumente.php b/custom/Espo/Custom/Controllers/CAICollectionCDokumente.php new file mode 100644 index 00000000..b1fe1273 --- /dev/null +++ b/custom/Espo/Custom/Controllers/CAICollectionCDokumente.php @@ -0,0 +1,23 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + echo "================================================================\n"; + echo " ACL-Berechtigungen für Junction Entities setzen\n"; + echo "================================================================\n\n"; + + // Entities, für die ACL-Berechtigungen gesetzt werden sollen + $entities = [ + 'CAdvowareAktenCDokumente' => 'Advoware-Dokumente Junction', + 'CAICollectionCDokumente' => 'AI Collection-Dokumente Junction', + 'CPulsTeamZuordnung' => 'Puls-Team-Zuordnung' + ]; + + // Hole alle Rollen + $stmt = $pdo->query("SELECT id, name, data FROM role WHERE deleted = 0"); + $roles = $stmt->fetchAll(PDO::FETCH_ASSOC); + + echo "Gefundene Rollen: " . count($roles) . "\n\n"; + + $updatedCount = 0; + + foreach ($roles as $role) { + $roleName = $role['name']; + $roleId = $role['id']; + $data = json_decode($role['data'], true); + + // Prüfe ob ACL-Daten existieren + if (!isset($data['table'])) { + $data['table'] = []; + } + + $hasChanges = false; + + // Füge ACL für jede Entity hinzu + foreach ($entities as $entity => $description) { + if (!isset($data['table'][$entity])) { + // Setze Standard-Berechtigungen basierend auf der Rolle + if (stripos($roleName, 'admin') !== false) { + // Administrator: Volle Rechte + $data['table'][$entity] = [ + 'create' => 'yes', + 'read' => 'all', + 'edit' => 'all', + 'delete' => 'all' + ]; + } else { + // Andere Rollen: Leserechte + $data['table'][$entity] = [ + 'create' => 'yes', + 'read' => 'own', + 'edit' => 'own', + 'delete' => 'no' + ]; + } + $hasChanges = true; + echo " ✓ {$entity} zu Rolle '{$roleName}' hinzugefügt\n"; + } + } + + // Speichere nur wenn Änderungen vorgenommen wurden + if ($hasChanges) { + $jsonData = json_encode($data, JSON_UNESCAPED_UNICODE); + $updateStmt = $pdo->prepare("UPDATE role SET data = :data WHERE id = :id"); + $updateStmt->execute([ + ':data' => $jsonData, + ':id' => $roleId + ]); + $updatedCount++; + echo " → Rolle '{$roleName}' aktualisiert\n\n"; + } + } + + echo "================================================================\n"; + echo " ZUSAMMENFASSUNG\n"; + echo "================================================================\n\n"; + echo "✅ {$updatedCount} von " . count($roles) . " Rollen aktualisiert\n\n"; + + if ($updatedCount > 0) { + echo "Hinweis: Cache muss geleert werden!\n"; + echo "Führe aus: python3 custom/scripts/validate_and_rebuild.py\n\n"; + } else { + echo "ℹ Keine Änderungen notwendig - alle Rollen haben bereits ACL für diese Entities\n\n"; + } + + // Zeige ACL-Status + echo "================================================================\n"; + echo " ACL-STATUS PRO ROLLE\n"; + echo "================================================================\n\n"; + + foreach ($roles as $role) { + $roleName = $role['name']; + $data = json_decode($role['data'], true); + + echo "Rolle: {$roleName}\n"; + echo str_repeat("-", 60) . "\n"; + + foreach ($entities as $entity => $description) { + if (isset($data['table'][$entity])) { + $acl = $data['table'][$entity]; + echo sprintf( + " %-30s C:%-4s R:%-4s E:%-4s D:%-4s\n", + $entity, + $acl['create'] ?? 'no', + $acl['read'] ?? 'no', + $acl['edit'] ?? 'no', + $acl['delete'] ?? 'no' + ); + } else { + echo " {$entity}: ⚠ KEINE ACL\n"; + } + } + echo "\n"; + } + +} catch (PDOException $e) { + echo "❌ Datenbankfehler: " . $e->getMessage() . "\n"; + exit(1); +} catch (Exception $e) { + echo "❌ Fehler: " . $e->getMessage() . "\n"; + exit(1); +} + +echo "✅ Erfolgreich abgeschlossen\n"; diff --git a/data/config.php b/data/config.php index 4d3dad21..c8966c49 100644 --- a/data/config.php +++ b/data/config.php @@ -360,7 +360,7 @@ return [ 0 => 'youtube.com', 1 => 'google.com' ], - 'microtime' => 1773097042.742692, + 'microtime' => 1773097606.553663, 'siteUrl' => 'https://crm.bitbylaw.com', 'fullTextSearchMinLength' => 4, 'webSocketUrl' => 'ws://api.bitbylaw.com:5000/espocrm/ws', diff --git a/data/state.php b/data/state.php index 57351662..e74e7f45 100644 --- a/data/state.php +++ b/data/state.php @@ -1,7 +1,7 @@ 1773097042, - 'microtimeState' => 1773097042.98789, + 'cacheTimestamp' => 1773097606, + 'microtimeState' => 1773097606.681824, 'currencyRates' => [ 'EUR' => 1.0 ],