Skip to content

Commit

Permalink
IndAss: 37251, support MemberView of Course
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaagen authored and klees committed Feb 20, 2024
1 parent a190f44 commit 075d3ca
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

/**
* Deal with ilias rbac-system
*/
Expand Down Expand Up @@ -50,7 +50,12 @@ public function __construct(
*/
public function checkRBACAccessToObj(string $operation): bool
{
return $this->isSystemAdmin() || $this->handler->checkAccessOfUser($this->usr->getId(), $operation, '', $this->iass->getRefId(), 'iass');
if($this->simulateMember()) {
return $this->checkMemberRoleForPermission($operation);
} else {
return $this->isSystemAdmin() ||
$this->handler->checkAccessOfUser($this->usr->getId(), $operation, '', $this->iass->getRefId(), 'iass');
}
}

public function checkRBACOrPositionAccessToObj(string $operation)
Expand Down Expand Up @@ -78,6 +83,33 @@ public function checkRBACOrPositionAccessToObj(string $operation)
throw new \LogicException("Unknown rbac/position-operation: $operation");
}

public function simulateMember(): bool
{
$settings = ilMemberViewSettings::getInstance();
return $settings->isActive() &&
$settings->getContainer() === $this->iass->getParentContainerIdByType($this->iass->getRefId(), ['crs']);
}

protected function checkMemberRoleForPermission(string $operation): bool
{
$ref_id = $this->iass->getRefId();
$roles = array_filter(
$this->review->getParentRoleIds($ref_id),
static fn(array $role): bool => str_starts_with($role['title'], 'il_crs_member_')
);
if($roles === []) {
return false;
}
$role = array_shift($roles);
$active_ops = $this->review->getActiveOperationsOfRole($ref_id, $role['rol_id']);
foreach($active_ops as $op) {
if($this->review->getOperation($op)['operation'] === $operation) {
return true;
}
}
return false;
}

/**
* @inheritdoc
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public function isActiveLP(): bool
* @param int $id start at this id
* @param string[] $types search for these strings
*
* @return int the obj_id or 0 if root is reached
* @return int the ref_id or 0 if root is reached
*/
public function getParentContainerIdByType(int $id, array $types): int
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,9 @@
*
*********************************************************************/

declare(strict_types=1);


class ilObjIndividualAssessmentAccess extends ilObjectAccess implements ilConditionHandling
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ public function executeCommand(): void
$cmd = 'members';
}
}
if($cmd === 'edit' && $this->object->accessHandler()->simulateMember()) {
$cmd = 'view';
}

$cmd .= 'Object';
$this->$cmd();
}
Expand Down

0 comments on commit 075d3ca

Please sign in to comment.