Skip to content

Commit 6c85823

Browse files
authored
Improve handling of visibility in S3 (#16735)
### What does it do? Improves the visibility handling of objects on S3, while maintaining preferring the default "private" status. ### Why is it needed? Currently, there is no way to set or view the visibility of S3 Objects. ### How to test Open an AWS container with various visible and non-visible objects. Before: ![image](https://github.com/user-attachments/assets/288615b8-6158-4b89-b7df-1ce97b656f10) After: ![image](https://github.com/user-attachments/assets/b1d32316-1ec7-4818-9870-112fdba4467c) ### Related issue(s)/PR(s) Fixes issue #16432
1 parent 8edfde0 commit 6c85823

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

core/src/Revolution/Sources/modS3MediaSource.php

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
class modS3MediaSource extends modMediaSource
2525
{
26-
protected $visibility_files = false;
26+
protected $visibility_files = true;
2727
protected $visibility_dirs = false;
2828

2929

@@ -179,7 +179,7 @@ public function getDefaultProperties()
179179
'desc' => 'prop_file.visibility_desc',
180180
'type' => 'modx-combo-visibility',
181181
'options' => '',
182-
'value' => 'public',
182+
'value' => 'private',
183183
'lexicon' => 'core:source',
184184
],
185185
'skipFiles' => [
@@ -398,7 +398,7 @@ public function getContainerList($path)
398398
'menu' => [
399399
'items' => $this->getListDirContextMenu(),
400400
],
401-
'visibility' => true
401+
'visibility' => $this->getVisibilityDirectory($object['path'])
402402
];
403403
} elseif (
404404
$object['type'] === 'file' &&
@@ -643,19 +643,22 @@ public function renameContainer($oldPath, $newName)
643643
public function getVisibility($path)
644644
{
645645
// S3 Visibility Checks always returning false
646-
return true;
646+
return false;
647647
}
648648

649+
public function getVisibilityFile($path)
650+
{
651+
if ($this->visibility_files) {
652+
return $this->filesystem->visibility($path);
653+
}
654+
return false;
655+
}
649656

650-
/**
651-
* @param string $path ~ relative path of file/directory
652-
* @param string $visibility ~ public or private
653-
*
654-
* @return bool
655-
*/
656-
public function setVisibility($path, $visibility)
657+
public function getVisibilityDirectory($path)
657658
{
658-
// S3 Set visibility always returns false
659+
if ($this->visibility_dirs) {
660+
return $this->filesystem->visibility($path);
661+
}
659662
return false;
660663
}
661664

@@ -666,7 +669,7 @@ protected function getImageDimensions($path, $ext)
666669

667670
protected function isFileBinary($file)
668671
{
669-
$binary_extensions = [
672+
$non_binary_extensions = [
670673
'css',
671674
'csv',
672675
'htm',
@@ -688,12 +691,12 @@ protected function isFileBinary($file)
688691
'txt',
689692
'xml',
690693
];
691-
foreach ($binary_extensions as $a) {
694+
foreach ($non_binary_extensions as $a) {
692695
if (stripos($file, $a) !== false) {
693-
return true;
696+
return false;
694697
}
695698
}
696-
return false;
699+
return true;
697700
}
698701

699702
protected function isFileImage($file, $image_extensions = [])
@@ -742,7 +745,7 @@ protected function buildFileBrowserViewList($path, $ext, $image_extensions, $bas
742745
$preview_image_info = $this->buildManagerImagePreview($path, $ext, $width, $height, $bases, $properties);
743746
}
744747

745-
$visibility = $this->visibility_files ? $this->getVisibility($path) : false;
748+
$visibility = $this->visibility_files ? $this->getVisibilityFile($path) : false;
746749

747750
$lastmod = 0;
748751
$size = 0;

0 commit comments

Comments
 (0)