Skip to content

Commit

Permalink
Merge pull request #89 from oat-sa/release-3.4.2
Browse files Browse the repository at this point in the history
Release 3.4.2
  • Loading branch information
Jérôme Bogaerts authored Oct 17, 2017
2 parents d604621 + 86cb110 commit a954967
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 10 deletions.
2 changes: 1 addition & 1 deletion manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
'label' => 'LTI library',
'description' => 'TAO LTI library and helpers',
'license' => 'GPL-2.0',
'version' => '3.4.1',
'version' => '3.4.2',
'author' => 'Open Assessment Technologies SA',
'requires' => array(
'tao' => '>=10.8.0'
Expand Down
7 changes: 7 additions & 0 deletions models/classes/user/KvLtiUserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ public function findUser(\taoLti_models_classes_LtiLaunchData $ltiContext)

$ltiUser = LtiUser::unserialize($data);

$roles = $this->determineTaoRoles($ltiContext);
if($roles !== array(INSTANCE_ROLE_LTI_BASE)){
$ltiUser->setRoles($roles);
$this->getPersistence()->set(self::LTI_USER . $ltiContext->getUserID() . $ltiConsumer->getUri(), json_encode($ltiUser));
}


return $ltiUser;
}

Expand Down
15 changes: 9 additions & 6 deletions models/classes/user/LtiUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @author Joel Bout, <joel@taotesting.com>
* @package taoLti
*/
class LtiUser extends \common_user_User implements ServiceLocatorAwareInterface
class LtiUser extends \common_user_User implements ServiceLocatorAwareInterface, \JsonSerializable
{
use ServiceLocatorAwareTrait;

Expand Down Expand Up @@ -75,18 +75,21 @@ public function __construct($launchData, $userUri, $roles, $language = DEFAULT_L
{
$this->ltiLaunchData = $launchData;
$this->userUri = $userUri;
$this->roles = $this->setRoles($roles);
$this->setRoles($roles);
$this->language = $language;
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->email = $email;
$this->label = $label;
}

private function setRoles($roles)
public function setRoles($roles)
{
return array_map(function($value){
$newRoles = array_map(function($value){
return ($value instanceof \core_kernel_classes_Resource) ? $value->getUri() : $value;
}, $roles);

$this->roles = $newRoles;
}


Expand Down Expand Up @@ -155,7 +158,7 @@ public static function unserialize($data)
$user = $data !== false ? json_decode($data, true) : array();

if (isset($user['launchData']) && isset($user['userUri']) && isset($user['roles']) && isset($user['language']) && isset($user['firstname']) && isset($user['lastname']) && isset($user['email']) && isset($user['label'])) {
return new self($user['launchData'], $user['userUri'], $user['roles'], $user['language'], $user['firstname'], $user['lastname'], $user['email'], $user['label']);
return new self(unserialize($user['launchData']), $user['userUri'], $user['roles'], $user['language'], $user['firstname'], $user['lastname'], $user['email'], $user['label']);
}

return null;
Expand All @@ -165,7 +168,7 @@ public static function unserialize($data)
public function jsonSerialize()
{
return [
'launchData' => $this->ltiLaunchData,
'launchData' => serialize($this->ltiLaunchData),
'userUri' => $this->userUri,
'roles' => $this->roles,
'language' => $this->language,
Expand Down
11 changes: 9 additions & 2 deletions models/classes/user/OntologyLtiUserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class OntologyLtiUserService extends LtiUserService

const PROPERTY_USER_LTIKEY = 'http://www.tao.lu/Ontologies/TAOLTI.rdf#UserKey';

const CLASS_LTI_USER = 'http://www.tao.lu/Ontologies/TAOLTI.rdf#LTIConsumer';
const CLASS_LTI_USER = 'http://www.tao.lu/Ontologies/TAOLTI.rdf#LTIUser';

const PROPERTY_USER_LAUNCHDATA = 'http://www.tao.lu/Ontologies/TAOLTI.rdf#LaunchData';

Expand Down Expand Up @@ -78,9 +78,16 @@ public function findUser(\taoLti_models_classes_LtiLaunchData $ltiContext)
]
);

$roles = $this->determineTaoRoles($ltiContext);

return new LtiUser($ltiContext, $instance->getUri(), $properties[PROPERTY_USER_ROLES], (string)current($properties[PROPERTY_USER_UILG]), (string)current($properties[PROPERTY_USER_FIRSTNAME]), (string)current($properties[PROPERTY_USER_LASTNAME]), (string)current($properties[PROPERTY_USER_MAIL]));
$ltiUser = new LtiUser($ltiContext, $instance->getUri(), $properties[PROPERTY_USER_ROLES], (string)current($properties[PROPERTY_USER_UILG]), (string)current($properties[PROPERTY_USER_FIRSTNAME]), (string)current($properties[PROPERTY_USER_LASTNAME]), (string)current($properties[PROPERTY_USER_MAIL]));

if($roles !== array(INSTANCE_ROLE_LTI_BASE)){
$ltiUser->setRoles($roles);
$instance->editPropertyValues(new \core_kernel_classes_Property(PROPERTY_USER_ROLES), $roles);
}

return $ltiUser;
} else {
return null;
}
Expand Down
49 changes: 49 additions & 0 deletions scripts/install/RegisterKvUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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\scripts\install;

use oat\oatbox\extension\InstallAction;
use oat\taoLti\models\classes\user\KvLtiUserService;

/**
* Class RegisterKvUser
* @package oat\taoLti\scripts\install
* @author Antoine Robin, <antoine@taotesting.com>
*/
class RegisterKvUser extends InstallAction
{

/**
* @param $params
* @return \common_report_Report
*/
public function __invoke($params)
{
if(count($params) === 0){
return new \common_report_Report(\common_report_Report::TYPE_ERROR, __('Please give the key value persistence id'));
}
$persistenceId = reset($params);
$ltiUser = new KvLtiUserService([KvLtiUserService::OPTION_PERSISTENCE => $persistenceId]);
$this->registerService(KvLtiUserService::SERVICE_ID, $ltiUser);

return new \common_report_Report(\common_report_Report::TYPE_SUCCESS, __('Registered Lti user in Key value'));
}
}
46 changes: 46 additions & 0 deletions scripts/install/RegisterOntologyUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?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\scripts\install;

use oat\oatbox\extension\InstallAction;
use oat\taoLti\models\classes\user\KvLtiUserService;
use oat\taoLti\models\classes\user\OntologyLtiUserService;

/**
* Class RegisterOntologyUser
* @package oat\taoLti\scripts\install
* @author Antoine Robin, <antoine@taotesting.com>
*/
class RegisterOntologyUser extends InstallAction
{

/**
* @param $params
* @return \common_report_Report
*/
public function __invoke($params)
{
$ltiUser = new OntologyLtiUserService();
$this->registerService(OntologyLtiUserService::SERVICE_ID, $ltiUser);

return new \common_report_Report(\common_report_Report::TYPE_SUCCESS, __('Registered Lti user in ontology'));
}
}
2 changes: 1 addition & 1 deletion scripts/update/class.Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function update($initialVersion)

$this->setVersion('3.4.0');
}
$this->skip('3.4.0', '3.4.1');
$this->skip('3.4.0', '3.4.2');

}
}

0 comments on commit a954967

Please sign in to comment.