Skip to content
Snippets Groups Projects
Commit 0061c6be authored by Ron Lucke's avatar Ron Lucke Committed by Elmar Ludwig
Browse files

fixes #253

parent ce90b8f1
No related branches found
No related tags found
No related merge requests found
......@@ -119,6 +119,9 @@ class StructuralElementsUpdate extends JsonApiController
}
}
$resource->release_date = $json['data']['attributes']['release-date'];
$resource->withdraw_date = $json['data']['attributes']['withdraw-date'];
// update parent
if (self::arrayHas($json, 'data.relationships.parent')) {
$parent = $this->getParentFromJson($json);
......
......@@ -238,6 +238,10 @@ class StructuralElement extends \SimpleORMap
return true;
}
if (!$this->releasedForReaders($this)) {
return false;
}
if (!count($this->read_approval)) {
return $this->canReadSequential($user);
}
......@@ -282,6 +286,30 @@ class StructuralElement extends \SimpleORMap
return $this->previousProgressAchieved($user);
}
/**
* @return bool true if the user may read this instance in time interval
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
private function releasedForReaders(StructuralElement $element): bool
{
$released = false;
if (!$element->release_date || $element->release_date <= time()) {
$released = true;
}
if ($element->withdraw_date && $element->withdraw_date <= time()) {
$released = false;
}
$parent_released = true;
if (!$element->isRootNode()) {
$parent_released = $this->releasedForReaders($element->parent);
}
return $released && $parent_released;
}
/**
* @param mixed $user the user to validate
*
......
......@@ -50,14 +50,16 @@ export default {
for (var i = 0; i < data.length; i++) {
if (data[i].relationships.parent.data?.id == parentId) {
let new_childs = this.loadChildren(data[i].id, data, depth + 1);
children.push({
name: data[i].attributes.title,
position: data[i].attributes.position,
element_id: data[i].id,
children: new_childs,
depth: depth,
current: this.currentElementId === data[i].id
});
if (data[i].attributes['can-read']) {
children.push({
name: data[i].attributes.title,
position: data[i].attributes.position,
element_id: data[i].id,
children: new_childs,
depth: depth,
current: this.currentElementId === data[i].id
});
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment