Skip to content

Commit 9f7359f

Browse files
committed
feat(global-settings): add global configuration retrieval and email settings checks
1 parent 9fa56ef commit 9f7359f

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { GlobalSettingsModule } from './types';
2+
3+
export const globalSettings: GlobalSettingsModule = {
4+
group: {
5+
id: 'global',
6+
name: 'Global Settings',
7+
description: 'General application configuration settings',
8+
icon: 'settings',
9+
sort_order: 0
10+
},
11+
settings: [
12+
{
13+
key: 'global.page_url',
14+
defaultValue: 'http://localhost:5173',
15+
type: 'string',
16+
description: 'Base URL for the application frontend',
17+
encrypted: false,
18+
required: false
19+
},
20+
{
21+
key: 'global.send_mail',
22+
defaultValue: false,
23+
type: 'boolean',
24+
description: 'Enable or disable email sending functionality',
25+
encrypted: false,
26+
required: false
27+
}
28+
]
29+
};

services/backend/src/global-settings/index.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
ValidationResult,
1111
SmtpConfig,
1212
GitHubOAuthConfig,
13+
GlobalConfig,
1314
InitializationResult
1415
} from './types';
1516

@@ -397,6 +398,54 @@ export class GlobalSettingsInitService {
397398
const config = await this.getGitHubOAuthConfiguration();
398399
return config !== null;
399400
}
401+
402+
/**
403+
* Get complete Global configuration
404+
*/
405+
static async getGlobalConfiguration(): Promise<GlobalConfig | null> {
406+
try {
407+
const settings = await Promise.all([
408+
GlobalSettingsService.get('global.page_url'),
409+
GlobalSettingsService.get('global.send_mail')
410+
]);
411+
412+
const [pageUrl, sendMail] = settings;
413+
414+
return {
415+
pageUrl: pageUrl?.value || 'http://localhost:5173',
416+
sendMail: sendMail?.value === 'true'
417+
};
418+
} catch (error) {
419+
console.error('Failed to get Global configuration:', error);
420+
return null;
421+
}
422+
}
423+
424+
/**
425+
* Check if email sending is enabled
426+
*/
427+
static async isEmailSendingEnabled(): Promise<boolean> {
428+
try {
429+
const setting = await GlobalSettingsService.get('global.send_mail');
430+
return setting?.value === 'true';
431+
} catch (error) {
432+
console.error('Failed to check if email sending is enabled:', error);
433+
return false; // Default to disabled if there's an error
434+
}
435+
}
436+
437+
/**
438+
* Get the application page URL
439+
*/
440+
static async getPageUrl(): Promise<string> {
441+
try {
442+
const setting = await GlobalSettingsService.get('global.page_url');
443+
return setting?.value || 'http://localhost:5173';
444+
} catch (error) {
445+
console.error('Failed to get page URL:', error);
446+
return 'http://localhost:5173'; // Default fallback
447+
}
448+
}
400449
}
401450

402451
// Export the helper class
@@ -409,5 +458,6 @@ export type {
409458
ValidationResult,
410459
SmtpConfig,
411460
GitHubOAuthConfig,
461+
GlobalConfig,
412462
InitializationResult
413463
};

services/backend/src/global-settings/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ export interface GitHubOAuthConfig {
7878
scope: string;
7979
}
8080

81+
export interface GlobalConfig {
82+
pageUrl: string;
83+
sendMail: boolean;
84+
}
85+
8186
export interface InitializationResult {
8287
totalModules: number;
8388
totalSettings: number;

0 commit comments

Comments
 (0)