Skip to content

Commit ff41db6

Browse files
committed
[FIX] 0047121: Failed test: "Read only" für Administrationsknoten "Datei"
1 parent 1dde937 commit ff41db6

5 files changed

Lines changed: 71 additions & 74 deletions

File tree

components/ILIAS/File/classes/Icons/IconListingUI.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ class IconListingUI
3939
private Standard $icon_list;
4040
private \ilUIFilterService $filter_service;
4141
private \ILIAS\UI\Component\Input\Container\Filter\Standard $filter;
42-
private \ILIAS\HTTP\Services $http;
4342

4443
public function __construct(
4544
private IconRepositoryInterface $icon_repo,
46-
private object $gui
45+
private ilObjFileIconsOverviewGUI $gui,
46+
private bool $write_access
4747
) {
4848
global $DIC;
4949

@@ -53,7 +53,6 @@ public function __construct(
5353
$this->ui_factory = $DIC->ui()->factory();
5454
$this->refinery = $DIC->refinery();
5555
$this->storage = $DIC->resourceStorage();
56-
$this->http = $DIC->http();
5756
$this->filter_service = $DIC->uiService()->filter();
5857

5958
$this->initFilter();
@@ -116,18 +115,23 @@ protected function initListing(): void
116115
);
117116
$this->deletion_modals[] = $deletion_modal = $this->getDeletionConfirmationModal($icon);
118117

119-
$item_action_entries = [
120-
$this->ui_factory->button()->shy(
121-
$this->lng->txt('de_activate_icon'),
122-
$change_activation_target
123-
)
124-
];
125-
if (!$icon->isDefaultIcon()) {
126-
$item_action_entries[] = $this->ui_factory->button()->shy($this->lng->txt('edit'), $edit_target);
127-
$item_action_entries[] = $this->ui_factory->button()->shy($this->lng->txt('delete'), '#')->withOnClick(
128-
$deletion_modal->getShowSignal()
129-
);
118+
if ($this->write_access) {
119+
$item_action_entries = [
120+
$this->ui_factory->button()->shy(
121+
$this->lng->txt('de_activate_icon'),
122+
$change_activation_target
123+
)
124+
];
125+
if (!$icon->isDefaultIcon()) {
126+
$item_action_entries[] = $this->ui_factory->button()->shy($this->lng->txt('edit'), $edit_target);
127+
$item_action_entries[] = $this->ui_factory->button()->shy($this->lng->txt('delete'), '#')->withOnClick(
128+
$deletion_modal->getShowSignal()
129+
);
130+
}
131+
} else {
132+
$item_action_entries = [];
130133
}
134+
131135
$item_actions = $this->ui_factory->dropdown()->standard($item_action_entries);
132136

133137
$id = $this->storage->manage()->find($icon->getRid());

components/ILIAS/File/classes/Icons/class.ilObjFileIconsOverviewGUI.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@ class ilObjFileIconsOverviewGUI
5454
private Services $storage;
5555
private IconRepositoryInterface $icon_repo;
5656
private \ilFileServicesSettings $file_service_settings;
57+
private \ilAccessHandler $access;
58+
private bool $write_access;
5759

5860
final public function __construct()
5961
{
6062
global $DIC;
6163
$this->ctrl = $DIC->ctrl();
64+
$this->access = $DIC->access();
6265
$this->lng = $DIC->language();
6366
$this->lng->loadLanguageModule('file');
6467
$this->toolbar = $DIC->toolbar();
@@ -71,6 +74,11 @@ final public function __construct()
7174
$this->storage = $DIC->resourceStorage();
7275
$this->icon_repo = new IconDatabaseRepository();
7376
$this->file_service_settings = $DIC->fileServiceSettings();
77+
$this->write_access = $this->access->checkAccess(
78+
'write',
79+
'',
80+
(int) ($this->http_request->getQueryParams()['ref_id'] ?? 0)
81+
);
7482
}
7583

7684
final public function executeCommand(): void
@@ -95,16 +103,19 @@ final public function executeCommand(): void
95103
private function index(): void
96104
{
97105
// toolbar: add new icon button
98-
$btn_new_icon = $this->ui_factory->button()->standard(
99-
$this->lng->txt('add_icon'),
100-
$this->ctrl->getLinkTargetByClass(self::class, self::CMD_OPEN_CREATION_FORM)
101-
);
102-
$this->toolbar->addComponent($btn_new_icon);
106+
if ($this->write_access) {
107+
$btn_new_icon = $this->ui_factory->button()->standard(
108+
$this->lng->txt('add_icon'),
109+
$this->ctrl->getLinkTargetByClass(self::class, self::CMD_OPEN_CREATION_FORM)
110+
);
111+
$this->toolbar->addComponent($btn_new_icon);
112+
}
103113

104114
// Listing of icons
105115
$listing = new IconListingUI(
106116
$this->icon_repo,
107-
$this
117+
$this,
118+
$this->write_access
108119
);
109120

110121
$content = [];

components/ILIAS/File/classes/Preview/Form.php

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
<?php
22

3-
/**
4-
* This file is part of ILIAS, a powerful learning management system
5-
* published by ILIAS open source e-Learning e.V.
6-
*
7-
* ILIAS is licensed with the GPL-3.0,
8-
* see https://www.gnu.org/licenses/gpl-3.0.en.html
9-
* You should have received a copy of said license along with the
10-
* source code, too.
11-
*
12-
* If this is not the case or you just want to try ILIAS, you'll find
13-
* us at:
14-
* https://www.ilias.de
15-
* https://github.com/ILIAS-eLearning
16-
*
17-
*********************************************************************/
18-
193
namespace ILIAS\components\File\Preview;
204

215
use ILIAS\UI\Component\Input\Field\Factory;
@@ -31,8 +15,10 @@ class Form
3115
private Factory $field_factory;
3216
private \ILIAS\Refinery\Factory $refinery;
3317

34-
public function __construct(private Settings $settings)
35-
{
18+
public function __construct(
19+
private Settings $settings,
20+
private bool $write_access
21+
) {
3622
global $DIC;
3723
$this->language = $DIC->language();
3824
$this->field_factory = $DIC->ui()->factory()->input()->field();
@@ -56,10 +42,10 @@ public function asFormGroup(): Group
5642
$this->language->txt('enable_preview'),
5743
$this->language->txt('enable_preview_info')
5844
)
59-
->withDisabled(!$possible)
45+
->withDisabled(!$this->write_access || !$possible)
6046
->withValue($this->settings->isPreviewEnabled())
6147
->withAdditionalTransformation(
62-
$this->refinery->custom()->transformation(function ($v): void {
48+
$this->refinery->custom()->transformation(function (bool $v): void {
6349
$this->settings->setPreviewEnabled($v);
6450
})
6551
);
@@ -69,11 +55,11 @@ public function asFormGroup(): Group
6955
$this->language->txt('preview_image_size'),
7056
$this->language->txt('preview_image_size_info')
7157
)
72-
->withDisabled(!$possible)
58+
->withDisabled(!$this->write_access || !$possible)
7359
->withRequired(true)
7460
->withValue($this->settings->getImageSize())
7561
->withAdditionalTransformation(
76-
$this->refinery->custom()->transformation(function ($v): void {
62+
$this->refinery->custom()->transformation(function (int $v): void {
7763
$this->settings->setImageSize($v);
7864
})
7965
);
@@ -83,10 +69,10 @@ public function asFormGroup(): Group
8369
$this->language->txt('preview_persisting'),
8470
$this->language->txt('preview_persisting_info')
8571
)
86-
->withDisabled(!$possible)
72+
->withDisabled(!$this->write_access || !$possible)
8773
->withValue($this->settings->isPersisting())
8874
->withAdditionalTransformation(
89-
$this->refinery->custom()->transformation(function ($v): void {
75+
$this->refinery->custom()->transformation(function (bool $v): void {
9076
$this->settings->setPersisting($v);
9177
})
9278
);
@@ -96,10 +82,10 @@ public function asFormGroup(): Group
9682
$this->language->txt('max_previews_per_object'),
9783
$this->language->txt('max_previews_per_object_info')
9884
)
99-
->withDisabled(!$possible)
85+
->withDisabled(!$this->write_access || !$possible)
10086
->withValue($this->settings->getMaximumPreviews())
10187
->withAdditionalTransformation(
102-
$this->refinery->custom()->transformation(function ($v): void {
88+
$this->refinery->custom()->transformation(function (int $v): void {
10389
$this->settings->setMaximumPreviews($v);
10490
})
10591
);
@@ -109,10 +95,10 @@ public function asFormGroup(): Group
10995
$this->language->txt('previews_for_tiles'),
11096
$this->language->txt('previews_for_tiles_info')
11197
)
112-
->withDisabled(!$possible)
98+
->withDisabled(!$this->write_access || !$possible)
11399
->withValue($this->settings->hasTilePreviews())
114100
->withAdditionalTransformation(
115-
$this->refinery->custom()->transformation(function ($v): void {
101+
$this->refinery->custom()->transformation(function (bool $v): void {
116102
$this->settings->setTilePreviews($v);
117103
})
118104
);

components/ILIAS/File/classes/Settings/Form.php

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
<?php
22

3-
/**
4-
* This file is part of ILIAS, a powerful learning management system
5-
* published by ILIAS open source e-Learning e.V.
6-
*
7-
* ILIAS is licensed with the GPL-3.0,
8-
* see https://www.gnu.org/licenses/gpl-3.0.en.html
9-
* You should have received a copy of said license along with the
10-
* source code, too.
11-
*
12-
* If this is not the case or you just want to try ILIAS, you'll find
13-
* us at:
14-
* https://www.ilias.de
15-
* https://github.com/ILIAS-eLearning
16-
*
17-
*********************************************************************/
18-
193
namespace ILIAS\components\File\Settings;
204

215
use ILIAS\UI\Component\Input\Field\Factory;
@@ -31,8 +15,10 @@ class Form
3115
private Factory $field_factory;
3216
private \ILIAS\Refinery\Factory $refinery;
3317

34-
public function __construct(private General $settings)
35-
{
18+
public function __construct(
19+
private General $settings,
20+
private bool $write_access
21+
) {
3622
global $DIC;
3723
$this->language = $DIC->language();
3824
$this->language->loadLanguageModule("bgtask");
@@ -57,8 +43,9 @@ public function asFormGroup(): Group
5743
)
5844
->withValue($this->settings->getDownloadLimitinMB())
5945
->withRequired(true)
46+
->withDisabled(!$this->write_access)
6047
->withAdditionalTransformation(
61-
$this->refinery->custom()->transformation(function ($value) {
48+
$this->refinery->custom()->transformation(function (int $value): int {
6249
$this->settings->setDownloadLimitInMB($value);
6350
return $value;
6451
})
@@ -71,8 +58,9 @@ public function asFormGroup(): Group
7158
$this->language->txt('inline_file_extensions_info')
7259
)
7360
->withValue($this->settings->getInlineFileExtensions())
61+
->withDisabled(!$this->write_access)
7462
->withAdditionalTransformation(
75-
$this->refinery->custom()->transformation(function ($value) {
63+
$this->refinery->custom()->transformation(function (array $value): array {
7664
$this->settings->setInlineFileExtensions($value);
7765
return $value;
7866
})
@@ -84,9 +72,10 @@ public function asFormGroup(): Group
8472
$this->language->txt('show_amount_of_downloads_info')
8573
)
8674
->withValue($this->settings->isShowAmountOfDownloads())
75+
->withDisabled(!$this->write_access)
8776
->withAdditionalTransformation(
8877
$this->refinery->custom()->transformation(
89-
function ($value) {
78+
function (bool $value): bool {
9079
$this->settings->setShowAmountOfDownloads($value);
9180
return $value;
9281
}
@@ -99,8 +88,9 @@ function ($value) {
9988
$this->language->txt('download_ascii_filename_info')
10089
)
10190
->withValue($this->settings->isDownloadWithAsciiFileName())
91+
->withDisabled(!$this->write_access)
10292
->withAdditionalTransformation(
103-
$this->refinery->custom()->transformation(function ($value) {
93+
$this->refinery->custom()->transformation(function (bool $value): bool {
10494
$this->settings->setDownloadWithAsciiFileName($value);
10595
return $value;
10696
})

components/ILIAS/File/classes/class.ilObjFileAccessSettingsGUI.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use ILIAS\UI\Factory;
2121
use ILIAS\UI\Renderer;
2222
use ILIAS\UI\Component\Input\Container\Form\Standard;
23-
use ILIAS\HTTP\Services;
2423
use ILIAS\File\Icon\ilObjFileIconsOverviewGUI;
2524
use ILIAS\components\File\Preview\Settings;
2625
use ILIAS\components\File\Settings\General;
@@ -47,6 +46,7 @@ class ilObjFileAccessSettingsGUI extends ilObjectGUI
4746
private ilLanguage $language;
4847
private Form $preview_settings;
4948
private \ILIAS\components\File\Settings\Form $file_object_settings;
49+
private bool $write_access;
5050
protected Factory $ui_factory;
5151
protected Renderer $ui_renderer;
5252

@@ -60,8 +60,15 @@ public function __construct($a_data, int $a_id, bool $a_call_by_reference)
6060
global $DIC;
6161
$this->type = "facs";
6262
parent::__construct($a_data, $a_id, $a_call_by_reference, false);
63-
$this->preview_settings = new Form(new Settings());
64-
$this->file_object_settings = new \ILIAS\components\File\Settings\Form(new General());
63+
$this->write_access = $this->access->checkAccess('write', '', $this->object->getRefId());
64+
$this->preview_settings = new Form(
65+
new Settings(),
66+
$this->write_access
67+
);
68+
$this->file_object_settings = new \ILIAS\components\File\Settings\Form(
69+
new General(),
70+
$this->write_access
71+
);
6572
$this->ui_factory = $DIC->ui()->factory();
6673
$this->ui_renderer = $DIC->ui()->renderer();
6774
$this->language = $DIC->language();
@@ -169,7 +176,6 @@ protected function editSettings(): void
169176
{
170177
$this->addFileObjectsSubTabs();
171178
$this->tabs_gui->setSubTabActive("settings");
172-
$form = $this->buildForm();
173179
$this->tpl->setContent($this->ui_renderer->render($this->buildForm()));
174180
}
175181

0 commit comments

Comments
 (0)