diff --git a/app/views/settings.py b/app/views/settings.py
index e2a68160..ffe90cf8 100644
--- a/app/views/settings.py
+++ b/app/views/settings.py
@@ -2,6 +2,7 @@
Settings management views for the application.
"""
+import os
import logging
import inspect
from functools import wraps
@@ -46,9 +47,16 @@ def require_admin_access(func):
async def settings_page(request: Request, db: Session = Depends(get_db)):
"""
Settings management page - admin only.
+
+ This page is a convenience feature to view and edit settings.
+ Values are displayed in precedence order: Database > Environment > Defaults
"""
try:
+ # Get settings from database
+ from app.utils.settings_service import get_all_settings_from_db
+ db_settings = get_all_settings_from_db(db)
+
# Get settings organized by category
categories = get_settings_by_category()
@@ -57,9 +65,26 @@ async def settings_page(request: Request, db: Session = Depends(get_db)):
for category, keys in categories.items():
settings_data[category] = []
for key in keys:
- # Get current value from settings
+ # Get current value from settings (already has precedence applied)
value = getattr(settings, key, None)
+ # Determine the source of this setting
+ # Check if it's in the database
+ if key in db_settings:
+ source = "database"
+ source_label = "DB"
+ source_color = "green"
+ # Check if it's from environment variable
+ elif key.upper() in os.environ or key in os.environ:
+ source = "environment"
+ source_label = "ENV"
+ source_color = "blue"
+ else:
+ # It's using the default value
+ source = "default"
+ source_label = "DEFAULT"
+ source_color = "gray"
+
# Get metadata
metadata = get_setting_metadata(key)
@@ -71,7 +96,10 @@ async def settings_page(request: Request, db: Session = Depends(get_db)):
settings_data[category].append({
"key": key,
"display_value": display_value if display_value is not None else "",
- "metadata": metadata
+ "metadata": metadata,
+ "source": source,
+ "source_label": source_label,
+ "source_color": source_color
})
return templates.TemplateResponse(
@@ -82,6 +110,12 @@ async def settings_page(request: Request, db: Session = Depends(get_db)):
"app_version": settings.version
}
)
+ {
+ "request": request,
+ "settings_data": settings_data,
+ "app_version": settings.version
+ }
+ )
except Exception as e:
logger.error(f"Error loading settings page: {e}")
raise HTTPException(
diff --git a/docs/SettingsManagement.md b/docs/SettingsManagement.md
index 6f2c7095..7653d50d 100644
--- a/docs/SettingsManagement.md
+++ b/docs/SettingsManagement.md
@@ -2,10 +2,15 @@
## Overview
-DocuElevate now supports managing application settings through a web-based GUI. Settings can be configured, saved to the database, and will persist across application restarts with the following precedence:
+DocuElevate supports managing application settings through a web-based GUI. This is a **convenience feature** that allows administrators to view and edit configuration settings. Settings are displayed and saved with the following precedence:
**Database > Environment Variables > Defaults**
+Each setting in the UI shows a badge indicating its current source:
+- š¢ **DB** - Explicitly saved in database (highest priority)
+- šµ **ENV** - From environment variable (.env file or system)
+- āŖ **DEFAULT** - Built-in application default
+
## Accessing the Settings Page
1. Navigate to `/settings` in your web browser
@@ -63,19 +68,36 @@ Most runtime settings (API keys, storage credentials) can be changed without res
2. Browse categories using the expandable sections
3. Each setting shows:
- **Name**: The setting key
+ - **Source Badge**: Where the current value comes from (DB/ENV/DEFAULT)
- **Description**: What the setting does
- **Current Value**: The active value (masked if sensitive)
- **Type**: String, boolean, integer, or list
- - **Required**: Whether the setting must be configured
+ - **Required**: Whether the setting must be configured (informational only)
- **Restart Required**: Whether changing this setting requires a restart
+### Understanding Source Badges
+
+- **š¢ DB (Green)**: This setting has been explicitly saved via the settings page. It's stored in the database and overrides environment variables.
+- **šµ ENV (Blue)**: This setting comes from an environment variable (`.env` file or system environment). It can be overridden by saving it in the database.
+- **āŖ DEFAULT (Gray)**: This setting is using the built-in application default. No environment variable or database value is set.
+
+The current value displayed is **always** the effective value after applying precedence (DB > ENV > DEFAULT).
+
### Updating Settings
1. Modify the desired settings in the form
-2. Click "Save Settings" at the bottom of the page
-3. Settings are validated before saving
-4. Success/error messages are displayed
-5. If any changed setting requires a restart, you'll be notified
+2. **All fields are optional** - you only need to change the settings you want to override
+3. Click "Save Settings" at the bottom of the page
+4. Settings are validated before saving
+5. Success/error messages are displayed
+6. Successfully saved settings will show a š¢ DB badge
+7. If any changed setting requires a restart, you'll be notified
+
+**Important**:
+- You don't need to fill all fields - only change what you want to override
+- Saving a setting to the database makes it override environment variables
+- Empty fields are ignored (won't clear existing values)
+- To revert a setting to ENV or DEFAULT, delete it from the database (see API endpoints)
### Bulk Updates
diff --git a/frontend/templates/settings.html b/frontend/templates/settings.html
index 11757ab6..6469b0cb 100644
--- a/frontend/templates/settings.html
+++ b/frontend/templates/settings.html
@@ -15,16 +15,24 @@
Application Settings
- Configure application settings through the web interface.
- Settings saved here will take precedence over environment variables.
+ This is a convenience feature to view and edit application settings through the web interface.
+
+
š Settings Precedence Order:
+
+
DB Database settings (highest priority) - explicitly saved via this UI
+
ENV Environment variables - from .env file or system environment