mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 06:24:23 +01:00
Fix misc bugs
This commit is contained in:
@@ -211,32 +211,33 @@ class TeamSchema(ma.ModelSchema):
|
||||
else:
|
||||
target_team = current_team
|
||||
|
||||
provided_ids = []
|
||||
for f in fields:
|
||||
f.pop("id", None)
|
||||
field_id = f.get("field_id")
|
||||
if self.view == "admin":
|
||||
provided_ids = []
|
||||
for f in fields:
|
||||
f.pop("id", None)
|
||||
field_id = f.get("field_id")
|
||||
|
||||
# # 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()
|
||||
# # 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()
|
||||
|
||||
# Get the existing field entry if one exists
|
||||
entry = TeamFieldEntries.query.filter_by(
|
||||
field_id=field.id, team_id=target_team.id
|
||||
).first()
|
||||
if entry:
|
||||
f["id"] = entry.id
|
||||
provided_ids.append(entry.id)
|
||||
# Get the existing field entry if one exists
|
||||
entry = TeamFieldEntries.query.filter_by(
|
||||
field_id=field.id, team_id=target_team.id
|
||||
).first()
|
||||
if entry:
|
||||
f["id"] = entry.id
|
||||
provided_ids.append(entry.id)
|
||||
|
||||
# Extremely dirty hack to prevent deleting previously provided data.
|
||||
# This needs a better soln.
|
||||
entries = (
|
||||
TeamFieldEntries.query.options(load_only("id"))
|
||||
.filter_by(team_id=target_team.id)
|
||||
.all()
|
||||
)
|
||||
for entry in entries:
|
||||
if entry.id not in provided_ids:
|
||||
fields.append({"id": entry.id})
|
||||
# Extremely dirty hack to prevent deleting previously provided data.
|
||||
# This needs a better soln.
|
||||
entries = (
|
||||
TeamFieldEntries.query.options(load_only("id"))
|
||||
.filter_by(team_id=target_team.id)
|
||||
.all()
|
||||
)
|
||||
for entry in entries:
|
||||
if entry.id not in provided_ids:
|
||||
fields.append({"id": entry.id})
|
||||
else:
|
||||
provided_ids = []
|
||||
for f in fields:
|
||||
|
||||
@@ -205,32 +205,33 @@ class UserSchema(ma.ModelSchema):
|
||||
else:
|
||||
target_user = current_user
|
||||
|
||||
provided_ids = []
|
||||
for f in fields:
|
||||
f.pop("id", None)
|
||||
field_id = f.get("field_id")
|
||||
if self.view == "admin":
|
||||
provided_ids = []
|
||||
for f in fields:
|
||||
f.pop("id", None)
|
||||
field_id = f.get("field_id")
|
||||
|
||||
# # 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()
|
||||
# # 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()
|
||||
|
||||
# Get the existing field entry if one exists
|
||||
entry = UserFieldEntries.query.filter_by(
|
||||
field_id=field.id, user_id=target_user.id
|
||||
).first()
|
||||
if entry:
|
||||
f["id"] = entry.id
|
||||
provided_ids.append(entry.id)
|
||||
# Get the existing field entry if one exists
|
||||
entry = UserFieldEntries.query.filter_by(
|
||||
field_id=field.id, user_id=target_user.id
|
||||
).first()
|
||||
if entry:
|
||||
f["id"] = entry.id
|
||||
provided_ids.append(entry.id)
|
||||
|
||||
# Extremely dirty hack to prevent deleting previously provided data.
|
||||
# This needs a better soln.
|
||||
entries = (
|
||||
UserFieldEntries.query.options(load_only("id"))
|
||||
.filter_by(user_id=target_user.id)
|
||||
.all()
|
||||
)
|
||||
for entry in entries:
|
||||
if entry.id not in provided_ids:
|
||||
fields.append({"id": entry.id})
|
||||
# Extremely dirty hack to prevent deleting previously provided data.
|
||||
# This needs a better soln.
|
||||
entries = (
|
||||
UserFieldEntries.query.options(load_only("id"))
|
||||
.filter_by(user_id=target_user.id)
|
||||
.all()
|
||||
)
|
||||
for entry in entries:
|
||||
if entry.id not in provided_ids:
|
||||
fields.append({"id": entry.id})
|
||||
else:
|
||||
provided_ids = []
|
||||
for f in fields:
|
||||
|
||||
@@ -11,6 +11,19 @@ function createTeam(event) {
|
||||
event.preventDefault();
|
||||
const params = $("#team-info-create-form").serializeJSON(true);
|
||||
|
||||
params.fields = [];
|
||||
|
||||
for (const property in params) {
|
||||
if (property.match(/fields\[\d+\]/)) {
|
||||
let field = {};
|
||||
let id = parseInt(property.slice(7, -1));
|
||||
field["field_id"] = id;
|
||||
field["value"] = params[property];
|
||||
params.fields.push(field);
|
||||
delete params[property];
|
||||
}
|
||||
}
|
||||
|
||||
CTFd.fetch("/api/v1/teams", {
|
||||
method: "POST",
|
||||
credentials: "same-origin",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -15,14 +15,17 @@
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{ form.website.label }}
|
||||
<small class="float-right text-muted align-text-bottom">Optional</small>
|
||||
{{ form.website(class="form-control") }}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{ form.affiliation.label }}
|
||||
<small class="float-right text-muted align-text-bottom">Optional</small>
|
||||
{{ form.affiliation(class="form-control") }}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{ form.country.label }}
|
||||
<small class="float-right text-muted align-text-bottom">Optional</small>
|
||||
{{ form.country(class="form-control custom-select") }}
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user