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 ...@@ -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 // update parent
if (self::arrayHas($json, 'data.relationships.parent')) { if (self::arrayHas($json, 'data.relationships.parent')) {
$parent = $this->getParentFromJson($json); $parent = $this->getParentFromJson($json);
......
...@@ -238,6 +238,10 @@ class StructuralElement extends \SimpleORMap ...@@ -238,6 +238,10 @@ class StructuralElement extends \SimpleORMap
return true; return true;
} }
if (!$this->releasedForReaders($this)) {
return false;
}
if (!count($this->read_approval)) { if (!count($this->read_approval)) {
return $this->canReadSequential($user); return $this->canReadSequential($user);
} }
...@@ -282,6 +286,30 @@ class StructuralElement extends \SimpleORMap ...@@ -282,6 +286,30 @@ class StructuralElement extends \SimpleORMap
return $this->previousProgressAchieved($user); 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 * @param mixed $user the user to validate
* *
......
...@@ -50,14 +50,16 @@ export default { ...@@ -50,14 +50,16 @@ export default {
for (var i = 0; i < data.length; i++) { for (var i = 0; i < data.length; i++) {
if (data[i].relationships.parent.data?.id == parentId) { if (data[i].relationships.parent.data?.id == parentId) {
let new_childs = this.loadChildren(data[i].id, data, depth + 1); let new_childs = this.loadChildren(data[i].id, data, depth + 1);
children.push({ if (data[i].attributes['can-read']) {
name: data[i].attributes.title, children.push({
position: data[i].attributes.position, name: data[i].attributes.title,
element_id: data[i].id, position: data[i].attributes.position,
children: new_childs, element_id: data[i].id,
depth: depth, children: new_childs,
current: this.currentElementId === data[i].id 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