Skip to content

Commit

Permalink
Merge branch 'release-15.14.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Oct 20, 2023
2 parents cb21fa8 + a9e1286 commit a5ff316
Showing 1 changed file with 63 additions and 5 deletions.
68 changes: 63 additions & 5 deletions controller/AuthoringTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,22 @@
use helpers_Random;
use InterruptedActionException;
use OAT\Library\Lti1p3Core\Message\Payload\LtiMessagePayloadInterface;
use oat\tao\model\featureFlag\FeatureFlagChecker;
use oat\tao\model\featureFlag\FeatureFlagCheckerInterface;
use oat\taoLti\models\classes\LtiException;
use oat\taoLti\models\classes\LtiMessages\LtiErrorMessage;
use oat\taoLti\models\classes\LtiService;
use oat\taoLti\models\classes\Tool\Validation\Lti1p3Validator;
use oat\taoLti\models\classes\user\UserService;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use tao_actions_Main;
use tao_models_classes_UserService;

class AuthoringTool extends ToolModule
{
private const LTI_NO_MATCHING_REGISTRATION_FOUND_MESSAGE = 'No matching registration found tool side';

/**
* @throws LtiException
* @throws InterruptedActionException
Expand All @@ -55,6 +61,9 @@ public function run(): void
}
}

/**
* @throws LtiException
*/
protected function getValidatedLtiMessagePayload(): LtiMessagePayloadInterface
{
return $this->getServiceLocator()
Expand All @@ -64,27 +73,76 @@ protected function getValidatedLtiMessagePayload(): LtiMessagePayloadInterface
}

/**
* @throws common_exception_Error
* @throws ActionEnforcingException
* @throws InterruptedActionException
* @throws LtiException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws common_exception_Error
*/
public function launch(): void
{
$message = $this->getValidatedLtiMessagePayload();
$ltiMessage = $this->getLtiMessageOrRedirectToLogin();

$user = $this->getServiceLocator()
->getContainer()
->get(tao_models_classes_UserService::class)
->addUser(
$message->getUserIdentity()->getIdentifier(),
$ltiMessage->getUserIdentity()->getIdentifier(),
helpers_Random::generateString(UserService::PASSWORD_LENGTH),
new core_kernel_classes_Resource(current($message->getRoles()))
new core_kernel_classes_Resource(current($ltiMessage->getRoles()))
);
$this->getServiceLocator()
->getContainer()
->get(LtiService::class)
->startLti1p3Session($message, $user);
->startLti1p3Session($ltiMessage, $user);

$this->forward('run', null, null, $_GET);
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
private function isFeatureTaoAsToolEnabled(): bool
{
return $this->getServiceManager()
->getContainer()
->get(FeatureFlagChecker::class)
->isEnabled(FeatureFlagCheckerInterface::FEATURE_FLAG_TAO_AS_A_TOOL);
}

/**
* @throws ContainerExceptionInterface
* @throws InterruptedActionException
* @throws LtiException
* @throws NotFoundExceptionInterface
*/
private function getLtiMessageOrRedirectToLogin(): LtiMessagePayloadInterface
{
if (!$this->isFeatureTaoAsToolEnabled()) {
$this->getLogger()->info(
'TAO as tool feature is disabled. The user will be redirected to the login page.'
);
$this->redirect(_url('login', 'Main', 'tao'));
}

try {
$message = $this->getValidatedLtiMessagePayload();
} catch (LtiException $exception) {
if ($exception->getMessage() !== self::LTI_NO_MATCHING_REGISTRATION_FOUND_MESSAGE) {
throw $exception;
}

$this->getLogger()->warning(
sprintf(
'Missing registration for current audience. Redirecting to the login page. Exception: %s',
$exception
)
);
$this->redirect(_url('login', 'Main', 'tao'));
}

return $message;
}
}

0 comments on commit a5ff316

Please sign in to comment.