Skip to content

Commit

Permalink
Handled anonymous users in notifications and flow tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi-itk committed Sep 14, 2023
1 parent 20d560e commit f45c9f1
Show file tree
Hide file tree
Showing 20 changed files with 1,717 additions and 401 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ before starting to add changes. Use example [placed in the end of the page](#exa

## [Unreleased]

- [#56](https://github.com/OS2Forms/os2forms/pull/56)
Handled anonymous users in notifications and flow tasks

## [3.10.0] 2023-08-23

- [OSF-55] DAWA Address-Matrikula (autocomplete) (required)
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"drupal/webform_validation": "^2.0",
"drupal/webform_views": "^5.0@alpha",
"drupal/workflow_participants": "^2.4",
"os2forms/os2forms_digital_post": "^3.0",
"os2web/os2web_datalookup": "^1.0",
"os2web/os2web_nemlogin": "^1.0",
"phpoffice/phpword": "^0.18.2",
Expand Down
12 changes: 8 additions & 4 deletions modules/os2forms_forloeb/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ All notable changes to this project should be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

See ["how do I make a good changelog record?"](https://keepachangelog.com/en/1.0.0/#how)
See ["how do I make a good changelog record?"](https://keepachangelog.com/en/1.0.0/#how)
before starting to add changes.

## [Unreleased]

- Implemented `hook_maestro_zero_user_notification` and added *Maestro
notification* handler for sending notifications via email or digital post.
- Cleaned up prefilling of forms in `MaestroWebformInheritTask`.

## 2.5.2 - 27.03.2023

### Updated
- Bumped drupal/ultimate_cron version fixing [Deprecated function: Implicit conversion from float-string](https://www.drupal.org/project/ultimate_cron/issues/3256142).
- Bumped drupal/ultimate_cron version fixing [Deprecated function: Implicit conversion from float-string](https://www.drupal.org/project/ultimate_cron/issues/3256142).

## 2.5.1 - 10.03.2023
- Added github action for checking changelog changes when creating pull requests
Expand All @@ -24,11 +28,11 @@ before starting to add changes.

## 2.5.0 - 11.10.2022

### Added
### Added
- retry task controller action
- Added support for inheriting values without creating a submission

## 2.4.0
## 2.4.0

### Added
- Github CI action for checking Drupal Coding standards with PHP Code Sniffer
Expand Down
52 changes: 49 additions & 3 deletions modules/os2forms_forloeb/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,56 @@
# OS2forms 2.1 med Forløb [![Build Status](https://app.travis-ci.com/OS2Forms/os2forms_forloeb.svg?branch=develop)](https://app.travis-ci.com/OS2Forms/os2forms_forloeb)

Adds a Maestro workflow engine and advanced workflow functionality to OS2forms.

## Installing OS2forms 2.1 med Forløb

This module requires the codebase from the [OS2forms core project](https://github.com/OS2Forms/os2forms8) installed per the documentation and by selecting the os2forms_forloeb_profile at installation. After succesful installation you should have the OS2forms med Forløb Module available for install via gui.

You can also install the module by using Drush:
```
./vendor/bin/drush en os2forms_forloeb
```

```
./vendor/bin/drush pm:enable os2forms_forloeb
```

-------------------------------------------------------------------------------

## Maestro notifications

Maestro 3.1 adds a `hook_webform_submission_form_alter` hook which we utilize to
send assignment, reminder and escalation notifications by adding a *Maestro
notification* handler to a form that spawns a Maestro workflow or assigns a
task. If the notification recipient is identified by an an email address, the
notification is sent as an email, and if the identifier is a Danish CPR number,
the notifications is sent as digital post.

See [Opret flow-notifikationer](https://os2forms.os2.eu/node/457) (in Danish)
for details.

### Settings

Settings for OS2Forms forløb are defined on `/admin/config/system/os2forms_forloeb`.

#### Known anonymous roles

In order to make the notifications work, Maestro workflow tasks must be assigned
to a *known anonymous role* and these roles are defined under *Known anonymous
roles*.

#### Processing

A notification is not sent to a user immediately, but added to a queue which
must be processed asynchronously. Specify the queue handling notification jobs.

#### Templates

Define templates for emails and digital post (PDF).

### Note on digital post

Digital post is sent using the API provided by the [OS2Forms Digital Post
module](https://github.com/itk-dev/os2forms_digital_post)
(`os2forms_digital_post`) which in turn uses [SF1600: Print på
serviceplatformen](https://digitaliseringskataloget.dk/integration/sf1600). Not
all OS2Forms projects use `os2forms_digital_post` and in the future we should
generalize the API for sending digital post to allow other implementations (not
based on [SF1600](https://digitaliseringskataloget.dk/integration/sf1600)).
6 changes: 4 additions & 2 deletions modules/os2forms_forloeb/os2forms_forloeb.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ name: 'OS2forms med Forløb Module'
description: 'Adds a Maestro workflow engine and advanced workflow functionality to OS2forms.'
package: OS2Forms
type: module
core: 8.x
core_version_requirement: ^8 || ^9
core_version_requirement: ^9 || ^10

configure: os2forms_forloeb.settings

dependencies:
- 'drupal:admin_toolbar_tools'
Expand Down Expand Up @@ -51,5 +52,6 @@ dependencies:
- 'drupal:webform_submission_log'
- 'drupal:webform_templates'
- 'drupal:workflow_participants'
- 'os2forms_digital_post:os2forms_digital_post'
'interface translation project': os2forms_forloeb
'interface translation server pattern': modules/contrib/os2forms_forloeb/translations/os2forms_forloeb.da.po
5 changes: 5 additions & 0 deletions modules/os2forms_forloeb/os2forms_forloeb.links.menu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
os2forms_forloeb.settings:
title: OS2Forms forløb
description: Configure the OS2Forms forløb module
parent: system.admin_config_system
route_name: os2forms_forloeb.settings
120 changes: 71 additions & 49 deletions modules/os2forms_forloeb/os2forms_forloeb.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@
* Install, update and uninstall functions for the os2forms_forloeb.
*/

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\maestro\Engine\MaestroEngine;
use Drupal\os2forms_forloeb\MaestroHelper;
use Drupal\os2forms_forloeb\Plugin\EngineTasks\MaestroWebformInheritTask;
use Drupal\user\Entity\User;
use Drupal\webform\Entity\WebformSubmission;
use Drupal\webform\WebformInterface;
use Drupal\webform\WebformSubmissionInterface;

/**
* Implements hook_maestro_interactive_handlers().
Expand Down Expand Up @@ -289,66 +284,93 @@ function os2forms_forloeb_preprocess_page(&$variables) {
}

/**
* Implements hook_token_info_alter().
* Implements hook_webform_submission_form_alter().
*/
function os2forms_forloeb_token_info_alter(&$data) {
$data['tokens']['webform_submission']['os2forms_forloeb_execute_task'] = [
'name' => t('Execute task path for webform submission'),
'description' => t("The token that can be user to get path for webform submission redirect URL."),
'type' => 'webform_submission',
];
function os2forms_forloeb_webform_submission_form_alter(array &$form, FormStateInterface $formState, string $formId) {
MaestroWebformInheritTask::webformSubmissionFormAlter($form, $formState, $formId);
}

/**
* Implements hook_maestro_zero_user_notification().
*/
function os2forms_forloeb_maestro_zero_user_notification($templateMachineName, $taskMachineName, $queueID, $notificationType) {
_os2forms_forloeb_helper()->maestroZeroUserNotification($templateMachineName, $taskMachineName, $queueID, $notificationType);
}

/**
* Implements hook_tokens().
* Implements hook_maestro_can_user_execute_task_alter().
*
* Provides token value for webform_submission:os2forms_forloeb_execute_task.
* For OS2Forms, you may have a consistent assignment to an "anonymous" user via
* a role. Use the QueueID and userID to drill into the task and alter the
* returnValue to TRUE if this is a user that should be looking at this task.
*
* You can make this as complex as you'd like it to be, checking things like
* sessions, login tokens, email addresses etc.
*/
function os2forms_forloeb_tokens($type, array $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
$replacements = [];

if ($type === 'webform_submission' && !empty($data['webform_submission']) && isset($tokens['os2forms_forloeb_execute_task'])) {
$replacements[$tokens['os2forms_forloeb_execute_task']] = Url::fromRoute(
'os2forms_forloeb.forloeb_task_console_controller_execute',
['os2forms-forloeb-ws-token' => $data['webform_submission']->getToken()],
['absolute' => TRUE]
)->toString(TRUE)->getGeneratedUrl();
}
function os2forms_forloeb_maestro_can_user_execute_task_alter(&$returnValue, $queueID, $userID) {
_os2forms_forloeb_helper()->maestroCanUserExecuteTaskAlter($returnValue, $queueID, $userID);
}

return $replacements;
/**
* Implements hook_mail().
*/
function os2forms_forloeb_mail($key, &$message, $params) {
_os2forms_forloeb_helper()->mail($key, $message, $params);
}

/**
* Implements hook_entity_access().
*
* Allows requests with tokens to view the entity.
* Implements hook_mail_alter().
*/
function os2forms_forloeb_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
if ($operation == 'update' && $entity instanceof WebformSubmission) {
$token = \Drupal::request()->query->get('os2forms-forloeb-ws-token');
if ($token && $token === $entity->getToken()) {
return AccessResult::allowed();
}
}
return AccessResult::neutral();
function os2forms_forloeb_mail_alter(&$message) {
_os2forms_forloeb_helper()->mailAlter($message);
}

/**
* Implements hook_maestro_post_fetch_assigned_queue_tasks().
* Implements hook_theme().
*/
function os2forms_forloeb_maestro_post_fetch_assigned_queue_tasks($userID, &$queueIDs) {
$token = \Drupal::request()->query->get('os2forms-forloeb-ws-token', '');
if ($token) {
$forloebTaskConsole = Drupal::service('os2forms_forloeb.task_console');
$queueRecord = $forloebTaskConsole->getQueueIdByWebformSubmissionToken($token);
$queueIDs[] = $queueRecord->id();
$queueIDs = array_unique($queueIDs);
}
function os2forms_forloeb_theme(array &$variables) {
$theme['os2forms_forloeb_notification_preview'] = [
'variables' => [
'webform' => NULL,
'handler' => NULL,
'notification_type' => NULL,
'subject' => NULL,
'recipient' => NULL,
'content_type' => NULL,
'submission' => NULL,
'return_url' => NULL,
'render_url' => NULL,
'preview_urls' => [
'prev' => NULL,
'self' => NULL,
'next' => NULL,
],
],
];

$theme['os2forms_forloeb_notification_message_email_html'] = [
'variables' => [
'message' => [
'content' => [
'value' => NULL,
'format' => NULL,
],
],
'task_url' => NULL,
'action_label' => NULL,
'webform_submission' => NULL,
'handler' => NULL,
],
];

$theme['os2forms_forloeb_notification_message_pdf_html'] = $theme['os2forms_forloeb_notification_message_email_html'];

return $theme;
}

/**
* Implements hook_ENTITY_TYPE_prepare_form().
* Get MaestroHelper.
*/
function os2forms_forloeb_webform_submission_prepare_form(WebformSubmissionInterface $webform_submission, string $operation, FormStateInterface $form_state) {
MaestroWebformInheritTask::webformSubmissionPrepareForm($webform_submission, $operation, $form_state);
function _os2forms_forloeb_helper(): MaestroHelper {
return Drupal::service(MaestroHelper::class);
}
49 changes: 36 additions & 13 deletions modules/os2forms_forloeb/os2forms_forloeb.routing.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
os2forms_forloeb.forloeb_task_console_controller_execute:
path: 'os2forms-forloeb/execute-task'
os2forms_forloeb.settings:
path: '/admin/config/system/os2forms_forloeb'
defaults:
_controller: '\Drupal\os2forms_forloeb\Controller\ForloebTaskConsoleController::execute'
_title: 'Execute task'
_form: '\Drupal\os2forms_forloeb\Form\SettingsForm'
_title: 'OS2Forms forløb'
requirements:
_permission: 'access content'
options:
no_cache: TRUE
_permission: 'administer site configuration'

os2forms_forloeb.forloeb_task_console_controller_execute_retry:
path: 'os2forms-forloeb/execute-task-retry'
os2forms_forloeb.meastro_notification.preview:
path: '/admin/structure/webform/manage/{webform}/os2forms_forloeb/notification/{handler}/preview/{notification_type}/{content_type}'
defaults:
_controller: '\Drupal\os2forms_forloeb\Controller\ForloebTaskConsoleController::retry'
_title: 'Task not yet ready'
_controller: '\Drupal\os2forms_forloeb\Controller\MaestroNotificationController::preview'
_title: 'Maestro notification preview'
notification_type: assignment
options:
parameters:
webform:
type: 'entity:webform'
requirements:
_permission: 'access content'
_permission: 'view any webform submission'

os2forms_forloeb.meastro_notification.preview_render:
path: '/admin/structure/webform/manage/{webform}/os2forms_forloeb/notification/{handler}/preview/{notification_type}/{content_type}/render/{submission}'
defaults:
_controller: '\Drupal\os2forms_forloeb\Controller\MaestroNotificationController::previewRender'
_title: 'Maestro notification render preview'
options:
no_cache: TRUE
parameters:
webform:
type: 'entity:webform'
submission:
type: 'entity:webform_submission'
requirements:
_permission: 'view any webform submission'

os2forms_forloeb.meastro_notification.preview_message:
path: '/os2forms_forloeb/notification/message'
defaults:
_controller: '\Drupal\os2forms_forloeb\Controller\MaestroNotificationController::message'
_title: 'Maestro notification message'
requirements:
_permission: 'view any webform submission'
21 changes: 18 additions & 3 deletions modules/os2forms_forloeb/os2forms_forloeb.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ services:
logger.channel.os2forms_forloeb:
parent: logger.channel_base
arguments: ['os2forms_forloeb']
os2forms_forloeb.task_console:
class: Drupal\os2forms_forloeb\ForloebTaskConsole
arguments: ['@entity_type.manager', '@logger.channel.os2forms_forloeb']

logger.channel.os2forms_forloeb_submission:
parent: logger.channel_base
arguments: ['webform_submission']

Drupal\os2forms_forloeb\MaestroHelper:
arguments:
- '@entity_type.manager'
- '@config.factory'
- '@webform.token_manager'
- '@plugin.manager.mail'
- '@language_manager'
- '@webform.theme_manager'
- '@logger.channel.os2forms_forloeb'
- '@logger.channel.os2forms_forloeb_submission'
- '@module_handler'
- '@plugin.manager.entity_print.print_engine'
- '@Drupal\os2forms_digital_post\Helper\DigitalPostHelper'
Loading

0 comments on commit f45c9f1

Please sign in to comment.