Skip to content

Commit

Permalink
Merge pull request #60 from oat-sa/release-2.0.0
Browse files Browse the repository at this point in the history
Release 2.0.0
  • Loading branch information
antoinerobin authored Mar 31, 2017
2 parents be325c7 + c0c567d commit d6b3646
Show file tree
Hide file tree
Showing 14 changed files with 271 additions and 38 deletions.
3 changes: 2 additions & 1 deletion actions/LtiModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ abstract class LtiModule extends tao_actions_CommonModule
*
* @param string $error error to handle
* @param boolean $returnLink
* @param int $httpStatus
*/
protected function returnError($error, $returnLink = true)
protected function returnError($error, $returnLink = true, $httpStatus = null)
{
$error = new \taoLti_models_classes_LtiException($error);
$this->returnLtiError($error, $returnLink);
Expand Down
15 changes: 12 additions & 3 deletions actions/class.ToolModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ public function launch()
'session' => session_id(),
'redirect' => _url('run', null, null, $_GET))));
} else {
$this->returnError(__('You are not authorized to use this system'));
throw new taoLti_models_classes_LtiException(
__('You are not authorized to use this system'),
\oat\taoLti\models\classes\LtiMessages\LtiErrorMessage::ERROR_UNAUTHORIZED
);
}
} catch (common_user_auth_AuthFailedException $e) {
common_Logger::i($e->getMessage());
$this->returnError(__('The LTI connection could not be established'), false);
throw new taoLti_models_classes_LtiException(
__('The LTI connection could not be established'),
\oat\taoLti\models\classes\LtiMessages\LtiErrorMessage::ERROR_UNAUTHORIZED
);
} catch (\taoLti_models_classes_LtiException $e) {
// In regard of the IMS LTI standard, we have to show a back button that refer to the
// launch_presentation_return_url url param. So we have to retrieve this parameter before trying to start
Expand All @@ -66,7 +72,10 @@ public function launch()
$this->returnLtiError($e, false);
} catch (tao_models_classes_oauth_Exception $e) {
common_Logger::i($e->getMessage());
$this->returnError(__('The LTI connection could not be established'), false);
throw new taoLti_models_classes_LtiException(
__('The LTI connection could not be established'),
\oat\taoLti\models\classes\LtiMessages\LtiErrorMessage::ERROR_UNAUTHORIZED
);
}
}

