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

Handle anonymous users in notifications and flow tasks #56

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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa
- [OS-58] New company address fields
- Custom permissions by term field
- Removing dependency to config_entity_revisions, webform_revisions, coc_forms_auto_export
- [PR-56](https://github.com/OS2Forms/os2forms/pull/56)
Handled anonymous users in notifications and flow tasks

## [3.10.0] 2023-08-23

Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"cweagans/composer-patches": "^1.6.5",
"dompdf/dompdf": "^2.0",
"drupal/admin_toolbar": "^3.0",
"drupal/advancedqueue": "^1.0",
"drupal/chosen": "^2.10",
"drupal/ckeditor_a11ychecker": "^2.0@alpha",
"drupal/clientside_validation": "^3.0",
Expand All @@ -39,7 +40,7 @@
"drupal/libraries": "^3.0@beta",
"drupal/linkit": "^5.0",
"drupal/logging_alerts": "^2.0",
"drupal/maestro": "^3.0",
"drupal/maestro": "^3.1",
"drupal/mailsystem": "^4.1",
"drupal/masquerade": "^2.0@RC",
"drupal/pathauto": "^1.5",
Expand Down Expand Up @@ -74,6 +75,9 @@
"webmozart/path-util": "^2.3",
"zaporylie/composer-drupal-optimizations": "^1.2"
},
"suggest": {
"os2forms/os2forms_digital_post": "Send Maestro notifications via digital post (see https://github.com/itk-dev/os2forms_digital_post/blob/main/README.md)"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
"drupal/coder": "^8.3",
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)).
17 changes: 11 additions & 6 deletions modules/os2forms_forloeb/os2forms_forloeb.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ 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'
- 'drupal:advancedqueue'
- 'drupal:diff'
- 'drupal:entity_print'
- 'drupal:eu_cookie_compliance'
Expand All @@ -18,20 +20,19 @@ dependencies:
- 'drupal:mailsystem'
- 'drupal:masquerade'
- 'drupal:os2forms'
- 'drupal:os2forms_nemid'
- 'drupal:os2forms_dawa'
- 'drupal:os2forms_nemid'
- 'drupal:os2forms_sbsys'
- 'drupal:os2web_simplesaml'
- 'drupal:pathauto'
- 'drupal:r4032login'
- 'drupal:redirect'
- 'drupal:smtp'
- 'drupal:system'
- 'drupal:switch_page_theme'
- 'drupal:system'
- 'drupal:token'
- 'drupal:ultimate_cron'
- 'drupal:webform'
- 'drupal:webform_ui'
- 'drupal:webform_access'
- 'drupal:webform_attachment'
- 'drupal:webform_composite'
Expand All @@ -42,11 +43,15 @@ dependencies:
- 'drupal:webform_node_element'
- 'drupal:webform_remote_handlers'
- 'drupal:webform_rest'
- 'drupal:webform_share'
- 'drupal:webform_scheduled_email'
- 'drupal:webform_share'
- 'drupal:webform_submission_export_import'
- 'drupal:webform_submission_log'
- 'drupal:webform_templates'
- 'drupal:webform_ui'
- 'drupal:workflow_participants'
# os2forms_digital_post may be used for sending Meastro notifications via digital post
# - '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);
}
Loading
Loading