🔍 Code Extractor

function api_get_system_config

Maturity: 46

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.

File:
/tf/active/vicechatdev/docchat/app.py
Lines:
840 - 855
Complexity:
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

  • flask
  • config

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

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function api_update_system_config 79.2% similar

    Flask API endpoint that allows administrators to update system configuration settings including system role, expertise, domain context, custom instructions, output style, and query languages, with persistence to disk.

    From: /tf/active/vicechatdev/docchat/app.py
  • function system_status 63.4% similar

    Flask API endpoint that returns comprehensive system status information including database connectivity, authentication state, and feature availability.

    From: /tf/active/vicechatdev/vice_ai/new_app.py
  • function get_system_configuration 62.2% 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 admin_status 60.5% similar

    Flask route handler that retrieves comprehensive system status information including disk usage, session counts, analysis counts, and orphaned file detection for an admin dashboard.

    From: /tf/active/vicechatdev/full_smartstat/app.py
  • function api_update_chat_config 58.6% similar

    Flask API endpoint that updates the configuration settings for a specific chat session by accepting JSON data, converting it to a ChatConfiguration object, and persisting the changes.

    From: /tf/active/vicechatdev/vice_ai/new_app.py
← Back to Browse