feat: add direct-save CMS and About archive
This commit is contained in:
@@ -80,3 +80,32 @@ def action(value):
|
||||
text(value["label"], 40, required=True)
|
||||
if not isinstance(value["route_id"], str) or value["route_id"] not in ROUTES - {"home"}:
|
||||
raise ValidationError("Action route is not approved.")
|
||||
|
||||
|
||||
def action_url(value):
|
||||
if not value:
|
||||
return
|
||||
if not isinstance(value, str) or value != value.strip() or "\\" in value or any(ord(char) < 32 for char in value):
|
||||
raise ValidationError("Use a root-relative path or a secure https URL.")
|
||||
try:
|
||||
parsed = urlsplit(value)
|
||||
except ValueError as exc:
|
||||
raise ValidationError("Invalid action URL.") from exc
|
||||
if value.startswith("/"):
|
||||
if value.startswith("//") or parsed.scheme or parsed.netloc:
|
||||
raise ValidationError("Internal links must be root-relative paths.")
|
||||
return
|
||||
if parsed.scheme != "https" or not parsed.netloc or parsed.username or parsed.password:
|
||||
raise ValidationError("External action URLs must use https and cannot include credentials.")
|
||||
external_https_url(value)
|
||||
|
||||
|
||||
def external_https_url(value):
|
||||
try:
|
||||
parsed = urlsplit(value)
|
||||
hostname = parsed.hostname
|
||||
parsed.port
|
||||
except (AttributeError, ValueError) as exc:
|
||||
raise ValidationError("Enter a valid https URL without credentials.") from exc
|
||||
if parsed.scheme != "https" or not hostname or parsed.username or parsed.password:
|
||||
raise ValidationError("Enter a valid https URL without credentials.")
|
||||
|
||||
Reference in New Issue
Block a user