Skip to content

Commit

Permalink
Merge remote-tracking branch 'dgi/8.x-2.x' into move-base
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-vessey committed Jun 4, 2021
2 parents ab97f46 + a2dc99b commit 1a304e1
Show file tree
Hide file tree
Showing 14 changed files with 530 additions and 20 deletions.
5 changes: 5 additions & 0 deletions islandora_spreadsheet_ingest.links.menu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ islandora_spreadsheet_ingest.request.list:
parent: system.admin_content
title: 'Add from Spreadsheet'
description: 'Permits ingest of content described in spreadsheets.'
islandora_spreadsheet_ingest.admin:
route_name: islandora_spreadsheet_ingest.admin
parent: system.admin_config_islandora
title: 'Islandora Spreadsheet Ingest Settings'
description: 'Configure settings for the Islandora Spreadsheet Ingest module.'
36 changes: 36 additions & 0 deletions islandora_spreadsheet_ingest.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* General hook implementations.
*/

use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;

use Drupal\islandora_spreadsheet_ingest\RequestInterface;
Expand Down Expand Up @@ -134,3 +136,37 @@ function islandora_spreadsheet_ingest_entity_operation(EntityInterface $entity)

return $ops;
}

/**
* Helper for the migration access checks.
*
* @see islandora_spreadsheet_ingest_migration_group_entity_access()
* @see islandora_spreadsheet_ingest_migration_entity_access()
*/
function _islandora_spreadsheet_ingest_migration_entity_helper(EntityInterface $entity, AccountInterface $account, $uid, $tags) {
return AccessResult::allowedIf(in_array('isi_derived_migration', $tags))
->addCacheableDependency($entity)
->andIf(
AccessResult::allowedIf($uid !== FALSE && $uid == $account->id())
->cachePerUser()
);
}

/**
* Implements hook_ENTITY_TYPE_entity_access() for migration_group entities.
*/
function islandora_spreadsheet_ingest_migration_group_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
$shared = $entity->shared_configuration ?? [];
$tags = NestedArray::getValue($shared, ['migration_tags']) ?? [];
$uid = NestedArray::getValue($shared, ['source', 'isi', 'uid']) ?? FALSE;
return _islandora_spreadsheet_ingest_migration_entity_helper($entity, $account, $uid, $tags);
}

/**
* Implements hook_ENTITY_TYPE_entity_access() for migration entities.
*/
function islandora_spreadsheet_ingest_migration_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
$tags = $entity->migration_tags ?? [];
$uid = NestedArray::getValue($entity->source, ['isi', 'uid']) ?? FALSE;
return _islandora_spreadsheet_ingest_migration_entity_helper($entity, $account, $uid, $tags);
}
15 changes: 15 additions & 0 deletions islandora_spreadsheet_ingest.permissions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'administer islandora_spreadsheet_ingest requests':
title: 'Administer requests'
'create islandora_spreadsheet_ingest requests':
title: 'Create request'
'edit islandora_spreadsheet_ingest requests':
title: 'Edit request'
'edit islandora_spreadsheet_ingest request mapping':
title: 'Edit request mapping'
'view islandora_spreadsheet_ingest requests':
title: 'View requests'
'activate islandora_spreadsheet_ingest requests':
title: 'Activate requests'
'deleta islandora_spreadsheet_ingest requests':
title: 'Delete requests'
26 changes: 17 additions & 9 deletions islandora_spreadsheet_ingest.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,54 @@ entity.isi_request.list:
_entity_list: isi_request
_title: Islandora Spreadsheet Ingest
requirements:
_permission: 'access content overview'
_permission: 'view islandora_spreadsheet_ingest requests'
entity.isi_request.add_form:
path: '/admin/content/islandora_spreadsheet_ingest/add'
defaults:
_title: 'Add Content From Spreadsheet - Upload'
_entity_form: 'isi_request.add'
requirements:
_permission: 'access content overview'
_entity_create_access: 'isi_request'
entity.isi_request.edit_form:
path: '/admin/content/islandora_spreadsheet_ingest/{isi_request}/edit'
defaults:
_title: 'Edit'
_entity_form: 'isi_request.edit'
requirements:
_permission: 'access content overview'
_entity_access: 'isi_request.update'
entity.isi_request.map_form:
path: '/admin/content/islandora_spreadsheet_ingest/{isi_request}/mapping'
defaults:
_title: 'Mapping'
_entity_form: 'isi_request.map'
requirements:
_permission: 'access content overview'
_entity_access: 'isi_request.map'
entity.isi_request.delete_form:
path: '/admin/content/islandora_spreadsheet_ingest/{isi_request}/delete'
defaults:
_title: 'Delete'
_entity_form: 'isi_request.delete'
requirements:
_permission: 'access content overview'
_entity_access: 'isi_request.delete'
entity.isi_request.view:
path: '/admin/content/islandora_spreadsheet_ingest/{isi_request}'
defaults:
#_title: 'View'
_entity_form: 'isi_request.view'
_entity_view: 'isi_request.full'
requirements:
_permission: 'access content overview'
_entity_access: 'isi_request.view'
entity.isi_request.activate_form:
path: '/admin/content/islandora_spreadsheet_ingest/{isi_request}/activate'
defaults:
_title: 'Activate'
_entity_form: 'isi_request.activate'
requirements:
_permission: 'access content overview'
_entity_access: 'isi_request.activate'
islandora_spreadsheet_ingest.admin:
path: '/admin/config/islandora_spreadsheet_ingest'
defaults:
_title: 'Islandora Spreadsheet Ingest'
_form: '\Drupal\islandora_spreadsheet_ingest\Form\Admin'
requirements:
_permission: 'administer islandora_spreadsheet_ingest requests'
options:
_admin_route: TRUE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ process:
- plugin: skip_on_empty
method: row
message: 'Field Digital_File is missing'
- plugin: file_is_accessible
_destination_filename:
- plugin: get
source: '@_file_defined'
Expand Down
60 changes: 58 additions & 2 deletions src/Controller/RequestListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@

