diff --git a/CHANGELOG.md b/CHANGELOG.md index 880c6b75..0221824f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] +- [PR-224](https://github.com/OS2Forms/os2forms/pull/224) + - Add permission for accessing actions and bulk operations in webform submission list - [PR-101](https://github.com/OS2Forms/os2forms/pull/101) - Added support for `os2web_key` in Digital post - Switched from saving settings in key value store to config, i.e diff --git a/modules/os2forms_webform_list/os2forms_webform_list.module b/modules/os2forms_webform_list/os2forms_webform_list.module index 958ff0c8..2f0aee78 100644 --- a/modules/os2forms_webform_list/os2forms_webform_list.module +++ b/modules/os2forms_webform_list/os2forms_webform_list.module @@ -14,5 +14,6 @@ function os2forms_webform_list_entity_type_alter(array &$entity_types) { /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */ // Define a new list builder classes. $entity_types['webform']->setListBuilderClass('Drupal\os2forms_webform_list\CustomWebformEntityListBuilder'); + $entity_types['webform_submission']->setListBuilderClass('Drupal\os2forms_webform_list\CustomWebformSubmissionListBuilder'); $entity_types['maestro_template']->setListBuilderClass('Drupal\os2forms_webform_list\CustomMaestroTemplateEntityListBuilder'); } diff --git a/modules/os2forms_webform_list/os2forms_webform_list.permissions.yml b/modules/os2forms_webform_list/os2forms_webform_list.permissions.yml new file mode 100644 index 00000000..c5855b74 --- /dev/null +++ b/modules/os2forms_webform_list/os2forms_webform_list.permissions.yml @@ -0,0 +1,3 @@ +'access webform submission list bulk operations and actions': + title: 'Access webform submission list bulk operations and actions' + description: 'Access webform submission list bulk operations and actions' diff --git a/modules/os2forms_webform_list/src/CustomWebformSubmissionListBuilder.php b/modules/os2forms_webform_list/src/CustomWebformSubmissionListBuilder.php new file mode 100644 index 00000000..2776088f --- /dev/null +++ b/modules/os2forms_webform_list/src/CustomWebformSubmissionListBuilder.php @@ -0,0 +1,100 @@ +account)) { + $build['filter_form'] = $this->buildFilterForm(); + } + + // Customize buttons. + if ($this->customize) { + $build['customize'] = $this->buildCustomizeButton(); + } + + // Display info. + if ($this->total) { + $build['info'] = $this->buildInfo(); + } + + // Table. + $build += EntityListBuilder::render(); + $build['table']['#sticky'] = TRUE; + $build['table']['#attributes']['class'][] = 'webform-results-table'; + + // Bulk operations only visible on webform submissions pages. + $webform_submission_bulk_form = $this->configFactory->get('webform.settings')->get('settings.webform_submission_bulk_form'); + if ($webform_submission_bulk_form + && !$this->account + && $this->webform + && $this->webform->access('submission_update_any') + && $this->currentUser->hasPermission('access webform submission list bulk operations and actions')) { + $build['table'] = \Drupal::formBuilder()->getForm('\Drupal\webform\Form\WebformSubmissionBulkForm', $build['table'], $this->webform->access('submission_delete_any')); + } + + // Must preload libraries required by (modal) dialogs. + // Must preload libraries required by (modal) dialogs. + WebformDialogHelper::attachLibraries($build); + + return $build; + } + + /** + * Add permissions check on operations. + * + * @return array + * A renderable array containing the entity list. + */ + public function getDefaultOperations(EntityInterface $entity): array { + if ($this->currentUser->hasPermission('access webform submission list bulk operations and actions')) { + return parent::getDefaultOperations($entity); + } + else { + $webform = $entity->getWebform(); + $operations = []; + + if ($entity->access('view')) { + $operations['view'] = [ + 'title' => $this->t('View'), + 'weight' => 20, + 'url' => $this->requestHandler->getUrl($entity, $this->sourceEntity, 'webform.user.submission'), + ]; + } + + if ($entity->access('view_any') + && $this->currentUser->hasPermission('access webform submission log') + && $webform->hasSubmissionLog() + && $this->moduleHandler->moduleExists('webform_submission_log')) { + $operations['log'] = [ + 'title' => $this->t('Log'), + 'weight' => 100, + 'url' => $this->requestHandler->getUrl($entity, $this->sourceEntity, 'webform_submission.log'), + ]; + } + + return $operations; + } + } + +}