Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/V1Module/presenters/AssignmentsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use App\Helpers\MetaFormats\Validators\VBool;
use App\Helpers\MetaFormats\Validators\VDouble;
use App\Helpers\MetaFormats\Validators\VInt;
use App\Helpers\MetaFormats\Validators\VMixed;
use App\Helpers\MetaFormats\Validators\VString;
use App\Helpers\MetaFormats\Validators\VTimestamp;
use App\Helpers\MetaFormats\Validators\VUuid;
Expand Down Expand Up @@ -668,7 +667,13 @@ public function checkRemove(string $id)
#[Path("id", new VUuid(), "Identifier of the assignment to be removed", required: true)]
public function actionRemove(string $id)
{
$this->assignments->remove($this->assignments->findOrThrow($id));
$assignment = $this->assignments->findOrThrow($id);
$asyncJobs = $this->asyncJobs->findPendingJobs(null, true, null, $assignment); // all jobs of the assignment
foreach ($asyncJobs as $job) {
$this->dispatcher->unschedule($job);
}

$this->assignments->remove($assignment);
$this->sendSuccessResponse("OK");
}

Expand Down
2 changes: 1 addition & 1 deletion app/async/handlers/AssignmentNotificationJobHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function execute(AsyncJob $job)
}

$assignment = $job->getAssociatedAssignment();
if ($assignment) {
if ($assignment && !$assignment->isDeleted()) {
$this->assignmentEmailsSender->assignmentCreated($assignment);
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/async/handlers/ResubmitAllAsyncJobHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function execute(AsyncJob $job)
$this->canceled = false;

$assignment = $job->getAssociatedAssignment();
if (!$assignment) {
if (!$assignment || $assignment->isDeleted()) {
throw new InvalidArgumentException("Resubmit all async job is not attached to any assignment.");
}

Expand Down
12 changes: 11 additions & 1 deletion tests/Presenters/AssignmentsPresenter.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use App\Helpers\FileStorage\LocalFileStorage;
use App\Helpers\FileStorage\LocalHashFileStorage;
use App\V1Module\Presenters\AssignmentsPresenter;
use App\Security\Roles;
use App\Async\Handler\AssignmentNotificationJobHandler;
use Doctrine\ORM\EntityManagerInterface;
use Tester\Assert;
use App\Helpers\JobConfig;
Expand Down Expand Up @@ -922,9 +923,18 @@ class TestAssignmentsPresenter extends Tester\TestCase

public function testRemove()
{
$token = PresenterTestHelper::loginDefaultAdmin($this->container);
PresenterTestHelper::loginDefaultAdmin($this->container);
$user = PresenterTestHelper::getUser($this->container);

$assignment = current($this->assignments->findAll());
$assignment->setVisibleFrom((new DateTime())->modify('+1 day'));
$this->presenter->assignments->persist($assignment);

AssignmentNotificationJobHandler::scheduleAsyncJob($this->presenter->dispatcher, $user, $assignment);

$mockDispatcher = Mockery::mock(\App\Async\Dispatcher::class);
$mockDispatcher->shouldReceive("unschedule")->once();
$this->presenter->dispatcher = $mockDispatcher;

$request = new Nette\Application\Request(
'V1:Assignments',
Expand Down