API & Client - max sizes and max number of files must be greater than 0 - #71
This commit is contained in:
@ -12,7 +12,7 @@ from fittrackee.responses import (
|
||||
from fittrackee.users.decorators import authenticate_as_admin
|
||||
|
||||
from .models import AppConfig
|
||||
from .utils import update_app_config_from_database
|
||||
from .utils import update_app_config_from_database, verify_app_config
|
||||
|
||||
config_blueprint = Blueprint('config', __name__)
|
||||
|
||||
@ -96,11 +96,11 @@ def update_application_config(auth_user_id: int) -> Union[Dict, HttpResponse]:
|
||||
|
||||
:param integer auth_user_id: authenticate user id (from JSON Web Token)
|
||||
|
||||
:<json integrer gpx_limit_import: max number of files in zip archive
|
||||
:<json integer gpx_limit_import: max number of files in zip archive
|
||||
:<json boolean is_registration_enabled: is registration enabled ?
|
||||
:<json integrer max_single_file_size: max size of a single file
|
||||
:<json integrer max_zip_file_size: max size of a zip archive
|
||||
:<json integrer max_users: max users allowed to register on instance
|
||||
:<json integer max_single_file_size: max size of a single file
|
||||
:<json integer max_zip_file_size: max size of a zip archive
|
||||
:<json integer max_users: max users allowed to register on instance
|
||||
|
||||
:reqheader Authorization: OAuth 2.0 Bearer Token
|
||||
|
||||
@ -117,6 +117,10 @@ def update_application_config(auth_user_id: int) -> Union[Dict, HttpResponse]:
|
||||
if not config_data:
|
||||
return InvalidPayloadErrorResponse()
|
||||
|
||||
ret = verify_app_config(config_data)
|
||||
if ret:
|
||||
return InvalidPayloadErrorResponse(message=ret)
|
||||
|
||||
try:
|
||||
config = AppConfig.query.one()
|
||||
if 'gpx_limit_import' in config_data:
|
||||
|
@ -1,5 +1,5 @@
|
||||
import os
|
||||
from typing import Tuple
|
||||
from typing import Dict, List, Tuple
|
||||
|
||||
from flask import Flask
|
||||
|
||||
@ -49,3 +49,30 @@ def update_app_config_from_database(
|
||||
current_app.config[
|
||||
'is_registration_enabled'
|
||||
] = db_config.is_registration_enabled
|
||||
|
||||
|
||||
def verify_app_config(config_data: Dict) -> List:
|
||||
"""
|
||||
Verify if application config is valid.
|
||||
|
||||
If not, it returns not empty string
|
||||
"""
|
||||
ret = []
|
||||
if (
|
||||
'gpx_limit_import' in config_data
|
||||
and config_data['gpx_limit_import'] <= 0
|
||||
):
|
||||
ret.append('Max. files in a zip archive must be greater than 0')
|
||||
|
||||
if (
|
||||
'max_single_file_size' in config_data
|
||||
and config_data['max_single_file_size'] <= 0
|
||||
):
|
||||
ret.append('Max. size of uploaded files must be greater than 0')
|
||||
|
||||
if (
|
||||
'max_zip_file_size' in config_data
|
||||
and config_data['max_zip_file_size'] <= 0
|
||||
):
|
||||
ret.append('Max. size of zip archive must be greater than 0')
|
||||
return ret
|
||||
|
Reference in New Issue
Block a user