mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-10-25 20:47:18 +09:00
328 more routes used a JSON body as a dict straight from
request.get_json(), so a body of null, [] or a bare string crashed them
into a 500. Bare reads become json_object(); the
'get_json(silent=True) or {}' reads of action routes become
json_object(optional=True), which still treats a missing body as {}.
Routes that take arrays or pass the body through untouched are left
alone. The full backend suite shows no new failures.
Also carries three files' bare section citations (apps, backups,
notifications) and the extended citation guard, which needed them.
48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
"""Modules API — toggle heavy core verticals (Email, WordPress) on/off.
|
|
|
|
Read is available to any authenticated user (the frontend needs it to hide nav
|
|
and guard routes); flipping a toggle is admin-only.
|
|
"""
|
|
from flask import Blueprint, jsonify
|
|
from flask_jwt_extended import jwt_required
|
|
|
|
from app.services import module_service
|
|
from app.services.audit_service import AuditService
|
|
from app.models.audit_log import AuditLog
|
|
from app.middleware.rbac import get_current_user
|
|
from app.api._request import json_object
|
|
|
|
modules_bp = Blueprint('modules', __name__)
|
|
|
|
|
|
@modules_bp.route('', methods=['GET'])
|
|
@modules_bp.route('/', methods=['GET'])
|
|
@jwt_required()
|
|
def list_modules():
|
|
return jsonify({'modules': module_service.list_modules()})
|
|
|
|
|
|
@modules_bp.route('/<name>', methods=['PUT'])
|
|
@jwt_required()
|
|
def set_module(name):
|
|
user = get_current_user()
|
|
if not user or not user.is_admin:
|
|
return jsonify({'error': 'Admin access required'}), 403
|
|
|
|
if name not in module_service.MODULES:
|
|
return jsonify({'error': f'Unknown module: {name}'}), 404
|
|
|
|
data = json_object()
|
|
if 'enabled' not in data:
|
|
return jsonify({'error': 'enabled (boolean) required'}), 400
|
|
|
|
enabled = module_service.set_module_enabled(name, bool(data['enabled']), user_id=user.id)
|
|
AuditService.log(
|
|
action=AuditLog.ACTION_RESOURCE_ENABLE if enabled else AuditLog.ACTION_RESOURCE_DISABLE,
|
|
user_id=user.id,
|
|
target_type='module',
|
|
target_id=None,
|
|
details={'module': name, 'enabled': enabled},
|
|
)
|
|
return jsonify({'name': name, 'enabled': enabled})
|