diff --git a/services/admin_service/controllers/sys_config.py b/services/admin_service/controllers/sys_config.py index fc0d3f6..bf3b0c4 100644 --- a/services/admin_service/controllers/sys_config.py +++ b/services/admin_service/controllers/sys_config.py @@ -15,6 +15,10 @@ from services.admin_service.services.platform_report_service import PlatformRepo from services.admin_service.constants import sys_config_key from services.common.logging_config import get_logger from services.admin_service.utils.ip import get_public_ip, get_local_ip +from services.common.utils.validation_utils import ValidationUtils +from services.common.exceptions import ValidationException + + logger = get_logger(__name__) @@ -237,7 +241,12 @@ def set_sysconfig( email_smtp_password = email_config.get("smtp_password") email_smtp_sender = email_config.get("smtp_sender") - + if not domain: + # 正则检查domain格式 + try: + domain = ValidationUtils.validate_domain(domain) + except ValidationException as e: + return ResponseUtils.error(message=str(e), code=400) # Batch update configuration configs = [ diff --git a/services/admin_service/repositories/user_repository.py b/services/admin_service/repositories/user_repository.py index 8490d99..4bdb36b 100644 --- a/services/admin_service/repositories/user_repository.py +++ b/services/admin_service/repositories/user_repository.py @@ -85,7 +85,7 @@ class UserRepository: def get_user_list(self, offset: int, limit: int) -> Tuple[int, List[User]]: total = self.db.query(User).filter(User.is_deleted == 0, User.role_id == 2).count() - users = self.db.query(User).filter(User.is_deleted == 0, User.role_id == 2).offset(offset).limit(limit).all() + users = self.db.query(User).filter(User.is_deleted == 0, User.role_id == 2).order_by(User.created_at.desc()).offset(offset).limit(limit).all() return total, users def get_admin_user(self) -> Optional[User]: diff --git a/services/admin_service/services/mcp_manager_service.py b/services/admin_service/services/mcp_manager_service.py index 199f564..68ab929 100644 --- a/services/admin_service/services/mcp_manager_service.py +++ b/services/admin_service/services/mcp_manager_service.py @@ -472,7 +472,7 @@ class McpManagerService: # 5. Build return data apis_list = [] for temp_api in temp_apis: - api_dict = {"id": temp_api.id, "name": temp_api.name, "description": temp_api.description} + api_dict = {"id": temp_api.id, "name": temp_api.name,"url": temp_api.path, "description": temp_api.description} apis_list.append(api_dict) result = { diff --git a/services/common/utils/validation_utils.py b/services/common/utils/validation_utils.py index 41f724c..20e7246 100644 --- a/services/common/utils/validation_utils.py +++ b/services/common/utils/validation_utils.py @@ -120,6 +120,31 @@ class ValidationUtils: raise ValidationException(f"Parameter '{param_name}' must be a valid HTTP/HTTPS URL") return url + @staticmethod + def validate_domain(domain: str, param_name: str = "domain") -> str: + """ + Validate domain format + + Args: + domain: The domain to validate + param_name: Name of the parameter for error message + + Returns: + The validated domain + + Raises: + ValidationException: If domain format is invalid + """ + if not domain or not isinstance(domain, str): + raise ValidationException(f"Parameter '{param_name}' must be a valid domain name") + + domain = domain.strip().lower() + domain_pattern = r'^(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,})$' + + if not re.match(domain_pattern, domain): + raise ValidationException(f"Parameter '{param_name}' must be a valid domain name") + + return domain @staticmethod def validate_pagination(page: Any, page_size: Any) -> Tuple[int, int]: