feat(integrations): add role-based security and 1-click Outlook connect for colleagues
This commit is contained in:
+19
-13
@@ -72,18 +72,15 @@ if (empty($code)) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// 4. Instellingen ophalen
|
||||
$stmt = $db->prepare("SELECT settings FROM integrations WHERE user_id = ? AND provider = 'OUTLOOK'");
|
||||
$stmt->execute([$user['id']]);
|
||||
$row = $stmt->fetch();
|
||||
$savedSettings = json_decode($row['settings'] ?? '{}', true) ?: [];
|
||||
// 4. Centrale instellingen ophalen
|
||||
$appConfig = microsoft_get_app_config();
|
||||
|
||||
$clientId = !empty($savedSettings['client_id']) ? $savedSettings['client_id'] : fociz_env('MICROSOFT_CLIENT_ID', '');
|
||||
$clientSecret = !empty($savedSettings['client_secret']) ? $savedSettings['client_secret'] : fociz_env('MICROSOFT_CLIENT_SECRET', '');
|
||||
$tenantId = !empty($savedSettings['tenant_id']) ? $savedSettings['tenant_id'] : fociz_env('MICROSOFT_TENANT_ID', 'common');
|
||||
$clientId = $appConfig['client_id'];
|
||||
$clientSecret = $appConfig['client_secret'];
|
||||
$tenantId = $appConfig['tenant_id'];
|
||||
|
||||
if (empty($clientId) || empty($clientSecret)) {
|
||||
header('Location: /integrations.php?error=' . urlencode('Client ID of Client Secret ontbreekt in Fociz. Vul deze eerst in bij de Outlook instellingen.'));
|
||||
header('Location: /integrations.php?error=' . urlencode('Microsoft 365 configuratie (Client ID of Secret) ontbreekt in Fociz. Neem contact op met de beheerder.'));
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -108,15 +105,24 @@ $accountEmail = $profile['mail'] ?? ($profile['userPrincipalName'] ?? $user['ema
|
||||
$accountName = $profile['displayName'] ?? 'Microsoft 365 Account';
|
||||
|
||||
// 7. Opslaan in MariaDB
|
||||
$newSettings = array_merge($savedSettings, [
|
||||
'client_id' => $clientId,
|
||||
'client_secret' => $clientSecret,
|
||||
'tenant_id' => $tenantId,
|
||||
$stmtExisting = $db->prepare("SELECT settings FROM integrations WHERE user_id = ? AND provider = 'OUTLOOK'");
|
||||
$stmtExisting->execute([$user['id']]);
|
||||
$existingRow = $stmtExisting->fetch();
|
||||
$existingSettings = json_decode($existingRow['settings'] ?? '{}', true) ?: [];
|
||||
|
||||
$newSettings = array_merge($existingSettings, [
|
||||
'expires_at' => $expiresAt,
|
||||
'account_email' => $accountEmail,
|
||||
'account_name' => $accountName,
|
||||
]);
|
||||
|
||||
// Als de ingelogde gebruiker Beheerder (ADMIN) is, bewaren we ook de centrale app credentials
|
||||
if ($user['role'] === 'ADMIN') {
|
||||
$newSettings['client_id'] = $clientId;
|
||||
$newSettings['client_secret'] = $clientSecret;
|
||||
$newSettings['tenant_id'] = $tenantId;
|
||||
}
|
||||
|
||||
$saveStmt = $db->prepare("
|
||||
INSERT INTO integrations (user_id, provider, is_enabled, is_demo_mode, access_token, refresh_token, settings, last_sync_at)
|
||||
VALUES (?, 'OUTLOOK', 1, 0, ?, ?, ?, NOW())
|
||||
|
||||
Reference in New Issue
Block a user