Skip to content

Commit

Permalink
Merge branch 'trunk' of github.com:ILIAS-eLearning/ILIAS into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
smeyer-ilias committed Dec 18, 2023
2 parents 611dd85 + a00a598 commit 7aefd56
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public function forObject(
public function forSubObjects(
string $type,
int $ref_id,
SubObjectIDInterface ...$sub_object_ids
string ...$sub_types
): SubObjectModesInterface {
return new SubObjectModes(
$this->dic,
$type,
$ref_id,
...$sub_object_ids
...$sub_types
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function forObject(
public function forSubObjects(
string $type,
int $ref_id,
SubObjectIDInterface ...$sub_object_ids
string ...$sub_types
): SubObjectModesInterface;

public function getSubObjectID(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class DataTable implements DataTableInterface
protected DataFactory $data_factory;
protected StaticURL $static_url;

protected string $type;
protected int $ref_id;

/**
* @var Column[]
*/
Expand All @@ -47,13 +50,15 @@ public function __construct(
StaticURL $static_url,
string $type,
int $ref_id,
SubObjectIDInterface ...$sub_object_ids
string ...$sub_types
) {
$this->user = $user;
$this->ui_factory = $ui_factory;
$this->data_factory = $data_factory;
$this->static_url = $static_url;
$this->initColumnsAndData($type, $ref_id, ...$sub_object_ids);
$this->type = $type;
$this->ref_id = $ref_id;
$this->initColumns(...$sub_types);
}

/**
Expand All @@ -64,16 +69,8 @@ public function getColumns(): array
return $this->columns;
}

public function getData(SubObjectIDInterface $sub_object_id): array
public function loadData(SubObjectIDInterface ...$sub_object_ids): void
{
return $this->data[$sub_object_id->subtype()][$sub_object_id->objID()][$sub_object_id->subID()] ?? [];
}

protected function initColumnsAndData(
string $type,
int $ref_id,
SubObjectIDInterface ...$sub_object_ids
): void {
$ids = [];
foreach ($sub_object_ids as $sub_object_id) {
$ids[$sub_object_id->subtype()][$sub_object_id->objID()][] = [
Expand All @@ -86,8 +83,8 @@ protected function initColumnsAndData(
$values = [];
foreach ($id as $obj_id => $records) {
$values = array_merge($values, \ilAdvancedMDValues::queryForRecords(
$ref_id,
$type,
$this->ref_id,
$this->type,
$sub_type,
[$obj_id],
$sub_type,
Expand All @@ -97,18 +94,10 @@ protected function initColumnsAndData(
));
}

foreach (\ilAdvancedMDRecord::_getSelectedRecordsByObject(
$type,
$ref_id,
$sub_type,
$ref_id !== 0
) as $record_obj) {
$record_id = $record_obj->getRecordId();
$translations = \ilAdvancedMDFieldTranslations::getInstanceByRecordId($record_id);
foreach ($this->getRecordIds($sub_type) as $record_id) {
$defs = \ilAdvancedMDFieldDefinition::getInstancesByRecordId($record_id);
foreach ($defs as $def) {
$key = Constants::ID_PREFIX . $def->getFieldId();
$this->columns[$key] = $this->initColumn($translations, $def);
foreach ($values as $value) {
$obj_id = $value['obj_id'];
$sub_id = $value['sub_id'];
Expand All @@ -123,6 +112,26 @@ protected function initColumnsAndData(
}
}

public function getData(SubObjectIDInterface $sub_object_id): array
{
return $this->data[$sub_object_id->subtype()][$sub_object_id->objID()][$sub_object_id->subID()] ?? [];
}

protected function initColumns(
string ...$sub_types
): void {
foreach ($sub_types as $sub_type) {
foreach ($this->getRecordIds($sub_type) as $record_id) {
$translations = \ilAdvancedMDFieldTranslations::getInstanceByRecordId($record_id);
$defs = \ilAdvancedMDFieldDefinition::getInstancesByRecordId($record_id);
foreach ($defs as $def) {
$key = Constants::ID_PREFIX . $def->getFieldId();
$this->columns[$key] = $this->initColumn($translations, $def);
}
}
}
}

protected function initColumn(
\ilAdvancedMDFieldTranslations $translations,
\ilAdvancedMDFieldDefinition $def
Expand Down Expand Up @@ -223,4 +232,21 @@ protected function initData(

return $val;
}

/**
* @return int[]
*/
protected function getRecordIds(string $sub_type): array
{
$ids = [];
foreach (\ilAdvancedMDRecord::_getSelectedRecordsByObject(
$this->type,
$this->ref_id,
$sub_type,
$this->ref_id !== 0
) as $record_obj) {
$ids[] = $record_obj->getRecordId();
}
return $ids;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ interface DataTableInterface
*/
public function getColumns(): array;

public function loadData(SubObjectIDInterface ...$sub_object_ids): void;

public function getData(SubObjectIDInterface $sub_object_id): array;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ class SubObjectModes implements SubObjectModesInterface
protected int $ref_id;

/**
* @var SubObjectIDInterface[]
* @var string[]
*/
protected array $sub_object_ids;
protected array $sub_types;

public function __construct(
Container $dic,
string $type,
int $ref_id,
SubObjectIDInterface ...$sub_object_ids
string ...$sub_types
) {
$this->dic = $dic;
$this->type = $type;
$this->ref_id = $ref_id;
$this->sub_object_ids = $sub_object_ids;
$this->sub_types = $sub_types;
}
public function inDataTable(): DataTableInterface
{
Expand All @@ -56,7 +56,7 @@ public function inDataTable(): DataTableInterface
$this->dic['static_url'],
$this->type,
$this->ref_id,
...$this->sub_object_ids
...$this->sub_types
);
}
}
108 changes: 106 additions & 2 deletions components/ILIAS/Badge/classes/class.ilBadgeWAC.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,116 @@ class ilBadgeWAC implements ilWACCheckingClass
{
public function canBeDelivered(ilWACPath $ilWACPath): bool
{
global $DIC;

if (strpos($ilWACPath->getPath(), '..') !== false) {
return false;
}

if (preg_match('@ilBadge\/badge(.*?)\/@ui', $ilWACPath->getPath())) {
return true;
if (!preg_match('@ilBadge\/badge(tmpl)?_(\d+)\/@ui', $ilWACPath->getPath())) {
return false;
}

$obj_id = array_keys(ilObject::_getObjectsByType('bdga'))[0] ?? null;
$admin_ref_id = null;
if ($obj_id > 0) {
$admin_ref_id = array_values(ilObject::_getAllReferences($obj_id))[0] ?? null;
}

$has_global_badge_administration_access = (
$admin_ref_id > 0 &&
$DIC->rbac()->system()->checkAccessOfUser($DIC->user()->getId(), 'read', $admin_ref_id)
);

if (preg_match('@\/badgetmpl_(\d+)\/@ui', $ilWACPath->getPath())) {
// Badge template images must only be accessible for accounts with `read` permission on the badge administration node
return $has_global_badge_administration_access;
}

if (preg_match('@\/badge_(\d+)\/@ui', $ilWACPath->getPath(), $matches)) {
if ($has_global_badge_administration_access) {
return true;
}

$badge_id = (int) $matches[1];

return (
$this->isAssignedBadge($DIC, $badge_id) ||
$this->isAssignedBadgeOfPublishedUserProfile($DIC, $badge_id) ||
$this->hasAccessToBadgeParentIdNode($DIC, $badge_id, $has_global_badge_administration_access)
);
}

return false;
}

private function hasAccessToBadgeParentIdNode(
\ILIAS\DI\Container $DIC,
int $badge_id,
bool $has_global_badge_administration_access
) : bool {
// If the acting user still does not have access, check if the image is used in an object badge type
$badge = new ilBadge($badge_id);
if ($badge->getParentId() > 0) {
return false;
}

$badge_handler = ilBadgeHandler::getInstance();
if (!$badge_handler->isObjectActive((int) $badge->getParentId())) {
return false;
}

$context_ref_id = array_values(ilObject::_getAllReferences((int) $badge->getParentId()))[0] ?? null;
if (!($context_ref_id > 0)) {
return false;
}

$context_ref_id = (int) $context_ref_id;
if ($DIC->repositoryTree()->isGrandChild((int) SYSTEM_FOLDER_ID, $context_ref_id)) {
$has_access = $has_global_badge_administration_access;
} else {
$has_access = $DIC->access()->checkAccessOfUser(
$DIC->user()->getId(),
'write',
'',
$context_ref_id
);
}

return $has_access;
}

private function isAssignedBadge(\ILIAS\DI\Container $DIC, int $badge_id) : bool
{
// First, check all badge assignments of the current user for a match
$badges_of_user = ilBadgeAssignment::getInstancesByUserId($DIC->user()->getId());
foreach ($badges_of_user as $user_badge) {
if ((int) $user_badge->getBadgeId() === $badge_id) {
return true;
}
}

return false;
}

private function isAssignedBadgeOfPublishedUserProfile(\ILIAS\DI\Container $DIC, int $badge_id) : bool
{
// It seems the badge is not assigned to the curent user, so check if the profile of the badge user is made visible
$assignments = ilBadgeAssignment::getInstancesByBadgeId($badge_id);
foreach ($assignments as $assignment) {
if (!$assignment->getPosition()) {
continue;
}

$user = ilObjectFactory::getInstanceByObjId((int) $assignment->getUserId(), false);
if (!$user instanceof ilObjUser) {
continue;
}

$profile_visibility = $user->getPref('public_profile');
if ($profile_visibility === 'g' || ($profile_visibility === 'y' && !$DIC->user()->isAnonymous())) {
return true;
}
}

return false;
Expand Down
Loading

0 comments on commit 7aefd56

Please sign in to comment.