This commit is contained in:
2026-01-19 01:24:07 +01:00
parent 9df34f242a
commit 647edd0111

View File

@@ -1652,6 +1652,8 @@ class ApiKernel
$user = $this->requireAuth(); $user = $this->requireAuth();
$customerId = (int)($user['customer_id'] ?? 0); $customerId = (int)($user['customer_id'] ?? 0);
$settings = $customerId ? $this->ensureSettingsTokens($customerId, $this->getCustomerSettings($customerId)) : []; $settings = $customerId ? $this->ensureSettingsTokens($customerId, $this->getCustomerSettings($customerId)) : [];
$this->ensureAuthUserListSortColumn();
$settings['list_sort'] = $this->resolveUserListSort($user, $customerId);
$this->respond([ $this->respond([
'ok' => true, 'ok' => true,
'user' => $user, 'user' => $user,
@@ -1759,11 +1761,8 @@ class ApiKernel
private function handleAccountSettingsUpdate(): void private function handleAccountSettingsUpdate(): void
{ {
$user = $this->requireAuth(); $user = $this->requireAuth();
$this->ensureRole($user, ['owner', 'admin']);
$customerId = (int)($user['customer_id'] ?? 0); $customerId = (int)($user['customer_id'] ?? 0);
if ($customerId <= 0) $this->fail('Customer context missing', null, 500);
$settings = $this->getCustomerSettings($customerId);
$hasBridgeUrl = array_key_exists('bridge_url', $this->in); $hasBridgeUrl = array_key_exists('bridge_url', $this->in);
$hasBridgeToken = array_key_exists('bridge_token', $this->in); $hasBridgeToken = array_key_exists('bridge_token', $this->in);
$hasSenderToken = array_key_exists('sender_token', $this->in); $hasSenderToken = array_key_exists('sender_token', $this->in);
@@ -1771,22 +1770,35 @@ class ApiKernel
$hasEditorDefault = array_key_exists('editor_default', $this->in); $hasEditorDefault = array_key_exists('editor_default', $this->in);
$hasListSort = array_key_exists('list_sort', $this->in); $hasListSort = array_key_exists('list_sort', $this->in);
$hasBridgeTables = array_key_exists('bridge_tables', $this->in); $hasBridgeTables = array_key_exists('bridge_tables', $this->in);
$rotateBridge = !empty($this->in['rotate_bridge_token']);
$rotateSender = !empty($this->in['rotate_sender_token']);
$rotateExternal = !empty($this->in['rotate_external_token']);
$onlyListSort = $hasListSort && !$hasBridgeUrl && !$hasBridgeToken && !$hasSenderToken && !$hasExternalToken
&& !$hasEditorDefault && !$hasBridgeTables && !$rotateBridge && !$rotateSender && !$rotateExternal;
if (!$onlyListSort) {
$this->ensureRole($user, ['owner', 'admin']);
if ($customerId <= 0) $this->fail('Customer context missing', null, 500);
}
$settings = $customerId ? $this->getCustomerSettings($customerId) : [];
$bridgeUrl = $hasBridgeUrl ? trim((string)($this->in['bridge_url'] ?? '')) : (string)($settings['bridge_url'] ?? ''); $bridgeUrl = $hasBridgeUrl ? trim((string)($this->in['bridge_url'] ?? '')) : (string)($settings['bridge_url'] ?? '');
$bridgeToken = $hasBridgeToken ? trim((string)($this->in['bridge_token'] ?? '')) : (string)($settings['bridge_token'] ?? ''); $bridgeToken = $hasBridgeToken ? trim((string)($this->in['bridge_token'] ?? '')) : (string)($settings['bridge_token'] ?? '');
$senderToken = $hasSenderToken ? trim((string)($this->in['sender_token'] ?? '')) : (string)($settings['sender_token'] ?? ''); $senderToken = $hasSenderToken ? trim((string)($this->in['sender_token'] ?? '')) : (string)($settings['sender_token'] ?? '');
$externalToken = $hasExternalToken ? trim((string)($this->in['external_api_token'] ?? '')) : (string)($settings['external_api_token'] ?? ''); $externalToken = $hasExternalToken ? trim((string)($this->in['external_api_token'] ?? '')) : (string)($settings['external_api_token'] ?? '');
$editorDefault = $hasEditorDefault ? strtolower(trim((string)($this->in['editor_default'] ?? ''))) : strtolower((string)($settings['editor_default'] ?? '')); $editorDefault = $hasEditorDefault ? strtolower(trim((string)($this->in['editor_default'] ?? ''))) : strtolower((string)($settings['editor_default'] ?? ''));
$listSort = $hasListSort ? strtolower(trim((string)($this->in['list_sort'] ?? ''))) : ''; $listSort = $hasListSort ? strtolower(trim((string)($this->in['list_sort'] ?? ''))) : '';
$rotateBridge = !empty($this->in['rotate_bridge_token']);
$rotateSender = !empty($this->in['rotate_sender_token']);
$rotateExternal = !empty($this->in['rotate_external_token']);
$bridgeTables = $hasBridgeTables ? $this->normalizeBridgeTables($this->in['bridge_tables'] ?? []) : ($settings['bridge_tables'] ?? []); $bridgeTables = $hasBridgeTables ? $this->normalizeBridgeTables($this->in['bridge_tables'] ?? []) : ($settings['bridge_tables'] ?? []);
if ($bridgeUrl && !filter_var($bridgeUrl, FILTER_VALIDATE_URL)) { if ($bridgeUrl && !filter_var($bridgeUrl, FILTER_VALIDATE_URL)) {
$this->fail('Ungültige Bridge-URL', null, 422); $this->fail('Ungültige Bridge-URL', null, 422);
} }
if ($listSort !== '' && !in_array($listSort, ['created_asc', 'name_asc', 'name_desc', 'updated_desc'], true)) {
$this->fail('Ungültige Sortierung', null, 422);
}
if (!$onlyListSort) {
if ($rotateBridge || $bridgeToken === '') $bridgeToken = $this->generateToken(); if ($rotateBridge || $bridgeToken === '') $bridgeToken = $this->generateToken();
if ($rotateSender || $senderToken === '') $senderToken = $this->generateToken(); if ($rotateSender || $senderToken === '') $senderToken = $this->generateToken();
if ($rotateExternal || $externalToken === '') $externalToken = $this->generateToken(); if ($rotateExternal || $externalToken === '') $externalToken = $this->generateToken();
@@ -1794,9 +1806,6 @@ class ApiKernel
if ($editorDefault !== '' && !in_array($editorDefault, ['grapesjs', 'craftjs'], true)) { if ($editorDefault !== '' && !in_array($editorDefault, ['grapesjs', 'craftjs'], true)) {
$this->fail('Ungültiger Editor-Typ', null, 422); $this->fail('Ungültiger Editor-Typ', null, 422);
} }
if ($listSort !== '' && !in_array($listSort, ['created_asc', 'name_asc', 'name_desc', 'updated_desc'], true)) {
$this->fail('Ungültige Sortierung', null, 422);
}
$settings = $this->saveCustomerSettings($customerId, [ $settings = $this->saveCustomerSettings($customerId, [
'bridge_url' => $bridgeUrl, 'bridge_url' => $bridgeUrl,
@@ -1806,6 +1815,9 @@ class ApiKernel
'editor_default' => $editorDefault ?: null, 'editor_default' => $editorDefault ?: null,
'bridge_tables' => $bridgeTables, 'bridge_tables' => $bridgeTables,
]); ]);
} else {
$settings = $customerId ? $this->ensureSettingsTokens($customerId, $settings) : $settings;
}
if ($hasListSort) { if ($hasListSort) {
$this->ensureAuthUserListSortColumn(); $this->ensureAuthUserListSortColumn();
$this->updateUserListSort($user, $customerId, $listSort ?: null); $this->updateUserListSort($user, $customerId, $listSort ?: null);