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