Skip to content

Commit 836c2e1

Browse files
committed
Fixing group presented to have proper ReCodEx API injected.
1 parent 0f1da8f commit 836c2e1

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

app/presenters/GroupsPresenter.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
use App\Exceptions\BadRequestException;
66
use App\Exceptions\ForbiddenRequestException;
77
use App\Exceptions\NotFoundException;
8-
use App\Exceptions\NotImplementedException;
9-
use App\Helpers\RecodexApiHelper;
108
use App\Helpers\RecodexGroup;
119
use App\Model\Entity\SisScheduleEvent;
1210
use App\Model\Repository\SisScheduleEvents;
@@ -16,20 +14,14 @@
1614
/**
1715
* Group management (both for teachers and students).
1816
*/
19-
class GroupsPresenter extends BasePresenter
17+
class GroupsPresenter extends BasePresenterWithApi
2018
{
2119
/**
2220
* @var SisScheduleEvents
2321
* @inject
2422
*/
2523
public $sisEvents;
2624

27-
/**
28-
* @var RecodexApiHelper
29-
* @inject
30-
*/
31-
public $recodexApi;
32-
3325
/**
3426
* @var IEventPermissions
3527
* @inject

app/presenters/base/BasePresenterWithApi.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ class BasePresenterWithApi extends BasePresenter
2525

2626
public function startup()
2727
{
28-
parent::startup();
29-
3028
// Initialize ReCodEx auth token (main part is in User entity, suffix is in our auth token's payload).
3129
$user = $this->getCurrentUser();
3230
$token = $this->getAccessToken();
33-
$suffix = $token->getPayload('suffix');
31+
$suffix = $token->getPayloadOrDefault('suffix', null);
3432

3533
if ($user->getRecodexToken() && $suffix) {
3634
$this->recodexApi->setAuthToken($user->getRecodexToken() . $suffix);
3735
}
36+
37+
// the parent startup performs authorization checks, so it must be called after we set the token
38+
// (some presenters check permissions via ReCodEx API)
39+
parent::startup();
3840
}
3941
}

tests/Presenters/GroupsPresenter.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
$container = require_once __DIR__ . "/../bootstrap.php";
44

55
use App\Helpers\RecodexApiHelper;
6+
use App\Helpers\SisHelper;
67
use App\Presenters\GroupsPresenter;
78
use App\Exceptions\BadRequestException;
89
use App\Exceptions\ForbiddenRequestException;
@@ -60,6 +61,10 @@ class TestGroupsPresenter extends Tester\TestCase
6061
$this->namingHelper,
6162
$this->client
6263
));
64+
65+
$sisHelperName = current($this->container->findByType(SisHelper::class));
66+
$this->container->removeService($sisHelperName);
67+
$this->container->addService($sisHelperName, Mockery::mock(SisHelper::class));
6368
}
6469

6570
protected function setUp()

0 commit comments

Comments
 (0)