Skip to content

Commit

Permalink
Merge pull request #114 from discoverygarden/DDST-388
Browse files Browse the repository at this point in the history
[DDST-388] add http and https schemes as options
  • Loading branch information
nchiasson-dgi authored Aug 6, 2024
2 parents bdfc107 + 19e58eb commit fa749e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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

0 comments on commit fa749e4

Please sign in to comment.