Skip to content

Commit

Permalink
Add a warning log when clarifications are claimed
Browse files Browse the repository at this point in the history
  • Loading branch information
as6325400 committed Oct 27, 2024
1 parent 2d6f4ff commit 9bf826b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
19 changes: 19 additions & 0 deletions webapp/src/Controller/Jury/ClarificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,25 @@ public function changeQueueAction(Request $request, int $clarId): Response
return $this->redirectToRoute('jury_clarification', ['id' => $clarId]);
}

#[Route('/check-claimed', name: 'check_if_claimed', methods: ['GET'])]
public function checkIfClaimed(Request $request): Response
{
$clarid = $request->query->get('clarid');
$currentUserName = $this->getUser()->getuserName();

$queryBuilder = $this->em->createQueryBuilder()
->select('clar.jury_member')
->from(Clarification::class, 'clar')
->where('clar.clarid = :clarid')
->setParameter('clarid', $clarid);
$claimedJuryMember = $queryBuilder->getQuery()->getSingleResult();

return $this->json([
'isClaimedByOther' => $claimedJuryMember['jury_member'] !== null && $claimedJuryMember['jury_member'] !== $currentUserName,
'ClaimedBy' => $claimedJuryMember['jury_member'],
]);
}

protected function processSubmittedClarification(
FormInterface $form,
?Clarification $inReplTo = null
Expand Down
27 changes: 27 additions & 0 deletions webapp/templates/jury/partials/clarification_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,30 @@

</div>
{{ form_end(form) }}

<script>
$(function () {
var $body = $('body');
$body.on('submit', 'form[name=jury_clarification]', function () {
var clarid = {{ origclar | json_encode(constant('JSON_HEX_TAG')) | raw }}.clarid;
fetch(`/jury/clarifications/check-claimed?clarid=${clarid}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
}
})
.then(response => response.json())
.then(data => {
if (data.isClaimedByOther === true) {
confirm(`This clarification has been claimed by ${data.ClaimedBy}. Are you sure you want to send this message?`);
}
})
.catch(error => {
console.error('Error:', error);
alert('An error occurred while checking claim status.');
});
});
});
</script>

0 comments on commit 9bf826b

Please sign in to comment.