mirror of
https://github.com/aljazceru/CTFd.git
synced 2026-02-14 02:34:23 +01:00
Require required fields in schemas
This commit is contained in:
@@ -246,13 +246,20 @@ class TeamSchema(ma.ModelSchema):
|
||||
# Remove any existing set
|
||||
f.pop("id", None)
|
||||
field_id = f.get("field_id")
|
||||
value = f.get("value")
|
||||
|
||||
# # Check that we have an existing field for this. May be unnecessary b/c the foriegn key should enforce
|
||||
field = TeamFields.query.filter_by(id=field_id).first_or_404()
|
||||
|
||||
if field.required is True and value.strip() == "":
|
||||
raise ValidationError(
|
||||
f"Field '{field.name}' is required", field_names=["fields"]
|
||||
)
|
||||
|
||||
if field.editable is False:
|
||||
raise ValidationError(
|
||||
f"Field {field.name} cannot be editted", field_names=["fields"]
|
||||
f"Field '{field.name}' cannot be editted",
|
||||
field_names=["fields"],
|
||||
)
|
||||
|
||||
# Get the existing field entry if one exists
|
||||
|
||||
@@ -240,13 +240,20 @@ class UserSchema(ma.ModelSchema):
|
||||
# Remove any existing set
|
||||
f.pop("id", None)
|
||||
field_id = f.get("field_id")
|
||||
value = f.get("value")
|
||||
|
||||
# # Check that we have an existing field for this. May be unnecessary b/c the foriegn key should enforce
|
||||
field = UserFields.query.filter_by(id=field_id).first_or_404()
|
||||
|
||||
if field.required is True and value.strip() == "":
|
||||
raise ValidationError(
|
||||
f"Field '{field.name}' is required", field_names=["fields"]
|
||||
)
|
||||
|
||||
if field.editable is False:
|
||||
raise ValidationError(
|
||||
f"Field {field.name} cannot be editted", field_names=["fields"]
|
||||
f"Field '{field.name}' cannot be editted",
|
||||
field_names=["fields"],
|
||||
)
|
||||
|
||||
# Get the existing field entry if one exists
|
||||
|
||||
Reference in New Issue
Block a user