Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/trunk' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansenDatabay committed Dec 19, 2024
2 parents 2644f64 + aa0908a commit a57223e
Show file tree
Hide file tree
Showing 25 changed files with 575 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use ILIAS\Filesystem\Stream\Streams;
use ILIAS\UI\Component\Input\Container\Form\Standard as StandardForm;
use ILIAS\UI\Component\Input\Field\Section as Section;
use ILIAS\Refinery\ConstraintViolationException;

/**
* class ilConditionHandlerGUI
Expand Down Expand Up @@ -799,11 +800,33 @@ protected function confirmDeleteConditionTrigger(): void
$this->refinery->byTrying(
[
$this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int()),
// Actions for entire table sends a fixed token in an array, instead of all row ids
$this->refinery->custom()->transformation(function ($var) {
if (
is_array($var) &&
count($var) === 1 &&
(string) $var[0] === 'ALL_OBJECTS'
) {
return $var;
}
throw new UnexpectedValueException('Unexpected string in row_id array.');
}),
$this->refinery->always([])
]
)
);

if ($condition_trigger_ids === ['ALL_OBJECTS']) {
$condition_trigger_ids = [];
foreach (ilConditionHandler::_getPersistedConditionsOfTarget(
$this->getTargetRefId(),
$this->getTargetId(),
$this->getTargetType()
) as $condition) {
$condition_trigger_ids[] = $condition['id'];
}
}

$items = [];
foreach ($condition_trigger_ids as $condition_trigger_id) {
$condition = ilConditionHandler::_getCondition($condition_trigger_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

declare(strict_types=1);

use ILIAS\Modules\DataCollection\Fields\Formula\FormulaParser\Token\Tokenizer;

use ILIAS\Modules\DataCollection\Fields\Formula\FormulaParser\Math\Functions;
use ILIAS\Modules\DataCollection\Fields\Formula\FormulaParser\Math\Operators;

class ilDclTable
{
Expand Down Expand Up @@ -530,7 +532,11 @@ public function getFirstTableViewId(int $ref_id, int $user_id = 0, bool $with_de
*/
public function getFieldsForFormula(): array
{
$syntax_chars = array_merge(Tokenizer::$operators, Tokenizer::$functions, ['(', ')', ',']);
$syntax_chars = array_merge(
array_map(static fn(Operators $function): string => $function->value, Operators::cases()),
array_map(static fn(Functions $function): string => $function->value, Functions::cases()),
['(', ')', ',']
);
foreach ($this->getFields() as $field) {
if (in_array($field->getDatatypeId(), ilDclFormulaFieldModel::SUPPORTED_FIELDS)) {
foreach ($syntax_chars as $element) {
Expand Down
11 changes: 8 additions & 3 deletions components/ILIAS/File/classes/Capabilities/Capability.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ class Capability
{
private bool $unlocked = false;
private ?URI $uri = null;
/**
* @var Permissions[]
*/
private array $permissions = [];

public function __construct(
private Capabilities $capability,
private Permissions $permission
Permissions ... $permissions
) {
$this->permissions = $permissions;
}

public function withUnlocked(bool $unlocked): Capability
Expand Down Expand Up @@ -62,9 +67,9 @@ public function getCapability(): Capabilities
return $this->capability;
}

public function getPermission(): Permissions
public function getPermissions(): array
{
return $this->permission;
return $this->permissions;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function __construct(
private readonly \ilCtrlInterface $ctrl,
private readonly ActionRepository $action_repository,
private readonly Services $http,
private readonly TypeResolver $type_resolver,
private readonly URIBuilder $static_url
) {
$this->checks = [
Expand Down Expand Up @@ -79,19 +80,18 @@ public function get(int $ref_id, bool $do_checks = true): CapabilityCollection
* which will return the first unlocked Capability
*/
$capabilities = [
new Capability(Capabilities::FORCED_INFO_PAGE, Permissions::VISIBLE),
new Capability(Capabilities::FORCED_INFO_PAGE, ...Permissions::ANY()),
new Capability(Capabilities::VIEW_EXTERNAL, Permissions::VIEW_CONTENT),
new Capability(Capabilities::EDIT_EXTERNAL, Permissions::EDIT_CONTENT),
new Capability(Capabilities::DOWNLOAD, Permissions::READ),
new Capability(Capabilities::MANAGE_VERSIONS, Permissions::WRITE),
new Capability(Capabilities::EDIT_SETTINGS, Permissions::WRITE),
new Capability(Capabilities::INFO_PAGE, Permissions::VISIBLE),
new Capability(Capabilities::INFO_PAGE, ...Permissions::ANY()),
new Capability(Capabilities::NONE, Permissions::NONE),
new Capability(Capabilities::UNZIP, Permissions::WRITE),
];


if (\ilObject2::_lookupType($ref_id, true) !== 'file') {
if ($this->type_resolver->resolveType($ref_id) !== 'file') {
return new CapabilityCollection($capabilities);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function maybeUnlock(
int $ref_id,
): Capability {
$this->info = $info;
return $capability->withUnlocked($this->hasPermission($helpers, $ref_id, $capability->getPermission()));
return $capability->withUnlocked($this->hasPermission($helpers, $ref_id, ...$capability->getPermissions()));
}

public function maybeBuildURI(Capability $capability, CheckHelpers $helpers, int $ref_id): Capability
Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/File/classes/Capabilities/Check/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function maybeUnlock(
\ilObjFileInfo $info,
int $ref_id,
): Capability {
return $capability->withUnlocked($this->hasPermission($helpers, $ref_id, $capability->getPermission()));
return $capability->withUnlocked($this->hasPermission($helpers, $ref_id, ...$capability->getPermissions()));
}

public function maybeBuildURI(Capability $capability, CheckHelpers $helpers, int $ref_id): Capability
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function maybeUnlock(
\ilObjFileInfo $info,
int $ref_id,
): Capability {
if (!$this->hasPermission($helpers, $ref_id, $capability->getPermission())) {
if (!$this->hasPermission($helpers, $ref_id, ...$capability->getPermissions())) {
return $capability->withUnlocked(false);
}

Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/File/classes/Capabilities/Check/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function maybeUnlock(
\ilObjFileInfo $info,
int $ref_id,
): Capability {
return $capability->withUnlocked($this->hasPermission($helpers, $ref_id, $capability->getPermission()));
return $capability->withUnlocked($this->hasPermission($helpers, $ref_id, ...$capability->getPermissions()));
}

public function maybeBuildURI(Capability $capability, CheckHelpers $helpers, int $ref_id): Capability
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function maybeUnlock(
\ilObjFileInfo $info,
int $ref_id,
): Capability {
return $capability->withUnlocked($this->hasPermission($helpers, $ref_id, $capability->getPermission()));
return $capability->withUnlocked($this->hasPermission($helpers, $ref_id, ...$capability->getPermissions()));
}

public function maybeBuildURI(Capability $capability, CheckHelpers $helpers, int $ref_id): Capability
Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/File/classes/Capabilities/Check/Unzip.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function maybeUnlock(
return $capability;
}

return $capability->withUnlocked($this->hasPermission($helpers, $ref_id, $capability->getPermission()));
return $capability->withUnlocked($this->hasPermission($helpers, $ref_id, ...$capability->getPermissions()));
}

public function maybeBuildURI(Capability $capability, CheckHelpers $helpers, int $ref_id): Capability
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function maybeUnlock(
\ilObjFileInfo $info,
int $ref_id,
): Capability {
if (!$this->hasPermission($helpers, $ref_id, $capability->getPermission())) {
if (!$this->hasPermission($helpers, $ref_id, ...$capability->getPermissions())) {
return $capability->withUnlocked(false);
}

Expand Down
33 changes: 33 additions & 0 deletions components/ILIAS/File/classes/Capabilities/CoreTypeResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\File\Capabilities;

/**
* @author Fabian Schmid <[email protected]>
*/
class CoreTypeResolver implements TypeResolver
{
public function resolveType(int $ref_id): string
{
return \ilObject2::_lookupType($ref_id, true);
}

}
16 changes: 16 additions & 0 deletions components/ILIAS/File/classes/Capabilities/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,20 @@ enum Permissions: string
case COPY = 'copy';
case EDIT_CONTENT = 'edit_file';

public static function ANY(): array
{
return [
self::VISIBLE,
self::READ,
self::VIEW_CONTENT,
self::READ_LP,
self::EDIT_LP,
self::EDIT_PERMISSIONS,
self::WRITE,
self::DELETE,
self::COPY,
self::EDIT_CONTENT
];
}

}
30 changes: 30 additions & 0 deletions components/ILIAS/File/classes/Capabilities/TypeResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\File\Capabilities;

/**
* @author Fabian Schmid <[email protected]>
*/
interface TypeResolver
{
public function resolveType(int $ref_id): string;

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use ILIAS\File\Capabilities\CapabilityBuilder;
use ILIAS\components\WOPI\Discovery\ActionDBRepository;
use ILIAS\File\Capabilities\Capabilities;
use ILIAS\File\Capabilities\CoreTypeResolver;

/**
* @author Fabian Schmid <[email protected]>
Expand All @@ -47,6 +48,7 @@ public function __construct()
$DIC->ctrl(),
new ActionDBRepository($DIC->database()),
$DIC->http(),
new CoreTypeResolver(),
$DIC['static_url.uri_builder']
);
}
Expand Down
2 changes: 2 additions & 0 deletions components/ILIAS/File/classes/class.ilObjFileGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use ILIAS\File\Capabilities\Capabilities;
use ILIAS\File\Capabilities\CapabilityBuilder;
use ILIAS\File\Capabilities\CapabilityCollection;
use ILIAS\File\Capabilities\CoreTypeResolver;

/**
* GUI class for file objects.
Expand Down Expand Up @@ -132,6 +133,7 @@ public function __construct(int $a_id = 0, int $a_id_type = self::REPOSITORY_NOD
$this->ctrl,
$this->action_repo,
$DIC->http(),
new CoreTypeResolver(),
$DIC['static_url.uri_builder']
);
$this->capabilities = $capability_builder->get($a_id);
Expand Down
2 changes: 2 additions & 0 deletions components/ILIAS/File/classes/class.ilObjFileListGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use ILIAS\components\WOPI\Discovery\ActionDBRepository;
use ILIAS\File\Capabilities\Capabilities;
use ILIAS\File\Capabilities\CapabilityBuilder;
use ILIAS\File\Capabilities\CoreTypeResolver;

/**
* Class ilObjFileListGUI
Expand Down Expand Up @@ -54,6 +55,7 @@ public function __construct(int $context = self::CONTEXT_REPOSITORY)
$this->ctrl,
new ActionDBRepository($DIC->database()),
$DIC->http(),
new CoreTypeResolver(),
$DIC['static_url.uri_builder']
);

Expand Down
39 changes: 39 additions & 0 deletions components/ILIAS/File/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
File Object
===========

# General Information

The file object is the files that were created in the magazine via ‘Add new
Object’. The file object uses many of the central file services and also offers
WOPI actions, for example.

# Capabilities

The file object uses an internal mechanism to handle all the ‘functions’ that a
user with a file object can perform. The capabilities currently check
authorisations, whether WOPI actions are available for a file and also certain
settings per object. The capabilities per user and file object are calculated
once per request and are then used to provide links to actions, create tabs and
also handle static URLs, for example. In particular, the capabilities are also
used to decide which action to open by default when clicking on a file object in
the magazine.
Here is a list (based on unit tests) of cases in which a default action is to be
expected:

<!-- START CAPABILITY_TABLE -->

| User's Permissions | WOPI View Action av. | WOPI Edit Action av. | Click-Setting | Expected Capability |
| --------------------------------------------- | -------------------- | -------------------- | ------------- | ------------------- |
| read | Yes | Yes | Open | DOWNLOAD |
| write, read | Yes | Yes | Open | DOWNLOAD |
| edit_file | Yes | Yes | Open | EDIT_EXTERNAL |
| read, visible | No | No | Info-Page | FORCED_INFO_PAGE |
| read, write, visible, edit_file, view_content | Yes | Yes | Info-Page | FORCED_INFO_PAGE |
| write, read | Yes | Yes | Info-Page | FORCED_INFO_PAGE |
| visible | Yes | Yes | Open | INFO_PAGE |
| write | Yes | Yes | Open | MANAGE_VERSIONS |
| none | Yes | Yes | Open | NONE |
| edit_file, view_content | Yes | Yes | Open | VIEW_EXTERNAL |
| read, write, visible, edit_file, view_content | Yes | Yes | Open | VIEW_EXTERNAL |

<!-- END CAPABILITY_TABLE -->
Loading

0 comments on commit a57223e

Please sign in to comment.