feat(admin-profile): separate central system administration into admin.php and personal settings into profile.php
This commit is contained in:
@@ -18,6 +18,51 @@ function jira_normalize_domain(string $domain): string {
|
||||
return rtrim($domain, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Haalt het centrale bedrijfsdomein voor Atlassian Jira op
|
||||
*/
|
||||
function jira_get_company_domain(): string {
|
||||
$domain = fociz_env('JIRA_DOMAIN', '');
|
||||
if (!empty($domain)) {
|
||||
return jira_normalize_domain($domain);
|
||||
}
|
||||
|
||||
try {
|
||||
$db = get_db_connection();
|
||||
// Zoek bij beheerder(s) in de integrations tabel
|
||||
$stmt = $db->query("
|
||||
SELECT i.settings
|
||||
FROM integrations i
|
||||
JOIN users u ON i.user_id = u.id
|
||||
WHERE u.role = 'ADMIN' AND i.provider = 'JIRA' AND i.settings IS NOT NULL
|
||||
ORDER BY i.updated_at DESC
|
||||
LIMIT 1
|
||||
");
|
||||
$row = $stmt->fetch();
|
||||
if (!empty($row['settings'])) {
|
||||
$settings = json_decode($row['settings'], true) ?: [];
|
||||
if (!empty($settings['jira_domain'])) {
|
||||
return jira_normalize_domain($settings['jira_domain']);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback naar een willekeurige JIRA rij
|
||||
$fallback = $db->query("
|
||||
SELECT settings FROM integrations WHERE provider = 'JIRA' AND settings LIKE '%jira_domain%' LIMIT 1
|
||||
")->fetch();
|
||||
if (!empty($fallback['settings'])) {
|
||||
$settings = json_decode($fallback['settings'], true) ?: [];
|
||||
if (!empty($settings['jira_domain'])) {
|
||||
return jira_normalize_domain($settings['jira_domain']);
|
||||
}
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
error_log("jira_get_company_domain error: " . $e->getMessage());
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Genereert de Basic Authentication header voor Atlassian REST API
|
||||
*/
|
||||
@@ -240,7 +285,7 @@ function jira_get_user_issues(int $userId, bool $forceRefresh = false): array {
|
||||
}
|
||||
|
||||
$settings = json_decode($integration['settings'] ?? '{}', true) ?: [];
|
||||
$domain = $settings['jira_domain'] ?? fociz_env('JIRA_DOMAIN', '');
|
||||
$domain = !empty($settings['jira_domain']) ? $settings['jira_domain'] : jira_get_company_domain();
|
||||
$email = $settings['jira_email'] ?? fociz_env('JIRA_EMAIL', '');
|
||||
$apiToken = $settings['jira_api_token'] ?? fociz_env('JIRA_API_TOKEN', '');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user