Skip to content

Commit

Permalink
Fix order of tryId verification in play/set endpoint when using a tryId
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikdassow committed Aug 9, 2023
1 parent 183f372 commit f8355f3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Hooks/TryIdVerification/TryIdVerificationHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Sowiso\SDK\Api\EvaluateAnswer\EvaluateAnswerCallback;
use Sowiso\SDK\Api\PlayExercise\Data\PlayExerciseOnRequestData;
use Sowiso\SDK\Api\PlayExercise\PlayExerciseCallback;
use Sowiso\SDK\Api\PlayExerciseSet\Data\PlayExerciseSetOnRequestData;
use Sowiso\SDK\Api\PlayExerciseSet\Data\PlayExerciseSetOnSuccessData;
use Sowiso\SDK\Api\PlayExerciseSet\PlayExerciseSetCallback;
use Sowiso\SDK\Api\PlayHint\Data\PlayHintOnRequestData;
Expand Down Expand Up @@ -92,18 +93,23 @@ public function __construct(private TryIdVerificationHook $hook)
{
}

public function onSuccess(PlayExerciseSetOnSuccessData $data): void
public function onRequest(PlayExerciseSetOnRequestData $data): void
{
if ($data->getRequest()->usesAnyReadonlyView()) {
return;
}

if ($data->getRequest()->usesTryId()) {
// Safe to cast to an int because we checked if the try_id is used or not
$tryId = (int) $data->getRequest()->getTryId();

$this->hook->validateTryId($data->getContext(), $data->getPayload(), $tryId);
}
}

public function onSuccess(PlayExerciseSetOnSuccessData $data): void
{
if ($data->getRequest()->usesAnyReadonlyView()) {
return;
}

if ($data->getRequest()->usesTryId()) {
return;
}

Expand Down

0 comments on commit f8355f3

Please sign in to comment.