wip
This commit is contained in:
parent
30e9c9328e
commit
254593d260
20 changed files with 156 additions and 65 deletions
38
app/utils/validators.py
Normal file
38
app/utils/validators.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
def validate_app_data(name, server_id, existing_app_id=None):
|
||||
"""
|
||||
Validate application data, checking for required fields and uniqueness
|
||||
|
||||
Args:
|
||||
name: The application name
|
||||
server_id: The server ID
|
||||
existing_app_id: The ID of the application being edited (if any)
|
||||
|
||||
Returns:
|
||||
tuple: (valid, error_message)
|
||||
"""
|
||||
# Check for required fields
|
||||
if not name or not name.strip():
|
||||
return False, "Application name is required"
|
||||
|
||||
if not server_id:
|
||||
return False, "Server is required"
|
||||
|
||||
# Check name length
|
||||
if len(name) < 2:
|
||||
return False, "Application name must be at least 2 characters"
|
||||
|
||||
# Check for uniqueness of name on the server
|
||||
from app.models import App
|
||||
|
||||
query = App.query.filter(App.name == name, App.server_id == server_id)
|
||||
|
||||
# If editing an existing app, exclude it from the uniqueness check
|
||||
if existing_app_id:
|
||||
query = query.filter(App.id != existing_app_id)
|
||||
|
||||
existing_app = query.first()
|
||||
|
||||
if existing_app:
|
||||
return False, f"Application '{name}' already exists on this server"
|
||||
|
||||
return True, None
|
Loading…
Add table
Add a link
Reference in a new issue