function api_get_system_config
Flask API endpoint that retrieves current system configuration settings for admin users only, returning configuration values like system role, expertise, domain context, and supported languages.
/tf/active/vicechatdev/docchat/app.py
840 - 855
simple
Purpose
This endpoint serves as an admin-only API route to fetch the current system configuration. It's used in administrative interfaces to display and potentially edit system-wide settings. The function checks admin authorization, formats the SYSTEM_EXPERTISE list into a newline-separated string for easier editing, and returns a JSON response containing all major system configuration parameters.
Source Code
def api_get_system_config():
"""Get current system configuration (admin only)"""
if not is_admin_user():
return jsonify({'error': 'Unauthorized - Admin access required'}), 403
# Convert SYSTEM_EXPERTISE list to string for editing
expertise_str = '\n'.join(config.SYSTEM_EXPERTISE) if isinstance(config.SYSTEM_EXPERTISE, list) else config.SYSTEM_EXPERTISE
return jsonify({
'system_role': config.SYSTEM_ROLE,
'system_expertise': expertise_str,
'system_domain_context': config.SYSTEM_DOMAIN_CONTEXT,
'custom_system_instructions': config.CUSTOM_SYSTEM_INSTRUCTIONS or '',
'output_style': config.OUTPUT_STYLE,
'query_languages': config.SUPPORTED_LANGUAGES
})
Return Value
Returns a Flask JSON response tuple. On success (admin user): returns a JSON object with keys 'system_role', 'system_expertise' (newline-separated string), 'system_domain_context', 'custom_system_instructions', 'output_style', and 'query_languages' with HTTP status 200 (implicit). On failure (non-admin): returns JSON object with 'error' key and HTTP status 403.
Dependencies
flaskconfig
Required Imports
from flask import jsonify
import config
Conditional/Optional Imports
These imports are only needed under specific conditions:
from flask import session
Condition: Required by login_required decorator and is_admin_user() function for session management
Required (conditional)Usage Example
# This is an API endpoint, typically called via HTTP GET request
# Example using requests library:
import requests
# Assuming Flask app is running on localhost:5000
# and user is logged in with admin privileges
response = requests.get(
'http://localhost:5000/api/admin/system-config',
cookies={'session': 'your_session_cookie'}
)
if response.status_code == 200:
config_data = response.json()
print(f"System Role: {config_data['system_role']}")
print(f"Expertise: {config_data['system_expertise']}")
print(f"Domain Context: {config_data['system_domain_context']}")
else:
print(f"Error: {response.json()['error']}")
Best Practices
- Always ensure the is_admin_user() function properly validates admin privileges to prevent unauthorized access
- The function converts SYSTEM_EXPERTISE list to newline-separated string for UI editing - ensure the corresponding update endpoint reverses this transformation
- Returns 403 Forbidden for non-admin users, which is the correct HTTP status for authorization failures
- Consider adding error handling for cases where config attributes might be missing or None
- The endpoint should be called only after successful authentication via login_required decorator
- Ensure CORS settings are properly configured if this API is accessed from a different domain
- Consider adding rate limiting to prevent abuse of admin endpoints
- Log access attempts to this endpoint for security auditing purposes
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function api_update_system_config 79.2% similar
-
function system_status 63.4% similar
-
function get_system_configuration 62.2% similar
-
function admin_status 60.5% similar
-
function api_update_chat_config 58.6% similar