Skip to content

feat(3.x): better handling of visibility in S3 #16735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions core/src/Revolution/Sources/modS3MediaSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
class modS3MediaSource extends modMediaSource
{
protected $visibility_files = false;
protected $visibility_files = true;
protected $visibility_dirs = false;


Expand Down Expand Up @@ -179,7 +179,7 @@ public function getDefaultProperties()
'desc' => 'prop_file.visibility_desc',
'type' => 'modx-combo-visibility',
'options' => '',
'value' => 'public',
'value' => 'private',
'lexicon' => 'core:source',
],
'skipFiles' => [
Expand Down Expand Up @@ -398,7 +398,7 @@ public function getContainerList($path)
'menu' => [
'items' => $this->getListDirContextMenu(),
],
'visibility' => true
'visibility' => $this->getVisibilityDirectory($object['path'])
];
} elseif (
$object['type'] === 'file' &&
Expand Down Expand Up @@ -643,19 +643,22 @@ public function renameContainer($oldPath, $newName)
public function getVisibility($path)
{
// S3 Visibility Checks always returning false
return true;
return false;
}

public function getVisibilityFile($path)
{
if ($this->visibility_files) {
return $this->filesystem->visibility($path);
}
return false;
}

/**
* @param string $path ~ relative path of file/directory
* @param string $visibility ~ public or private
*
* @return bool
*/
public function setVisibility($path, $visibility)
public function getVisibilityDirectory($path)
{
// S3 Set visibility always returns false
if ($this->visibility_dirs) {
return $this->filesystem->visibility($path);
}
return false;
}

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

protected function isFileBinary($file)
{
$binary_extensions = [
$non_binary_extensions = [
'css',
'csv',
'htm',
Expand All @@ -688,12 +691,12 @@ protected function isFileBinary($file)
'txt',
'xml',
];
foreach ($binary_extensions as $a) {
foreach ($non_binary_extensions as $a) {
if (stripos($file, $a) !== false) {
return true;
return false;
}
}
return false;
return true;
}

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

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

$lastmod = 0;
$size = 0;
Expand Down