Vai al contenuto

βš™οΈ Settings System

LibreFolio uses a two-tiered settings system to manage configuration: Global Settings and User Settings.

🌍 Global Settings

Global settings are system-wide configurations that apply to all users. They are managed by administrators and are read-only for regular users.

🎯 Purpose

  • βš™οΈ To control core application behavior.
  • πŸ”§ To configure default values for the entire system.

πŸ”§ Implementation

  • πŸ—ƒοΈ Global settings are stored in the global_settings table in the database.
  • πŸ› οΈ They are managed via the user_cli.py script.
  • πŸ“– The settings_service.py provides functions to read these settings.

πŸ“‹ Example Global Settings

  • πŸ’° Default currency for the application.
  • πŸ”Œ Enabled/disabled status of external data providers.

πŸ’» Managing Global Settings

Global settings are initialized with default values using the CLI:

./dev.py user init-settings

Future versions will allow administrators to modify these settings through an admin UI.

πŸ‘€ User Settings

User settings are preferences specific to each individual user. Each user can modify their own settings.

🎯 Purpose

  • 🎨 To allow users to customize their experience.
  • πŸ”€ To store user-specific preferences that override global defaults.

πŸ”§ Implementation

  • πŸ—ƒοΈ User settings are stored in the user_settings table, linked to a user_id.
  • 🌐 They are managed via the API (/api/v1/settings).
  • πŸ“– The settings_service.py provides functions to get and set user-specific settings, with a fallback to the global setting if a user-specific one is not defined.

πŸ“‹ Example User Settings

  • πŸ’° The user's preferred display currency for their portfolio.
  • 🎨 Theme preference (light/dark mode).
  • πŸ“Š Dashboard layout preferences.

πŸ”— The Settings Service (settings_service.py)

This service acts as the central point for all settings-related operations. It abstracts the two-tiered system, providing a simple interface for the rest of the application.

When a setting is requested for a user, the service first checks if a UserSetting exists for that user. If not, it falls back to the corresponding GlobalSetting. This provides a clean and flexible way to handle default values and user overrides.