Files
espocrm/custom/scripts/set_junction_acl.php
bsiggel 3470dba301 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.
2026-03-10 00:10:57 +01:00

153 lines
5.1 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env php
<?php
/**
* ACL-Berechtigungen für neue Junction Entities setzen
*
* Dieses Skript fügt ACL-Berechtigungen für die folgenden Entities hinzu:
* - CAdvowareAktenCDokumente
* - CAICollectionCDokumente
* - CPulsTeamZuordnung
*
* Usage: php custom/scripts/set_junction_acl.php
*/
// Lade EspoCRM Config
$configFile = 'data/config-internal.php';
if (!file_exists($configFile)) {
die("❌ Config-Datei nicht gefunden: {$configFile}\n");
}
$config = include $configFile;
$db = $config['database'];
try {
// Datenbankverbindung
$pdo = new PDO(
"mysql:host={$db['host']};dbname={$db['dbname']}",
$db['user'],
$db['password']
);
$pdo->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";