Commit c2fe7bf8 authored by Alexandre Morin's avatar Alexandre Morin

Merge branch 'Support/2.4.X' into 'master'

Support/2.4.x master

See merge request !286
parents dcef8a19 738ba413
# CHANGELOG
## Version 2.4.4
### IHM
- `Fixed` Retrait de l’affichage des ressources si l'archive est en cours de suppression
### Métadonnées
- `Fixed` Ajout d'un bouton dans la modale de détail de l'archive permettant la conversion unitaire d'un document
- `Fixed` Rétablissement de l'affichage des fichiers convertis et des relations dans la modale de détails de l'archive
- `Changed` Différenciation entre le fichier d'origine et ses conversions dans l'arborescence du plan de classement
### Sécurité
- `Changed` Ajout du paramètre `lifetime` pour le jeton CSRF qui définit la durée de validité des jetons en secondes. Si omis, durée de 1 heure par défaut.
- `Fixed` Jeton CRSF consommé lorsqu'utilisé.
## Version 2.4.3
### Métadonnées
......
......@@ -64,7 +64,7 @@ class csrf
return;
}
$requestToken = $this->getRequestToken();
$requestToken = \laabs::getToken("Csrf", LAABS_IN_HEADER);
// Get account with LOCK
$this->sdoFactory->beginTransaction();
......@@ -75,17 +75,19 @@ class csrf
return;
}
$accountTokens = $account->authentication->csrf;
switch ($userCommand->method) {
case "create":
case "update":
case "delete":
$requestTokenTime = $this->isValidToken($requestToken, $accountTokens);
if (empty($requestToken)) {
throw new \core\Exception('Attempt to access without a valid token 1', 412);
}
$requestTokenTime = $this->checkToken($requestToken, $accountTokens);
$accountTokens = $this->shiftTokens($requestTokenTime, $accountTokens);
$accountTokens = $this->addToken($accountTokens);
break;
......@@ -130,21 +132,9 @@ class csrf
}
/**
* Retrieves the request csrf token
*
* @return string
*/
private function getRequestToken()
{
$requestToken = \laabs::getToken("Csrf", LAABS_IN_HEADER);
return $requestToken;
}
/**
* Retrieves the account information with a LOCK on database
* @param bool $lock Lock user
*
*
* @return auth/userAccount
*/
private function getAccount($lock = false)
......@@ -171,10 +161,28 @@ class csrf
if (!is_object($account->authentication->csrf)) {
$account->authentication->csrf = [];
} else {
$account->authentication->csrf = get_object_vars($account->authentication->csrf);
return $account;
}
$account->authentication->csrf = get_object_vars($account->authentication->csrf);
$lifetime = '3600';
if (isset($this->config['lifetime'])) {
$lifetime = $this->config['lifetime'];
}
$duration = \laabs::newDuration('PT'.$lifetime.'S');
$now = \laabs::newTimestamp();
foreach ($account->authentication->csrf as $time => $token) {
$timestamp = \laabs::newTimestamp($time);
$expiration = $timestamp->add($duration);
if ($now->diff($expiration)->invert == 1) {
unset($account->authentication->csrf[$time]);
}
}
return $account;
}
......@@ -214,16 +222,8 @@ class csrf
return end($accountTokens);
}
private function isValidToken($requestToken, $accountTokens)
private function checkToken($requestToken, $accountTokens)
{
if (empty($requestToken)) {
$e = new \core\Exception('Attempt to access without a valid token', 412);
throw $e;
return false;
}
$requestTokenTime = array_search($requestToken, $accountTokens);
if (empty($requestTokenTime)) {
......@@ -240,7 +240,7 @@ class csrf
private function shiftTokens($requestTokenTime, $accountTokens)
{
foreach ($accountTokens as $time => $token) {
if ($time < $requestTokenTime) {
if ($time <= $requestTokenTime) {
unset($accountTokens[$time]);
}
}
......
......@@ -168,7 +168,7 @@ class archive
} else {
$archive->hasRights = $archiveController->checkRights($archive);
}
} catch(\Exception $e) {
} catch (\Exception $e) {
$archive->hasRights = false;
}
}
......@@ -230,7 +230,7 @@ class archive
{
$this->view->addContentFile("recordsManagement/archive/archiveInfo/archiveInfo.html");
// Managment metadata
// Management metadata
$this->setManagementMetadatas($archive);
// Descriptive metadata
......@@ -254,7 +254,7 @@ class archive
$this->view->translate();
$this->view->merge();
return $this->view->saveHtml();
}
......@@ -289,7 +289,6 @@ class archive
$this->view->translate();
$this->view->merge();
return $this->view->saveHtml();
}
......@@ -342,7 +341,7 @@ class archive
$this->view->translate();
$this->view->merge();
return $this->view->saveHtml();
}
......@@ -656,7 +655,7 @@ class archive
if ($result == false) {
$count = 0;
} else {
$count = count($result);
$count = 1;
}
$this->json->message = '%1$s document(s) converted.';
$this->json->message = $this->translator->getText($this->json->message);
......@@ -1227,22 +1226,22 @@ class archive
protected function setDigitalResources($archive)
{
if ($archive->status == "disposed") {
if ($archive->status == "disposed" || $archive->status == "restituted" || $archive->status == "transfered") {
$archive->digitalResources = null;
} elseif (isset($archive->digitalResources)) {
foreach ($archive->digitalResources as $key => $digitalResource) {
$archive->digitalResources[$key]->json = json_encode($digitalResource);
$digitalResource->isConvertible = \laabs::callService("digitalResource/digitalResource/updateIsconvertible", $digitalResource);
if (!isset($digitalResource->relatedResource)) {
$digitalResource->relatedResource = [];
continue;
}
foreach ($digitalResource->relatedResource as $relatedResource) {
$relatedResource->isConvertible = \laabs::callService("digitalResource/digitalResource/updateIsconvertible", $relatedResource);
$relatedResource->relationshipType = $this->view->translator->getText($relatedResource->relationshipType, "relationship", "recordsManagement/messages");
} else {
foreach ($digitalResource->relatedResource as $relatedResource) {
$relatedResource->isConvertible = \laabs::callService("digitalResource/digitalResource/updateIsconvertible", $relatedResource);
$relatedResource->relationshipType = $this->view->translator->getText($relatedResource->relationshipType, "relationship", "recordsManagement/messages");
}
}
$archive->digitalResources[$key]->json = json_encode($digitalResource);
}
}
}
......
......@@ -843,10 +843,6 @@ msgid "isTimestampOf"
msgstr "Jeton d'horodatage"
msgctxt "relationship"
msgid "isConversionOf"
msgstr "Document converti"
msgctxt "relationship"
msgid "Indexing modification"
msgstr "Modification de l'index"
......
<li class="document" data-archive-id="[?merge .archiveId ?]" data-res-id="[?merge .resId ?]" data-json="[?merge .json ?]">
<span class="">
<small class="documentName"><i class="fa fa-file">&nbsp;</i><?merge .fileName ?></small>
<?merge .relationshipType.ifeq('isConversionOf') ?><i class="fa" data-closed-icon="none" data-opened-icon="none">&nbsp;</i>
<?merge .relatedResource.bool() ?><i class="fa" data-closed-icon="fa-caret-right" data-opened-icon="fa-caret-down">&nbsp;</i>
<small class="documentName">
<?merge .relationshipType.ifeq('isConversionOf') ?><i class="fa fa-files-o fa-fw">&nbsp;</i>
<?merge .relationshipType.bool().not() ?><i class="fa fa-file">&nbsp;</i>
<?merge .fileName ?>
</small>
</span>
<ul>
<?merge .contents /recordsManagement/archive/archiveTree/archiveContentTemplate.html ?>
<?merge .relatedResource /recordsManagement/archive/archiveTree/archiveContentTemplate.html ?>
</ul>
</li>
\ No newline at end of file
......@@ -34,17 +34,25 @@
selected: null,
select: function(e) {
this.unselect();
var li = e.closest('li')
var li = e.closest('li');
if(e.hasClass('archiveName')) {
$("#archiveNameH3").text(e.text());
li.children('span').removeClass('node-default').addClass('node-warning');
li.children('span').removeClass('node-default').addClass('node-warning');
trigger("showDetails.archive", li.data('archive-id'));
this.selected = li;
} else if (e.hasClass('documentName')) {
e.addClass('node-warning');
}
else if (e.hasClass('documentName')) {
// Pour les fichiers convertis, on va récupérer les 'relatedResource' dans le data.json du parent
if (!li.data('json')){
var converted_data = li.parents("li").first().data('json');
$.each(converted_data.relatedResource, function( index, value ) {
if(value.resId == li.data('resId')) {
li.data('json', value);
}
});
}
e.addClass('node-warning').removeClass('node-default');
trigger("showDetails.digitalResource", li.data('json'));
this.selected = li;
}
......
......@@ -17,7 +17,7 @@ var BootstrapTree = {
.find('.fa:first')
.each(function() {
$(this).addClass($(this).data('closed-icon'));
$(this).next().find("i").addClass("fa_folder");
$(this).next().find("i").addClass("fa-folder");
// $(this).next().find("i").addClass("fa-folder").removeClass("fa-folder-o");
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment