API - add email to contact admin in app config
This commit is contained in:
@ -11,6 +11,7 @@ from fittrackee.responses import (
|
||||
)
|
||||
from fittrackee.users.decorators import authenticate_as_admin
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.users.utils.controls import is_valid_email
|
||||
|
||||
from .models import AppConfig
|
||||
from .utils import update_app_config_from_database, verify_app_config
|
||||
@ -87,6 +88,7 @@ def update_application_config(auth_user: User) -> Union[Dict, HttpResponse]:
|
||||
|
||||
{
|
||||
"data": {
|
||||
"admin_contact": "admin@example.com",
|
||||
"gpx_limit_import": 10,
|
||||
"is_registration_enabled": true,
|
||||
"max_single_file_size": 1048576,
|
||||
@ -96,6 +98,7 @@ def update_application_config(auth_user: User) -> Union[Dict, HttpResponse]:
|
||||
"status": "success"
|
||||
}
|
||||
|
||||
:<json string admin_contact: email to contact the administrator
|
||||
:<json integer gpx_limit_import: max number of files in zip archive
|
||||
:<json boolean is_registration_enabled: is registration enabled ?
|
||||
:<json integer max_single_file_size: max size of a single file
|
||||
@ -110,6 +113,7 @@ def update_application_config(auth_user: User) -> Union[Dict, HttpResponse]:
|
||||
- provide a valid auth token
|
||||
- signature expired, please log in again
|
||||
- invalid token, please log in again
|
||||
- valid email must be provided for admin contact
|
||||
:statuscode 403: you do not have permissions
|
||||
:statuscode 500: error when updating configuration
|
||||
"""
|
||||
@ -118,6 +122,9 @@ def update_application_config(auth_user: User) -> Union[Dict, HttpResponse]:
|
||||
return InvalidPayloadErrorResponse()
|
||||
|
||||
ret = verify_app_config(config_data)
|
||||
admin_contact = config_data.get('admin_contact')
|
||||
if admin_contact and not is_valid_email(admin_contact):
|
||||
ret.append('valid email must be provided for admin contact')
|
||||
if ret:
|
||||
return InvalidPayloadErrorResponse(message=ret)
|
||||
|
||||
@ -133,6 +140,8 @@ def update_application_config(auth_user: User) -> Union[Dict, HttpResponse]:
|
||||
config.max_zip_file_size = config_data.get('max_zip_file_size')
|
||||
if 'max_users' in config_data:
|
||||
config.max_users = config_data.get('max_users')
|
||||
if 'admin_contact' in config_data:
|
||||
config.admin_contact = admin_contact if admin_contact else None
|
||||
|
||||
if config.max_zip_file_size < config.max_single_file_size:
|
||||
return InvalidPayloadErrorResponse(
|
||||
|
@ -23,6 +23,7 @@ class AppConfig(BaseModel):
|
||||
db.Integer, default=1048576, nullable=False
|
||||
)
|
||||
max_zip_file_size = db.Column(db.Integer, default=10485760, nullable=False)
|
||||
admin_contact = db.Column(db.String(255), nullable=True)
|
||||
|
||||
@property
|
||||
def is_registration_enabled(self) -> bool:
|
||||
@ -43,6 +44,7 @@ class AppConfig(BaseModel):
|
||||
|
||||
def serialize(self) -> Dict:
|
||||
return {
|
||||
'admin_contact': self.admin_contact,
|
||||
'gpx_limit_import': self.gpx_limit_import,
|
||||
'is_registration_enabled': self.is_registration_enabled,
|
||||
'max_single_file_size': self.max_single_file_size,
|
||||
|
Reference in New Issue
Block a user