-
Notifications
You must be signed in to change notification settings - Fork 256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a warning log when clarifications are claimed #2766
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'])] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of adding another endpoint here, let's just re-use the existing API endpoint for clarifications. It currently doesn't have the info on whether a clarification has been claimed, but that can be added easily. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we do this, we also have the info on whether it has been answered before and can use that as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In which API should this be added? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am talking about the default API clarification controller:
As you can see, it doesn't output That means all the logic is in the entity definition. If we check there, you can see the following: https://github.com/DOMjudge/domjudge/blob/main/webapp/src/Entity/Clarification.php#L67 This means it is excluded from serialization in the API. We can change it to
and it should appear. |
||
public function checkIfClaimed(Request $request): Response | ||
{ | ||
$clarid = $request->query->get('clarid'); | ||
$currentUserName = $this->getUser()->getUserIdentifier(); | ||
|
||
$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 | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should also work, doesn't it?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll give it a try. I remember it didn’t work initially, which is why I wrote it this way. |
||||||
|
||||||
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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.