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,32 +257,28 @@ function deleteSelectedAwards(event) {
});
}
function correctUserSubmission(event) {
function solveSelectedMissingChallenges(event) {
event.preventDefault();
const challenge_id = $(this).attr("challenge-id");
const challenge_name = $(this).attr("challenge-name");
const row = $(this)
.parent()
.parent();
let challengeIDs = $("input[data-missing-challenge-id]:checked").map(function() {
return $(this).data("missing-challenge-id");
});
let target = challengeIDs.length === 1 ? "challenge" : "challenges";
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 = {
ezQuery({
title: `Mark Correct`,
body: `Are you sure you want to mark ${challengeIDs.length} correct for ${htmlEntities(USER_NAME)}?`,
success: function() {
const reqs = [];
for (var challengeID of challengeIDs) {
let params = {
provided: "MARKED AS SOLVED BY ADMIN",
user_id: USER_ID,
team_id: TEAM_ID,
challenge_id: challenge_id,
challenge_id: challengeID,
type: "correct"
};
ezQuery({
title: "Mark Correct",
body: body,
success: function() {
CTFd.fetch("/api/v1/submissions", {
let req = CTFd.fetch("/api/v1/submissions", {
method: "POST",
credentials: "same-origin",
headers: {
@ -291,15 +287,10 @@ function correctUserSubmission(event) {
},
body: JSON.stringify(params)
})
.then(function(response) {
return response.json();
})
.then(function(response) {
if (response.success) {
// TODO: Refresh missing and solves instead of reloading
row.remove();
window.location.reload();
reqs.push(req);
}
Promise.all(reqs).then(responses => {
window.location.reload();
});
}
});
@ -427,7 +418,9 @@ $(() => {
deleteSelectedAwards(e);
});
$(".correct-submission").click(correctUserSubmission);
$("#missing-solve-button").click(function(e){
solveSelectedMissingChallenges(e);
});
$("#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 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="col-md-12">
<table class="table table-striped">
<h3 class="text-center py-3 d-block">Missing</h3>
<div class="float-right pb-3">
<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>
<tr>
<td class="text-center"><b>Challenge</b></td>
<td class="text-center"><b>Category</b></td>
<td class="text-center"><b>Value</b></td>
<td class="text-center"><b>Mark Solved</b></td>
<th class="border-right" data-checkbox>
<div class="form-check text-center">
<input type="checkbox" class="form-check-input" data-checkbox-all>&nbsp;
</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>
</thead>
<tbody>
{% for challenge in missing %}
<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 }}">
<a href="{{ url_for("admin.challenges_detail", challenge_id=challenge.id) }}">
{{ challenge.name }}
@ -398,13 +419,13 @@
</td>
<td class="text-center">{{ challenge.category }}</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 }}"
challenge-name="{{ challenge.name }}"
data-placement="top" title="Mark {{ challenge.name }} correct for {{ user.name }}">
<i class="fas fa-check"></i>
</a>
</td>
</td> -->
</tr>
{% endfor %}
</tbody>