Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| StateValidation | |
0.00% |
0 / 8 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| verifyStartAuthorization | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| verifyResumeAuthorization | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| getResumableStates | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2016 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoDelivery\model\authorization\strategy; |
| 23 | |
| 24 | use oat\oatbox\service\ConfigurableService; |
| 25 | use oat\taoDelivery\model\authorization\AuthorizationProvider; |
| 26 | use oat\taoDelivery\model\execution\DeliveryExecution; |
| 27 | use oat\oatbox\user\User; |
| 28 | use oat\taoDelivery\model\execution\DeliveryExecutionInterface; |
| 29 | |
| 30 | /** |
| 31 | * Verifies that the current state of a delivery execution allows resuming |
| 32 | */ |
| 33 | class StateValidation extends ConfigurableService implements AuthorizationProvider |
| 34 | { |
| 35 | /** |
| 36 | * (non-PHPdoc) |
| 37 | * @see \oat\taoDelivery\model\authorization\AuthorizationProvider::verifyStartAuthorization() |
| 38 | */ |
| 39 | public function verifyStartAuthorization($deliveryId, User $user) |
| 40 | { |
| 41 | // nothign to check, no state yet |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Verify that a given delivery execution is allowed to be executed |
| 46 | * |
| 47 | * @param DeliveryExecutionInterface $deliveryExecution |
| 48 | * @param User $user |
| 49 | * @throws \common_exception_Unauthorized |
| 50 | */ |
| 51 | public function verifyResumeAuthorization(DeliveryExecutionInterface $deliveryExecution, User $user) |
| 52 | { |
| 53 | $stateId = $deliveryExecution->getState()->getUri(); |
| 54 | if (!in_array($stateId, $this->getResumableStates())) { |
| 55 | \common_Logger::w( |
| 56 | 'Unexpected state "' . $stateId . '; delivery execution: ' . $deliveryExecution->getIdentifier() |
| 57 | ); |
| 58 | throw new \common_exception_Unauthorized(); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | public function getResumableStates() |
| 63 | { |
| 64 | return [DeliveryExecution::STATE_ACTIVE, DeliveryExecution::STATE_PAUSED]; |
| 65 | } |
| 66 | } |