namespace Drupal\islandora_spreadsheet_ingest\Controller;

use Drupal\Core\Link;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;

use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Request config entity list builder.
*/
class RequestListBuilder extends ConfigEntityListBuilder {

/**
* The migration group deriver service.
*
* @var \Drupal\islandora_spreadsheet_ingest\MigrationGroupDeriverInterface
*/
protected $migrationGroupDeriver;

/**
* {@inheritdoc}
*/
Expand All @@ -19,6 +30,7 @@ public function buildHeader() {
$header['label'] = $this->t('Request');
$header['id'] = $this->t('ID');
$header['active'] = $this->t('Active');
$header['migration_group'] = $this->t('Migration group');

return $header + parent::buildHeader();
}
Expand All @@ -27,11 +39,55 @@ public function buildHeader() {
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity->label();
$row['label'] = $entity->toLink(NULL, 'edit-form');
if (!$row['label']->getUrl()->access()) {
$row['label'] = $entity->label();
}
$row['id'] = $entity->id();
$row['active'] = $entity->getActive() ? $this->t('Active') : $this->t('Inactive');

$mg_name = $this->migrationGroupDeriver->deriveName($entity);
// XXX: The migration_group entity does not actually have this listed as one
// of its routes (it is instead on the "migration" entity for some reason...
// ... anyway... let's build out a link to it.
$mg_link = Link::createFromRoute(
$mg_name,
'entity.migration.list',
['migration_group' => $mg_name]
);
$activate_link = $entity->toLink($entity->getActive() ? $this->t('Active') : $this->t('Inactive'), 'activate-form');
$row['active'] = $activate_link->getUrl()->access() ?
$activate_link :
$activate_link->getText();
$row['migration_group'] = $entity->getActive() ?
($mg_link->getUrl()->access() ?
$mg_link :
$mg_link->getText()) :
'';

return $row + parent::buildRow($entity);
}

/**
* {@inheritdoc}
*/
public function getOperations(EntityInterface $entity) {
$ops = parent::getOperations($entity);

// Filter to only those operations to which the user has access.
return array_filter($ops, function ($op) {
return $op['url']->access();
});
}

/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
$instance = parent::createInstance($container, $entity_type);

$instance->migrationGroupDeriver = $container->get('islandora_spreadsheet_ingest.migration_group_deriver');

return $instance;
}

}
6 changes: 4 additions & 2 deletions src/Entity/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
* "edit" = "Drupal\islandora_spreadsheet_ingest\Form\Ingest\FileUpload",
* "map" = "Drupal\islandora_spreadsheet_ingest\Form\Ingest\Mapping",
* "view" = "Drupal\islandora_spreadsheet_ingest\Form\Ingest\Review",
* }
* },
* "access" = "Drupal\islandora_spreadsheet_ingest\RequestAccessControlHandler",
* "view_builder" = "Drupal\islandora_spreadsheet_ingest\RequestViewBuilder",
* },
* config_prefix = "request",
* admin_permission = "administer site configuration",
* admin_permission = "administer islandora_spreadsheet_ingest requests",
* entity_keys = {
* "id" = "id",
* "label" = "label",
Expand Down
96 changes: 96 additions & 0 deletions src/Form/Admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace Drupal\islandora_spreadsheet_ingest\Form;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Module settings form.
*/
class Admin extends ConfigFormBase {

/**
* The StreamWrapperManager.
*
* @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface
*/
protected $streamWrapperManager;

/**
* {@inheritdoc}
*/
public function __construct(ConfigFactoryInterface $config_factory, StreamWrapperManagerInterface $stream_wrapper_manager) {
parent::__construct($config_factory);
$this->streamWrapperManager = $stream_wrapper_manager;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('stream_wrapper_manager')
);
}

/**
* {@inheritdoc}
*/
public function getFormId() {
return 'islandora_spreadsheet_ingest_admin_settings_form';
}

/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = [];
$config = $this->config('islandora_spreadsheet_ingest.settings');
$current_whitelist = $config->get('binary_directory_whitelist');
$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),
];
$form['paths'] = [
'#type' => 'textarea',
'#title' => $this->t('Binary path whitelist'),
'#default_value' => $current_whitelist ? implode(',', $current_whitelist) : '',
'#description' => $this->t('A comma separated list of local locations from which spreadsheet ingests can use binaries.'),
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Save'),
];

