Skip to content

Commit

Permalink
Object: Fix Access Check on Availability Period
Browse files Browse the repository at this point in the history
  • Loading branch information
kergomard committed Jan 27, 2025
1 parent 7f23537 commit 0816f97
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use ILIAS\Object\Properties\ObjectReferenceProperties\ObjectAvailabilityPeriodProperty;
use ILIAS\UI\Component\Button\Standard as StandardButton;
use ILIAS\UI\Component\Modal\RoundTrip as RoundTripModal;
use ILIAS\UI\Implementation\Component\Listing\Unordered as UnorderedListing;
use ILIAS\UI\Factory as UIFactory;
use ILIAS\Refinery\Factory as Refinery;
use ILIAS\Data\Factory as DataFactory;
Expand Down Expand Up @@ -81,19 +80,25 @@ public function getEditAvailabilityPeriodPropertiesModal(

public function saveEditAvailabilityPeriodPropertiesModal(
\ilObjectGUI $parent_gui,
\Closure $check_access,
ServerRequestInterface $request
): ?RoundTripModal {
): RoundTripModal|bool {
$post_url = $this->ctrl->getFormAction($parent_gui, 'saveAvailabilityPeriod');
$availability_period_modal = $this->buildModal($post_url)
->withRequest($request);
$data = $availability_period_modal->getData();
if ($data === null) {
return $availability_period_modal;
}
$ref_ids = explode(',', $data['affected_items']);
$ref_ids = $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())->transform($data['affected_items']);

if (!$check_access($ref_ids)) {
return false;
}

$availability_period_property = $data['enable_availability_period'];
$this->saveAvailabilityPeriodPropertyForObjectRefIds($ref_ids, $availability_period_property);
return null;
return true;
}

private function buildModal(
Expand Down Expand Up @@ -156,7 +161,7 @@ private function saveAvailabilityPeriodPropertyForObjectRefIds(
): void {
foreach ($object_reference_ids as $object_reference_id) {
$this->object_reference_properties_repo->storePropertyAvailabilityPeriod(
$property->withObjectReferenceId((int) $object_reference_id)
$property->withObjectReferenceId($object_reference_id)
);
}
}
Expand Down
30 changes: 22 additions & 8 deletions Services/Object/classes/class.ilObjectGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -880,11 +880,13 @@ protected function addAvailabilityPeriodButtonToToolbar(ilToolbarGUI $toolbar):

public function editAvailabilityPeriodObject(): void
{
if (!$this->checkPermissionBool('write')) {
$item_ref_ids = $this->retriever->getSelectedIdsFromObjectList();
if (!$this->checkPermissionBool('write')
&& !$this->checkWritePermissionOnRefIdArray($item_ref_ids)) {
$this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_perm_write'));
return;
}
$item_ref_ids = $this->retriever->getSelectedIdsFromObjectList();

$availability_period_modal = $this->getMultiObjectPropertiesManipulator()->getEditAvailabilityPeriodPropertiesModal(
$item_ref_ids,
$this
Expand All @@ -904,13 +906,15 @@ public function editAvailabilityPeriodObject(): void

public function saveAvailabilityPeriodObject(): void
{
if (!$this->checkPermissionBool('write')) {
$this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_perm_write'));
return;
}
$availability_period_modal = $this->getMultiObjectPropertiesManipulator()->saveEditAvailabilityPeriodPropertiesModal($this, $this->request);
if ($availability_period_modal === null) {
$availability_period_modal = $this->getMultiObjectPropertiesManipulator()->saveEditAvailabilityPeriodPropertiesModal(
$this,
fn($ref_ids): bool => $this->checkPermissionBool('write') || $this->checkWritePermissionOnRefIdArray($ref_ids),
$this->request
);
if ($availability_period_modal === true) {
$this->tpl->setOnScreenMessage('success', $this->lng->txt('availability_period_changed'));
} elseif ($availability_period_modal === false) {
$this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_perm_write'));
} else {
$this->tpl->setVariable(
'IL_OBJECT_MODALS',
Expand Down Expand Up @@ -1806,4 +1810,14 @@ public function removeFromDeskObject(): void
$this->tpl->setOnScreenMessage("success", $this->lng->txt("rep_removed_from_favourites"), true);
$this->ctrl->redirectToURL(ilLink::_getLink($this->requested_ref_id));
}

private function checkWritePermissionOnRefIdArray(array $ref_ids): bool
{
foreach ($ref_ids as $ref_id) {
if (!$this->access->checkAccess('write', '', $ref_id)) {
return false;
}
}
return true;
}
}

0 comments on commit 0816f97

Please sign in to comment.