Expand Down
29 changes: 15 additions & 14 deletions actions/traits/LtiModuleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,25 @@ trait LtiModuleTrait
*/
protected function returnLtiError(\taoLti_models_classes_LtiException $error, $returnLink = true)
{
// full trace of the error
\common_Logger::e($error->__toString());

if (tao_helpers_Request::isAjax()) {
throw new common_exception_IsAjaxAction(__CLASS__ . '::' . __FUNCTION__);
} else {
$session = \common_session_SessionManager::getSession();
if ($session instanceof \taoLti_models_classes_TaoLtiSession) {
$launchData = $session->getLaunchData();
// In regard of the IMS LTI standard, we have to show a back button that refer to the
// launch_presentation_return_url url param. So we have to retrieve this parameter before trying to start
// the session
$consumerLabel = $launchData->getToolConsumerName();
if (!is_null($consumerLabel)) {
$this->setData('consumerLabel', $consumerLabel);
}
$launchData = \taoLti_models_classes_LtiLaunchData::fromRequest(\common_http_Request::currentRequest());

if ($launchData->hasVariable(\taoLti_models_classes_LtiLaunchData::LAUNCH_PRESENTATION_RETURN_URL)) {
$flowController = new FlowController();
$flowController->redirect($this->getLtiReturnUrl($launchData, $error));
}

if ($launchData->hasVariable(\taoLti_models_classes_LtiLaunchData::LAUNCH_PRESENTATION_RETURN_URL)) {
$flowController = new FlowController();
$flowController->redirect($this->getLtiReturnUrl($launchData, $error));
}
// In regard of the IMS LTI standard, we have to show a back button that refer to the
// launch_presentation_return_url url param. So we have to retrieve this parameter before trying to start
// the session
$consumerLabel = $launchData->getToolConsumerName();
if (!is_null($consumerLabel)) {
$this->setData('consumerLabel', $consumerLabel);
}

$this->setData('message', $error->getMessage());
Expand Down
12 changes: 8 additions & 4 deletions manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
*
*
*/
use oat\tao\model\user\TaoRoles;

use oat\tao\model\user\TaoRoles;
use oat\taoLti\scripts\install\InstallServices;
/**
* @author CRP Henri Tudor - TAO Team - {@link http://www.tao.lu}
* @license GPLv2 http://www.opensource.org/licenses/gpl-2.0.php
Expand All @@ -32,10 +33,10 @@
'label' => 'LTI library',
'description' => 'TAO LTI library and helpers',
'license' => 'GPL-2.0',
'version' => '1.11.0',
'version' => '2.0.0',
'author' => 'Open Assessment Technologies SA',
'requires' => array(
'tao' => '>=7.45.5'
'tao' => '>=8.0.1'
),
'models' => array(
'http://www.tao.lu/Ontologies/TAOLTI.rdf',
Expand All @@ -48,7 +49,10 @@
dirname(__FILE__). '/models/ontology/roledefinition.rdf',
dirname(__FILE__). '/models/ontology/ltiroles_person.rdf',
dirname(__FILE__). '/models/ontology/ltiroles_membership.rdf'
)
),
'php' => [
InstallServices::class
]
),
'update' => 'taoLti_scripts_update_Updater',
'managementRole' => 'http://www.tao.lu/Ontologies/TAOLTI.rdf#LtiManagerRole',
Expand Down
60 changes: 60 additions & 0 deletions models/classes/ExceptionInterpreter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2017 (original work) Open Assessment Technologies SA
*
*/

namespace oat\taoLti\models\classes;

use oat\tao\model\mvc\error\ExceptionInterpretor;

/**
* Class ExceptionInterpreter
* @package oat\taoLti\models\classes
* @author Aleh Hutnikau, <hutnikau@1pt.com>
*/
class ExceptionInterpreter extends ExceptionInterpretor
{
/**
* @var \taoLti_models_classes_LtiException
*/
protected $exception;

/**
* set exception to interpet
* @param \Exception $exception
* @return ExceptionInterpretor
*/
public function setException(\Exception $exception){
parent::setException($exception);
\common_Logger::e($exception->__toString());
return $this;
}

/**
* return an instance of ResponseInterface
* @return \oat\tao\model\mvc\error\class
*/
public function getResponse()
{
$response = new LtiReturnResponse;
$response->setServiceLocator($this->getServiceLocator());
$response->setException($this->exception);
return $response;
}

}
66 changes: 66 additions & 0 deletions models/classes/LtiReturnResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2017 (original work) Open Assessment Technologies SA
*
*/
namespace oat\taoLti\models\classes;

use oat\tao\model\mvc\error\ResponseAbstract;
use oat\tao\helpers\Template;

/**
* Class LtiReturnResponse
*
* Redirect to lti return url
*
* @package oat\taoLti\models\classes
* @author Aleh Hutnikau, <hutnikau@1pt.com>
* @property \taoLti_models_classes_LtiException $exception
*/
class LtiReturnResponse extends ResponseAbstract
{

public function setHttpCode($code) {
$this->httpCode = 302;
return $this;
}

public function send()
{
/** @var \taoLti_models_classes_TaoLtiSession $session */
$session = \common_session_SessionManager::getSession();
if ($session instanceof \taoLti_models_classes_TaoLtiSession) {
$launchData = $session->getLaunchData();
$baseUrl = $launchData->getReturnUrl();
} else {
$request = \common_http_Request::currentRequest();
$params = $request->getParams();
isset($params[\taoLti_models_classes_LtiLaunchData::LAUNCH_PRESENTATION_RETURN_URL]) ?
$baseUrl = $params[\taoLti_models_classes_LtiLaunchData::LAUNCH_PRESENTATION_RETURN_URL] : null;
}

if ($baseUrl !== null) {
$params = $this->exception->getLtiMessage()->getUrlParams();
$url = $baseUrl . (parse_url($baseUrl, PHP_URL_QUERY) ? '&' : '?') . http_build_query($params);
header(\HTTPToolkit::locationHeader($url));
} else {
require Template::getTemplate('error/error500.tpl', 'tao');
}
return;
}

}
7 changes: 4 additions & 3 deletions models/classes/class.LtiAuthAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
*
*/

use oat\taoLti\models\classes\LtiMessages\LtiErrorMessage;

/**
* Authentication adapter interface to be implemented by authentication methodes
* Authentication adapter interface to be implemented by authentication methods
*
* @access public
* @author Joel Bout, <joel@taotesting.com>
* @package taoLti
*/
class taoLti_models_classes_LtiAuthAdapter
implements common_user_auth_Adapter
Expand Down Expand Up @@ -57,7 +58,7 @@ public function authenticate() {
$ltiLaunchData = taoLti_models_classes_LtiLaunchData::fromRequest($this->request);
return new taoLti_models_classes_LtiUser($ltiLaunchData);
} catch (common_http_InvalidSignatureException $e) {
throw new taoLti_models_classes_LtiException('Invalid LTI signature');
throw new taoLti_models_classes_LtiException('Invalid LTI signature', LtiErrorMessage::ERROR_UNAUTHORIZED);
}
}
}
21 changes: 20 additions & 1 deletion models/classes/class.LtiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,25 @@
class taoLti_models_classes_LtiException extends common_Exception
{

/**
* @var string Unique key to determine error in log
*/
private $key;

public function __construct($message = null, $code = 0, Exception $previous = null)
{
parent::__construct($message, $code, $previous);
}

public function getKey()
{
if (!isset($this->key)) {
$this->key = uniqid();
}

return $this->key;
}

/**
* @var LtiErrorMessage
*/
Expand All @@ -40,10 +54,15 @@ public function getLtiMessage()
{
if ($this->ltiMessage === null) {
$message =__('Error (%s): ', $this->getCode()) . $this->getMessage();
$log = 'Error(' .$this->getCode() . '): ' . $this->__toString();
$log = __('Error(%s): [key %s] %s "%s"', $this->getCode(), $this->getKey(), get_class($this), $this->getMessage());
$this->ltiMessage = new LtiErrorMessage($message, $log);
}
return $this->ltiMessage;
}

public function __toString()
{
return '[key ' . $this->getKey() . '] ' . parent::__toString();
}

}
4 changes: 3 additions & 1 deletion models/classes/class.LtiLaunchData.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*
*/

use oat\taoLti\models\classes\LtiMessages\LtiErrorMessage;

class taoLti_models_classes_LtiLaunchData
{
const OAUTH_CONSUMER_KEY = 'oauth_consumer_key';
Expand Down Expand Up @@ -112,7 +114,7 @@ public function getVariable($key) {
if (isset($this->variables[$key])) {
return $this->variables[$key];
} else {
throw new taoLti_models_classes_LtiException('Undefined LTI variable '.$key);
throw new taoLti_models_classes_LtiException('Undefined LTI variable '.$key, LtiErrorMessage::ERROR_MISSING_PARAMETER);
}
}

Expand Down
Loading

0 comments on commit d6b3646

Please sign in to comment.