Skip to content
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

[DDST-388] add http and https schemes as options #114

Merged
merged 6 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion src/Form/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,17 @@ public function getFormId() {
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('islandora_spreadsheet_ingest.settings');
$current_whitelist = $config->get('binary_directory_whitelist');
$scheme_options = $this->streamWrapperManager->getNames(StreamWrapperInterface::READ_VISIBLE) + [
'http' => 'HTTP',
'https' => 'HTTPS',
'ftp' => 'FTP',
];
$form['schemes'] = [
'#type' => 'checkboxes',
'#title' => $this->t('Schemes'),
'#description' => $this->t('Allowed list of schemes for which binaries can be referenced from.'),
'#default_value' => $config->get('schemes') ?? [],
'#options' => $this->streamWrapperManager->getNames(StreamWrapperInterface::READ_VISIBLE),
'#options' => $scheme_options,
];
$form['paths'] = [
'#type' => 'textarea',
Expand Down
16 changes: 16 additions & 0 deletions src/Plugin/migrate/process/AccessibleFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Drupal\Core\Url;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -99,6 +101,20 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
$allowed_paths = $this->configFactory->get('islandora_spreadsheet_ingest.settings')->get('binary_directory_whitelist');
$allowed_schemes = $this->configFactory->get('islandora_spreadsheet_ingest.settings')->get('schemes');

// Ignore this check if relevant configuration has not been set, and advise
// that the configuration should be set.
if (empty($allowed_paths) && empty($allowed_schemes)) {
$migrate_executable->saveMessage(
strtr("File access criteria is not defined; passing check of file (:file). For site security, it is highly recommended to set appropriate configuration at :config_url.", [
':file' => $value,
':config_url' => Url::fromRoute('islandora_spreadsheet_ingest.admin')->toString(),
]),
MigrationInterface::MESSAGE_WARNING
);

return $value;
}

// If it's a local path check to see if it's in our allowed list.
$file_path = $this->fileSystem->realpath($value);
if ($file_path) {
Expand Down
Loading