return $form;
}

/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['islandora_spreadsheet_ingest.settings'];
}

/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('islandora_spreadsheet_ingest.settings');
$whitelist = explode(',', $form_state->getValue('paths'));
$config->set('binary_directory_whitelist', $whitelist);
$config->set('schemes', array_filter($form_state->getValue('schemes')));
$config->save();
parent::submitForm($form, $form_state);
}

}
2 changes: 1 addition & 1 deletion src/Form/Ingest/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public function save(array $form, FormStateInterface $form_state) {
try {
$request->save();

$form_state->setRedirect('entity.isi_request.map_form', [
$form_state->setRedirect('entity.isi_request.view', [
'isi_request' => $request->id(),
]);
}
Expand Down
13 changes: 9 additions & 4 deletions src/Form/Ingest/Mapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,19 @@ protected function mapMappings($entity_type, $entity, &$form, FormStateInterface
protected function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state);

$entity_validation = [
'::preValidateEntity',
'::validateEntity',
];

// Add the validation to the normal submit.
$actions['submit']['#validate'] = $entity_validation;

// Add "save and review" button or whatever.
$actions['save_and_review'] = [
'#type' => 'submit',
'#value' => $this->t('Save and proceed'),
'#validate' => [
'::preValidateEntity',
'::validateEntity',
],
'#validate' => $entity_validation,
'#submit' => array_merge(
$actions['submit']['#submit'],
[
Expand Down
7 changes: 5 additions & 2 deletions src/MigrationDeriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,12 @@ public function createAll(RequestInterface $request) {
'label' => $original_migration->label(),
'migration_group' => $mg_name,
'source' => [
/*
* XXX: Doesn't appear necessary to specify the columns?
/* XXX: Doesn't appear necessary to specify the columns?
* 'columns' => array_unique(iterator_to_array($this->getUsedColumns($info['mappings']))),
*
* @note: Constants and other things defined in the source on
* individual migrations will not be passed through. This is a design
* choice. If needed specify them on the group itself.
*/
],
'process' => iterator_to_array(
Expand Down
Loading

0 comments on commit 1a304e1

Please sign in to comment.