Skip to content

Commit

Permalink
[BUGFIX] Remove edit buttons if public
Browse files Browse the repository at this point in the history
  • Loading branch information
calien666 committed Feb 15, 2024
1 parent 45860f2 commit 0e319e1
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 9 deletions.
15 changes: 14 additions & 1 deletion Classes/ContextMenu/V11/ItemProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class ItemProvider extends AbstractProvider
{
protected ResourceFactory $resourceFactory;

protected Folder $folder;
protected ?Folder $folder = null;

/**
* @var array<string, mixed>
Expand Down Expand Up @@ -71,6 +71,19 @@ public function canHandle(): bool
return $this->table === 'sys_file' || $this->table === 'sys_file_storage';
}

/**
* @throws ResourceDoesNotExistException
*/
public function addItems(array $items): array
{
$this->initialize();
if (!$this->folder instanceof Folder) {
return $items;
}
$items += $this->prepareItems($this->itemsConfiguration);
return $items;
}

/**
* @throws ResourceDoesNotExistException
*/
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
$this->folder = $folder;
$this->folderHash = $folderHash;
$this->storage = $storage;
$this->feGroups = !empty($feGroups) ? GeneralUtility::intExplode(',', $feGroups) : [];
$this->feGroups = !empty($feGroups) ? GeneralUtility::intExplode(',', $feGroups, true) : [];
}

public function getUid(): int
Expand Down
22 changes: 19 additions & 3 deletions Classes/EventListener/EditAccessRightsButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ final class EditAccessRightsButton
{
private static string $filePattern = '/(\d)(:)(.*)/';

private IconFactory $iconFactory;

private UriBuilder $uriBuilder;

private FolderRepository $folderRepository;

public function __construct(
UriBuilder $uriBuilder,
FolderRepository $folderRepository,
IconFactory $iconFactory
) {
$this->uriBuilder = $uriBuilder;
$this->folderRepository = $folderRepository;
$this->iconFactory = $iconFactory;
}

public function __invoke(ModifyButtonBarEvent $event): void
{
/** @var ServerRequestInterface $request */
Expand All @@ -36,7 +52,7 @@ public function __invoke(ModifyButtonBarEvent $event): void
$storageId = (int)$matches[1];
$path = $matches[3];

$folder = GeneralUtility::makeInstance(FolderRepository::class)
$folder = $this->folderRepository
->findByStorageAndPath($storageId, $path);

if ($folder->getStorage()->isPublic()) {
Expand All @@ -45,11 +61,11 @@ public function __invoke(ModifyButtonBarEvent $event): void

$editAccessRightsButton = $event->getButtonBar()->makeLinkButton()
->setIcon(
GeneralUtility::makeInstance(IconFactory::class)
$this->iconFactory
->getIcon('actions-lock', Icon::SIZE_SMALL)
)
->setHref(
(string)GeneralUtility::makeInstance(UriBuilder::class)
(string)$this->uriBuilder
->buildUriFromRoute(
'record_edit',
[
Expand Down
4 changes: 4 additions & 0 deletions Classes/Hooks/ButtonBarHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public function renderButtons(array $params, ButtonBar $buttonBar): array
$folder = GeneralUtility::makeInstance(FolderRepository::class)
->findByStorageAndPath($storageId, $path);

if ($folder->getStorage()->isPublic()) {
return $buttons;
}

$editButton = $buttonBar->makeLinkButton()
->setIcon(
GeneralUtility::makeInstance(IconFactory::class)
Expand Down
15 changes: 15 additions & 0 deletions Configuration/TCA/Overrides/tx_securefilemount_folder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);


(static function (): void {
/**
* @deprecated will be removed with removal of v11 support
* cruser_id is breaking removed in v12
* @see https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Breaking-98024-TCA-option-cruserid-removed.html
*/
if ((new \TYPO3\CMS\Core\Information\Typo3Version())->getMajorVersion() < 12) {
$GLOBALS['TCA']['tx_securefilemount_folder']['ctrl']['cruser_id'] = 'cruser_id';
}
})();
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
}
],
"require": {
"php": "^7.4 || ^8.0 || ^8.1 || ^8.2",
"php": "^7.4 || ^8.0 || ^8.1 || ^8.2 || ^8.3",
"typo3/cms-backend": "^11.5 || ^12.4",
"typo3/cms-core": "^11.5 || ^12.4",
"typo3/cms-filelist": "^11.5 || ^12.4"
"typo3/cms-filelist": "^11.5 || ^12.4",
"typo3/cms-frontend": "^11.5 || ^12.4"
},
"require-dev": {
"typo3/testing-framework": "^7.0",
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'constraints' => [
'depends' => [
'typo3' => '11.5.0-12.4.99',
'php' => '7.4.0-8.2.99',
'php' => '7.4.0-8.3.99',
],
'conflicts' => [
'fal_securedownload' => '',
Expand Down
2 changes: 1 addition & 1 deletion ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
= \Calien\SecureFilemount\ContextMenu\V11\ItemProvider::class;

// Will be removed when v11 support dropped
// @see @see https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Breaking-96806-RemovedHookForModifyingButtonBar.html
// @see https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Breaking-96806-RemovedHookForModifyingButtonBar.html
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Backend\Template\Components\ButtonBar']['getButtonsHook'][1679002016878]
= \Calien\SecureFilemount\Hooks\ButtonBarHook::class . '->renderButtons';
}
Expand Down

0 comments on commit 0e319e1

Please sign in to comment.