from fittrackee import appLog, db from flask import Blueprint, current_app, jsonify, request from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound from ..users.utils import authenticate_as_admin from .models import AppConfig from .utils import update_app_config_from_database config_blueprint = Blueprint('config', __name__) @config_blueprint.route('/config', methods=['GET']) def get_application_config(): """ Get Application config **Example request**: .. sourcecode:: http GET /api/config HTTP/1.1 Content-Type: application/json **Example response**: .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json { "data": { "gpx_limit_import": 10, "is_registration_enabled": false, "max_single_file_size": 1048576, "max_zip_file_size": 10485760, "max_users": 0, "map_attribution": "© OpenStreetMap contributors" }, "status": "success" } :statuscode 200: success :statuscode 500: Error on getting configuration. """ try: config = AppConfig.query.one() response_object = {'status': 'success', 'data': config.serialize()} return jsonify(response_object), 200 except (MultipleResultsFound, NoResultFound) as e: appLog.error(e) response_object = { 'status': 'error', 'message': 'Error on getting configuration.', } return jsonify(response_object), 500 @config_blueprint.route('/config', methods=['PATCH']) @authenticate_as_admin def update_application_config(auth_user_id): """ Update Application config Authenticated user must be an admin **Example request**: .. sourcecode:: http GET /api/config HTTP/1.1 Content-Type: application/json **Example response**: .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json { "data": { "gpx_limit_import": 10, "is_registration_enabled": true, "max_single_file_size": 1048576, "max_zip_file_size": 10485760, "max_users": 10 }, "status": "success" } :param integer auth_user_id: authenticate user id (from JSON Web Token) :