Make bulk mark correct work for users

bulk-table-profile-actions
Kevin Chung 2020-05-02 14:35:47 -04:00
parent c101204879
commit 76bd626c36
3 changed files with 63 additions and 49 deletions

View File

@ -257,50 +257,41 @@ function deleteSelectedAwards(event) {
}); });
} }
function correctUserSubmission(event) { function solveSelectedMissingChallenges(event) {
event.preventDefault(); event.preventDefault();
const challenge_id = $(this).attr("challenge-id"); let challengeIDs = $("input[data-missing-challenge-id]:checked").map(function() {
const challenge_name = $(this).attr("challenge-name"); return $(this).data("missing-challenge-id");
const row = $(this) });
.parent() let target = challengeIDs.length === 1 ? "challenge" : "challenges";
.parent();
const body = "<span>Are you sure you want to mark <strong>{0}</strong> solved for from <strong>{1}</strong>?".format(
htmlEntities(challenge_name),
htmlEntities(USER_NAME)
);
const params = {
provided: "MARKED AS SOLVED BY ADMIN",
user_id: USER_ID,
team_id: TEAM_ID,
challenge_id: challenge_id,
type: "correct"
};
ezQuery({ ezQuery({
title: "Mark Correct", title: `Mark Correct`,
body: body, body: `Are you sure you want to mark ${challengeIDs.length} correct for ${htmlEntities(USER_NAME)}?`,
success: function() { success: function() {
CTFd.fetch("/api/v1/submissions", { const reqs = [];
method: "POST", for (var challengeID of challengeIDs) {
credentials: "same-origin", let params = {
headers: { provided: "MARKED AS SOLVED BY ADMIN",
Accept: "application/json", user_id: USER_ID,
"Content-Type": "application/json" team_id: TEAM_ID,
}, challenge_id: challengeID,
body: JSON.stringify(params) type: "correct"
}) };
.then(function(response) {
return response.json(); let req = CTFd.fetch("/api/v1/submissions", {
method: "POST",
credentials: "same-origin",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify(params)
}) })
.then(function(response) { reqs.push(req);
if (response.success) { }
// TODO: Refresh missing and solves instead of reloading Promise.all(reqs).then(responses => {
row.remove(); window.location.reload();
window.location.reload(); });
}
});
} }
}); });
} }
@ -427,7 +418,9 @@ $(() => {
deleteSelectedAwards(e); deleteSelectedAwards(e);
}); });
$(".correct-submission").click(correctUserSubmission); $("#missing-solve-button").click(function(e){
solveSelectedMissingChallenges(e);
});
$("#user-info-create-form").submit(createUser); $("#user-info-create-form").submit(createUser);

File diff suppressed because one or more lines are too long

View File

@ -376,21 +376,42 @@
</div> </div>
<div class="tab-pane fade" id="nav-missing" role="tabpanel" aria-labelledby="nav-missing-tab"> <div class="tab-pane fade" id="nav-missing" role="tabpanel" aria-labelledby="nav-missing-tab">
<h3 class="text-center pt-5 d-block">Missing</h3>
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<table class="table table-striped"> <div class="float-right pb-3">
<h3 class="text-center py-3 d-block">Missing</h3> <div class="btn-group" role="group">
<button type="button" class="btn btn-outline-success" id="missing-solve-button">
<i class="btn-fa fas fa-check"></i>
</button>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<table class="table table-striped border">
<thead> <thead>
<tr> <tr>
<td class="text-center"><b>Challenge</b></td> <th class="border-right" data-checkbox>
<td class="text-center"><b>Category</b></td> <div class="form-check text-center">
<td class="text-center"><b>Value</b></td> <input type="checkbox" class="form-check-input" data-checkbox-all>&nbsp;
<td class="text-center"><b>Mark Solved</b></td> </div>
</th>
<th class="sort-col text-center"><b>Challenge</b></th>
<th class="sort-col text-center"><b>Category</b></th>
<th class="sort-col text-center"><b>Value</b></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for challenge in missing %} {% for challenge in missing %}
<tr class="chal-solve" data-href="{{ url_for("admin.challenges_detail", challenge_id=challenge.id) }}"> <tr class="chal-solve" data-href="{{ url_for("admin.challenges_detail", challenge_id=challenge.id) }}">
<td class="border-right" data-checkbox>
<div class="form-check text-center">
<input type="checkbox" class="form-check-input" value="{{ challenge.id }}" data-missing-challenge-id="{{ challenge.id }}"
data-missing-challenge-name="{{ challenge.name }}">&nbsp;
</div>
</td>
<td class="text-center chal" id="{{ challenge.id }}"> <td class="text-center chal" id="{{ challenge.id }}">
<a href="{{ url_for("admin.challenges_detail", challenge_id=challenge.id) }}"> <a href="{{ url_for("admin.challenges_detail", challenge_id=challenge.id) }}">
{{ challenge.name }} {{ challenge.name }}
@ -398,13 +419,13 @@
</td> </td>
<td class="text-center">{{ challenge.category }}</td> <td class="text-center">{{ challenge.category }}</td>
<td class="text-center">{{ challenge.value }}</td> <td class="text-center">{{ challenge.value }}</td>
<td class="text-center"> <!-- <td class="text-center">
<a class="correct-submission" data-toggle="tooltip" challenge-id="{{ challenge.id }}" <a class="correct-submission" data-toggle="tooltip" challenge-id="{{ challenge.id }}"
challenge-name="{{ challenge.name }}" challenge-name="{{ challenge.name }}"
data-placement="top" title="Mark {{ challenge.name }} correct for {{ user.name }}"> data-placement="top" title="Mark {{ challenge.name }} correct for {{ user.name }}">
<i class="fas fa-check"></i> <i class="fas fa-check"></i>
</a> </a>
</td> </td> -->
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>