Skip to content

Commit

Permalink
Issue #27: Check Collabora access in the field formatter.
Browse files Browse the repository at this point in the history
  • Loading branch information
donquixote authored and hfiguiere committed Oct 24, 2024
1 parent c5362c3 commit 1b5536a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Plugin/Field/FieldFormatter/CoolPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Drupal\collabora_online\Plugin\Field\FieldFormatter;

use Drupal\collabora_online\Cool\CoolUtils;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase;
use Drupal\media\MediaInterface;
Expand Down Expand Up @@ -49,6 +50,15 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
return [];
}

$access_result = $media->access('preview in collabora', NULL, TRUE);
(new CacheableMetadata())
->addCacheableDependency($access_result)
->applyTo($elements);

if (!$access_result->isAllowed()) {
return $elements;
}

foreach ($this->getEntitiesToView($items, $langcode) as $delta => $file) {
$url = CoolUtils::getEditorUrl($media, false);

Expand Down

0 comments on commit 1b5536a

Please sign in to comment.