-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] WOPI View Actions for File Objects
- Loading branch information
Showing
23 changed files
with
1,267 additions
and
177 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
components/ILIAS/File/classes/Capabilities/Capabilities.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?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 | ||
* | ||
*********************************************************************/ | ||
|
||
/** | ||
* @author Fabian Schmid <[email protected]> | ||
*/ | ||
|
||
namespace ILIAS\File\Capabilities; | ||
|
||
enum Capabilities: string | ||
{ | ||
case EDIT_EXTERNAL = 'editExternal'; | ||
case INFO_PAGE = 'showSummary'; | ||
case MANAGE_VERSIONS = 'versions'; | ||
case EDIT_SETTINGS = 'edit'; | ||
case UNZIP = 'unzipCurrentRevision'; | ||
case DOWNLOAD = 'sendfile'; | ||
case VIEW_EXTERNAL = 'viewExternal'; | ||
case NONE = 'none'; | ||
|
||
public static function fromName(string $name): Capabilities | ||
{ | ||
foreach (self::cases() as $case) { | ||
if ($name === $case->name) { | ||
return $case; | ||
} | ||
} | ||
return self::NONE; | ||
} | ||
|
||
public static function fromCommand(string $cmd): Capabilities | ||
{ | ||
foreach (self::cases() as $case) { | ||
if ($cmd === $case->value) { | ||
return $case; | ||
} | ||
} | ||
return self::NONE; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?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 | ||
* | ||
*********************************************************************/ | ||
|
||
/** | ||
* @author Fabian Schmid <[email protected]> | ||
*/ | ||
|
||
namespace ILIAS\File\Capabilities; | ||
|
||
use ILIAS\Data\URI; | ||
|
||
class Capability | ||
{ | ||
private bool $unlocked = false; | ||
private ?URI $uri = null; | ||
|
||
public function __construct( | ||
private Capabilities $capability, | ||
private Permissions $permission | ||
) { | ||
} | ||
|
||
public function withUnlocked(bool $unlocked): Capability | ||
{ | ||
$this->unlocked = $unlocked; | ||
return $this; | ||
} | ||
|
||
public function withURI(?URI $uri): Capability | ||
{ | ||
$this->uri = $uri; | ||
return $this; | ||
} | ||
|
||
public function isUnlocked(): bool | ||
{ | ||
return $this->unlocked; | ||
} | ||
|
||
public function getUri(): ?URI | ||
{ | ||
return $this->uri; | ||
} | ||
|
||
public function getCapability(): Capabilities | ||
{ | ||
return $this->capability; | ||
} | ||
|
||
public function getPermission(): Permissions | ||
{ | ||
return $this->permission; | ||
} | ||
|
||
} |
107 changes: 107 additions & 0 deletions
107
components/ILIAS/File/classes/Capabilities/CapabilityBuilder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?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; | ||
|
||
use ILIAS\components\WOPI\Discovery\ActionRepository; | ||
use ILIAS\DI\Container; | ||
use ILIAS\File\Capabilities\Check\Download; | ||
use ILIAS\File\Capabilities\Check\EditContent; | ||
use ILIAS\File\Capabilities\Check\Manage; | ||
use ILIAS\File\Capabilities\Check\Unzip; | ||
use ILIAS\File\Capabilities\Check\ViewContent; | ||
use ILIAS\File\Capabilities\Check\None; | ||
use ILIAS\File\Capabilities\Check\Info; | ||
use ILIAS\File\Capabilities\Check\Edit; | ||
use ILIAS\File\Capabilities\Check\Check; | ||
use ILIAS\File\Capabilities\Check\CheckHelpers; | ||
|
||
/** | ||
* @author Fabian Schmid <[email protected]> | ||
*/ | ||
class CapabilityBuilder | ||
{ | ||
protected array $cache = []; | ||
/** | ||
* @var Check[] | ||
*/ | ||
private array $checks = []; | ||
|
||
public function __construct( | ||
private \ilObjFileInfoRepository $file_info_repository, | ||
private \ilAccessHandler $access, | ||
private \ilCtrlInterface $ctrl, | ||
private ActionRepository $action_repository | ||
) { | ||
$this->checks = [ | ||
new Download(), | ||
new Edit(), | ||
new EditContent(), | ||
new Info(), | ||
new Manage(), | ||
new None(), | ||
new Unzip(), | ||
new ViewContent(), | ||
]; | ||
} | ||
|
||
public function get(int $ref_id, bool $do_checks = true): CapabilityCollection | ||
{ | ||
if (isset($this->cache[$ref_id])) { | ||
return $this->cache[$ref_id]; | ||
} | ||
|
||
/** | ||
* This is the order of priorities when | ||
* using @see CapabilityCollection::getBest() | ||
* which will return the first unlocked Capability | ||
*/ | ||
$capabilities = [ | ||
new Capability(Capabilities::VIEW_EXTERNAL, Permissions::VIEW_CONTENT), | ||
new Capability(Capabilities::EDIT_EXTERNAL, Permissions::EDIT_FILE), | ||
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::NONE, Permissions::NONE), | ||
new Capability(Capabilities::UNZIP, Permissions::WRITE), | ||
]; | ||
|
||
|
||
if (\ilObject2::_lookupType($ref_id, true) !== 'file') { | ||
return new CapabilityCollection($capabilities); | ||
} | ||
|
||
$info = $this->file_info_repository->getByRefId($ref_id); | ||
$helpers = new CheckHelpers($this->access, $this->ctrl, $this->action_repository); | ||
$this->ctrl->setParameterByClass(\ilObjFileGUI::class, 'ref_id', $ref_id); | ||
|
||
foreach ($capabilities as $capability) { | ||
foreach ($this->checks as $check) { | ||
if ($check->canUnlock() === $capability->getCapability()) { | ||
$capability = $check->maybeUnlock($capability, $helpers, $info, $ref_id); | ||
$capability = $check->maybeBuildURI($capability, $helpers, $ref_id); | ||
} | ||
} | ||
} | ||
return $this->cache[$ref_id] = new CapabilityCollection($capabilities); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
components/ILIAS/File/classes/Capabilities/CapabilityCollection.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?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; | ||
|
||
use ILIAS\components\WOPI\Discovery\ActionRepository; | ||
|
||
/** | ||
* @author Fabian Schmid <[email protected]> | ||
*/ | ||
class CapabilityCollection | ||
{ | ||
/** | ||
* @param Capability[] $capabilities | ||
*/ | ||
public function __construct( | ||
private array $capabilities | ||
) { | ||
} | ||
|
||
public function all(): array | ||
{ | ||
return $this->capabilities; | ||
} | ||
|
||
public function get(Capabilities $capability): Capability|false | ||
{ | ||
foreach ($this->capabilities as $cap) { | ||
if ($cap->getCapability() === $capability) { | ||
return $cap; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public function getBest(): Capability | ||
{ | ||
foreach ($this->capabilities as $cap) { | ||
if ($cap->isUnlocked()) { | ||
return $cap; | ||
} | ||
} | ||
return new Capability(Capabilities::NONE, Permissions::NONE); | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
components/ILIAS/File/classes/Capabilities/Check/BaseCheck.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?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\Check; | ||
|
||
use ILIAS\Data\URI; | ||
use ILIAS\File\Capabilities\Permissions; | ||
use ILIAS\components\WOPI\Discovery\ActionTarget; | ||
|
||
/** | ||
* @author Fabian Schmid <[email protected]> | ||
*/ | ||
abstract class BaseCheck implements Check | ||
{ | ||
public function __construct() | ||
{ | ||
} | ||
|
||
protected function hasPermission( | ||
CheckHelpers $helpers, | ||
int $ref_id, | ||
Permissions ...$permission | ||
): bool { | ||
$permission_string = implode( | ||
',', | ||
array_map(static fn(Permissions $permission) => $permission->value, $permission) | ||
); | ||
|
||
return $helpers->access->checkAccess($permission_string, '', $ref_id, 'file'); | ||
} | ||
|
||
protected function hasWopiAction(CheckHelpers $helpers, string $suffix, ActionTarget ...$action): bool | ||
{ | ||
return $helpers->action_repository->hasActionForSuffix($suffix, $action); | ||
} | ||
|
||
public function hasWopiEditAction(CheckHelpers $helpers, string $suffix): bool | ||
{ | ||
return $helpers->action_repository->hasEditActionForSuffix($suffix); | ||
} | ||
|
||
public function hasWopiViewAction(CheckHelpers $helpers, string $suffix): bool | ||
{ | ||
return $helpers->action_repository->hasViewActionForSuffix($suffix); | ||
} | ||
|
||
} |
Oops, something went wrong.