mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-11-03 02:26:43 +09:00
Extensions can now contribute walkthroughs via contributions.walkthroughs in plugin.json. The backend validates definitions against a shared contract (route, signal, manual, and check completion types), transports them through the dynamic contribution envelope, and persists custom walkthroughs from the Studio. Includes the JSON Schema, SDK version gate, and extension scaffold support.
57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
"""Self-scoped guided walkthrough progress API."""
|
|
|
|
from flask import Blueprint, jsonify, request
|
|
|
|
from app.middleware.rbac import admin_required, get_current_user, require_role, viewer_required
|
|
from app.services.walkthrough_definition_service import (
|
|
WalkthroughDefinitionError,
|
|
WalkthroughDefinitionService,
|
|
)
|
|
from app.services.walkthrough_service import (
|
|
WalkthroughService,
|
|
WalkthroughStateError,
|
|
)
|
|
|
|
|
|
walkthroughs_bp = Blueprint('walkthroughs', __name__)
|
|
|
|
|
|
@walkthroughs_bp.route('/state', methods=['GET'])
|
|
@viewer_required
|
|
def get_walkthrough_state():
|
|
user = get_current_user()
|
|
return jsonify({'state': WalkthroughService.get_state(user.id)}), 200
|
|
|
|
|
|
@walkthroughs_bp.route('/state', methods=['PUT'])
|
|
@require_role('admin', 'developer', 'viewer')
|
|
def update_walkthrough_state():
|
|
user = get_current_user()
|
|
data = request.get_json(silent=True) or {}
|
|
try:
|
|
state = WalkthroughService.save_state(user.id, data.get('state', data))
|
|
except WalkthroughStateError as exc:
|
|
return jsonify({'error': str(exc)}), 400
|
|
return jsonify({'success': True, 'state': state}), 200
|
|
|
|
|
|
@walkthroughs_bp.route('/definitions', methods=['GET'])
|
|
@viewer_required
|
|
def get_walkthrough_definitions():
|
|
return jsonify({
|
|
'definitions': WalkthroughDefinitionService.get_definitions(),
|
|
}), 200
|
|
|
|
|
|
@walkthroughs_bp.route('/definitions', methods=['PUT'])
|
|
@admin_required
|
|
def update_walkthrough_definitions():
|
|
data = request.get_json(silent=True) or {}
|
|
try:
|
|
definitions = WalkthroughDefinitionService.save_definitions(
|
|
data.get('definitions', data),
|
|
)
|
|
except WalkthroughDefinitionError as exc:
|
|
return jsonify({'error': str(exc)}), 400
|
|
return jsonify({'success': True, 'definitions': definitions}), 200
|