🔍 Code Extractor

function get_system_settings

Maturity: 52

Retrieves system-wide configuration settings from a Neo4j database, returning default values if settings are not found or an error occurs.

File:
/tf/active/vicechatdev/CDocs/controllers/admin_controller.py
Lines:
432 - 475
Complexity:
simple

Purpose

This function fetches application-level system settings stored as a SystemSettings node in Neo4j. It provides a centralized way to access configuration parameters like site name, company name, theme preferences, and security settings. If the database query fails or no settings exist, it returns a predefined set of default values to ensure the application can continue functioning.

Source Code

def get_system_settings() -> Dict[str, Any]:
    """
    Get current system settings.
    
    Returns:
        Dictionary containing system settings
    """
    # For Neo4j, we might store settings as a special node
    try:
        settings_result = db.run_query(
            """
            MATCH (s:SystemSettings) 
            RETURN s LIMIT 1
            """
        )
        
        if settings_result and 's' in settings_result[0]:
            return dict(settings_result[0]['s'])
        else:
            # Return default settings
            return {
                'site_name': 'Controlled Document System',
                'company_name': 'ViceBio',
                'admin_email': settings.ADMIN_EMAIL,
                'logo_url': '/static/images/logo.png',
                'theme': 'light',
                'allow_registration': False,
                'default_role': 'USER',
                'session_timeout': 3600
            }
            
    except Exception as e:
        logger.error(f"Error getting system settings: {e}")
        # Return default values if error occurs
        return {
            'site_name': 'Controlled Document System',
            'company_name': 'ViceBio',
            'admin_email': settings.ADMIN_EMAIL if hasattr(settings, 'ADMIN_EMAIL') else '',
            'logo_url': '/static/images/logo.png',
            'theme': 'light',
            'allow_registration': False,
            'default_role': 'USER',
            'session_timeout': 3600
        }

Return Value

Type: Dict[str, Any]

Returns a dictionary (Dict[str, Any]) containing system configuration settings. Keys include: 'site_name' (str), 'company_name' (str), 'admin_email' (str), 'logo_url' (str), 'theme' (str), 'allow_registration' (bool), 'default_role' (str), and 'session_timeout' (int). If the SystemSettings node exists in Neo4j, returns its properties; otherwise returns hardcoded default values.

Dependencies

  • logging
  • typing
  • CDocs.db
  • CDocs.config

Required Imports

from typing import Dict, Any
from CDocs import db
from CDocs.config import settings
import logging

Usage Example

from typing import Dict, Any
from CDocs import db
from CDocs.config import settings
import logging

logger = logging.getLogger(__name__)

# Get system settings
system_config = get_system_settings()

# Access specific settings
site_name = system_config['site_name']
company_name = system_config['company_name']
theme = system_config['theme']
session_timeout = system_config['session_timeout']

# Use settings in application logic
if system_config['allow_registration']:
    # Enable user registration
    pass

print(f"Site: {site_name}, Company: {company_name}")
print(f"Theme: {theme}, Timeout: {session_timeout}s")

Best Practices

  • This function always returns a valid dictionary, making it safe to use without additional null checks
  • The function implements graceful degradation by returning default values on database errors
  • Ensure the Neo4j database connection (db module) is properly initialized before calling this function
  • The SystemSettings node should follow the pattern: CREATE (s:SystemSettings {site_name: '...', company_name: '...', ...})
  • Only one SystemSettings node should exist in the database (enforced by LIMIT 1 in query)
  • Consider caching the result of this function if called frequently to reduce database queries
  • The function logs errors but does not raise exceptions, ensuring application stability
  • Verify that settings.ADMIN_EMAIL is configured to avoid empty admin_email values

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_system_configuration 74.0% similar

    Retrieves system configuration settings from environment variables for display in an admin panel, including database connections, authentication settings, and operational parameters.

    From: /tf/active/vicechatdev/CDocs/controllers/admin_controller.py
  • function get_default_connection_config 55.7% similar

    Retrieves the default database connection configuration by loading settings from a sql_config.py file located in the same directory as the function.

    From: /tf/active/vicechatdev/full_smartstat/sql_query_generator.py
  • function get_config_value 54.3% similar

    Retrieves a configuration value from a nested dictionary structure in the global scope, with fallback to a default value if not found.

    From: /tf/active/vicechatdev/CDocs/settings_prod.py
  • function get_system_stats 50.3% similar

    Retrieves comprehensive system statistics from a Neo4j graph database for display on an admin dashboard, including user counts, document counts, review cycles, and approval metrics.

    From: /tf/active/vicechatdev/CDocs/controllers/admin_controller.py
  • function api_get_system_config 49.5% similar

    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.

    From: /tf/active/vicechatdev/docchat/app.py
← Back to Browse