From 0f4e07c00befceb043971428979eb636fe7c2098 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Thu, 21 Mar 2024 15:25:31 +0100 Subject: [PATCH 01/33] #867: Allow denying address protected citizen from webform --- CHANGELOG.md | 2 +- modules/os2forms_nemid/README.md | 1 + modules/os2forms_nemid/os2forms_nemid.module | 80 +++++++++++++++++ .../os2forms_nemid.services.yml | 2 +- .../src/Service/FormsHelper.php | 85 ++++++++++++++++++- 5 files changed, 167 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7ab53db..c3ce1310 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,10 +12,10 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] - Adding Lat and Long fetching to DataAddress - - CprFetchData adding ajax error fix - [#84](https://github.com/OS2Forms/os2forms/pull/84) Added digital post test command. +- Allow denying address protected citizen from webform. ## [3.14.0] diff --git a/modules/os2forms_nemid/README.md b/modules/os2forms_nemid/README.md index 6f67a0e9..d9f5e4e8 100644 --- a/modules/os2forms_nemid/README.md +++ b/modules/os2forms_nemid/README.md @@ -14,6 +14,7 @@ Besides this module adds a special settings to the Third Party Webform settings: - Webform type - Redirect to nemlogin automatically +- Settings: admin/structure/webform/manage/[webform]/settings diff --git a/modules/os2forms_nemid/os2forms_nemid.module b/modules/os2forms_nemid/os2forms_nemid.module index cd86dc49..39520843 100644 --- a/modules/os2forms_nemid/os2forms_nemid.module +++ b/modules/os2forms_nemid/os2forms_nemid.module @@ -11,6 +11,9 @@ use Drupal\migrate\Plugin\MigrateSourceInterface; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Row; use Drupal\os2forms_nemid\Plugin\WebformElement\NemidElementBase; +use Drupal\os2forms_nemid\Service\FormsHelper; +use Drupal\webform\Utility\WebformFormHelper; +use Drupal\webform\WebformSubmissionInterface; /** * Implements hook_form_FORM_ID_alter(). @@ -21,6 +24,15 @@ function os2forms_nemid_form_webform_os2forms_settings_form_alter(&$form, FormSt os2forms_nemid_webform_third_party_settings_form_alter($form, $form_state); } +/** + * Implements hook_ENTITY_TYPE_prepare_form(). + * + * Prepare webform. + */ +function os2forms_nemid_webform_submission_prepare_form(WebformSubmissionInterface $webform_submission, string $operation, FormStateInterface $form_state): void { + Drupal::service('os2forms_nemid.forms_helper')->webformSubmissionPrepareForm($webform_submission, $operation, $form_state); +} + /** * Implements hook_webform_third_party_settings_form_alter(). */ @@ -71,12 +83,80 @@ function os2forms_nemid_webform_third_party_settings_form_alter(&$form, FormStat '#default_value' => !(empty($settings)) ? $settings['nemlogin_auto_redirect'] : FALSE, '#description' => t('Redirection will happen right after user has is accessing the form, if user is already authenticated via NemID, redirection will not happen.'), ]; + + + $nemloginProtectionSettings = $webform->getThirdPartySetting('os2forms', 'os2forms_nemid_address_protection'); + + // OS2Forms NemID. + $form['third_party_settings']['os2forms']['os2forms_nemid_address_protection'] = [ + '#type' => 'details', + '#title' => t('OS2Forms address protection settings'), + '#open' => TRUE, + ]; + + + // Nemlogin auto redirect. + $form['third_party_settings']['os2forms']['os2forms_nemid_address_protection']['nemlogin_hide_form'] = [ + '#type' => 'select', + '#options' => [ + FormsHelper::WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_DEFAULT_BEHAVIOUR => t('No'), + FormsHelper::WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_DISPLAY_ERROR => t('Yes'), + ], + '#title' => t('Hide form if user is under protection'), + '#default_value' => !(empty($nemloginProtectionSettings)) ? $nemloginProtectionSettings['nemlogin_hide_form'] : FormsHelper::WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_DEFAULT_BEHAVIOUR, + '#description' => t('Hides elements and displays error if nemlogin reveals that citizen is under address protection and an address element is found on the webform'), + ]; + + // Nemlogin address protection. + $form['third_party_settings']['os2forms']['os2forms_nemid_address_protection']['nemlogin_hide_message'] = [ + '#title' => t('Hide message'), + '#type' => 'textarea', + '#default_value' => !(empty($nemloginProtectionSettings)) ? $nemloginProtectionSettings['nemlogin_hide_message'] : '', + '#description' => t('Message shown to user when visiting form'), + '#states' => [ + 'visible' => [ + [':input[name="third_party_settings[os2forms][os2forms_nemid_address_protection][nemlogin_hide_form]"]' => ['value' => FormsHelper::WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_DISPLAY_ERROR]], + ], + 'required' => [ + [':input[name="third_party_settings[os2forms][os2forms_nemid_address_protection][nemlogin_hide_form]"]' => ['value' => FormsHelper::WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_DISPLAY_ERROR]], + ] + ], + ]; } /** * Implements hook_webform_submission_form_alter(). */ function os2forms_nemid_webform_submission_form_alter(array &$form, FormStateInterface $form_state, $form_id) { + + // Handle address protection + if ($tempValue = $form_state->getTemporaryValue(FormsHelper::TEMPORARY_KEY)) { + if (FALSE === ($tempValue['access'] ?? TRUE)) { + // Flattening the elements makes it much easier to access nested elements. + $elements = &WebformFormHelper::flattenElements($form['elements']); + + \Drupal::messenger()->addError(t('Access to form denied')); + + if (isset($tempValue['message'])) { + $form['os2forms_nemlogin_message'] = [ + '#theme' => 'status_messages', + '#message_list' => [ + 'error' => [$tempValue['message']], + ], + ]; + } + + // Hide all actions …. + $form['actions']['#access'] = FALSE; + // … and elements. + foreach ($elements as &$element) { + $element['#access'] = FALSE; + } + } + + return; + } + // Getting webform Nemid settings. /** @var \Drupal\webform\WebformSubmissionInterface Interface $webformSubmission */ $webformSubmission = $form_state->getFormObject()->getEntity(); diff --git a/modules/os2forms_nemid/os2forms_nemid.services.yml b/modules/os2forms_nemid/os2forms_nemid.services.yml index 61f67993..5e159bbc 100644 --- a/modules/os2forms_nemid/os2forms_nemid.services.yml +++ b/modules/os2forms_nemid/os2forms_nemid.services.yml @@ -6,4 +6,4 @@ services: - {name: event_subscriber} os2forms_nemid.forms_helper: class: Drupal\os2forms_nemid\Service\FormsHelper - arguments: ['@os2web_nemlogin.auth_provider', '@plugin.manager.os2web_datalookup'] + arguments: ['@os2web_nemlogin.auth_provider', '@plugin.manager.os2web_datalookup', '@current_route_match'] diff --git a/modules/os2forms_nemid/src/Service/FormsHelper.php b/modules/os2forms_nemid/src/Service/FormsHelper.php index e271d552..b7b21d18 100644 --- a/modules/os2forms_nemid/src/Service/FormsHelper.php +++ b/modules/os2forms_nemid/src/Service/FormsHelper.php @@ -4,6 +4,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Routing\RouteMatchInterface; use Drupal\os2forms_nemid\Element\NemidCompanyCvrFetchData; use Drupal\os2forms_nemid\Element\NemidCompanyPNumber; use Drupal\os2forms_nemid\Element\NemidCprFetchData; @@ -11,6 +12,7 @@ use Drupal\os2web_datalookup\LookupResult\CprLookupResult; use Drupal\os2web_datalookup\Plugin\DataLookupManager; use Drupal\os2web_nemlogin\Service\AuthProviderService; +use Drupal\webform\WebformSubmissionInterface; /** * FormsHelper. @@ -20,6 +22,32 @@ * @package Drupal\os2forms_nemid\Service */ class FormsHelper { + const TEMPORARY_KEY = 'os2forms_nemlogin_address_protection'; + + /** + * Defines NemID login address protection display error option. + */ + const WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_DISPLAY_ERROR = 'os2forms_nemlogin_address_protection_display_error'; + + /** + * Defines NemID login address protection display default behaviour. + */ + const WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_DEFAULT_BEHAVIOUR = 'os2forms_nemlogin_address_protection_default_behaviour'; + + /** + * Defines NemID login address related elements. + */ + private const WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_ELEMENT_TYPES = [ + 'os2forms_nemid_address', + 'os2forms_nemid_street', + 'os2forms_nemid_house_nr', + 'os2forms_nemid_floor', + 'os2forms_nemid_apartment_nr', + 'os2forms_nemid_postal_code', + 'os2forms_nemid_city', + 'os2forms_nemid_kommunekode', + 'os2forms_nemid_coaddress' + ]; /** * Auth provider service. @@ -35,6 +63,13 @@ class FormsHelper { */ private $dataLookManager; + /** + * The route match. + * + * @var \Drupal\Core\Routing\RouteMatchInterface + */ + private RouteMatchInterface $routeMatch; + /** * Constructor. * @@ -43,9 +78,10 @@ class FormsHelper { * @param \Drupal\os2web_datalookup\Plugin\DataLookupManager $dataLookPluginManager * Datalookup plugin manager. */ - public function __construct(AuthProviderService $authProviderService, DataLookupManager $dataLookPluginManager) { + public function __construct(AuthProviderService $authProviderService, DataLookupManager $dataLookPluginManager, RouteMatchInterface $routeMatch) { $this->authProviderService = $authProviderService; $this->dataLookManager = $dataLookPluginManager; + $this->routeMatch = $routeMatch; } /** @@ -307,4 +343,51 @@ protected function getDataFetchTriggerValue($dataFetchValueFieldName, FormStateI return $value; } + /** + * Implements hook_ENTITY_TYPE_prepare_form(). + */ + public function webformSubmissionPrepareForm(WebformSubmissionInterface $webformSubmission, string $operation, FormStateInterface $formState): void { + // Only perform address protection check when displaying submission form. + $accessCheckRouteNames = [ + // Webform attached to a node. + 'entity.node.canonical', + // Creating a new submission. + 'entity.webform.canonical', + // Editing a submission. + 'entity.webform_submission.edit_form', + ]; + + if (!in_array($this->routeMatch->getRouteName(), $accessCheckRouteNames, TRUE)) { + return; + } + + // Check if hide address protection is selected + $hideForm = $webformSubmission->getWebform()->getThirdPartySettings('os2forms')['os2forms_nemid_address_protection']['nemlogin_hide_form'] ?? NULL; + + if ($hideForm === self::WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_DISPLAY_ERROR) { + $cprResult = $this->retrieveCprLookupResult($formState); + + if ($cprResult && $cprResult->isNameAddressProtected()) { + + // Check if any element violating address protection is present in webform. + $elements = $webformSubmission->getWebform()->getElementsDecodedAndFlattened(); + + foreach ($elements as $element) { + + if(in_array($element['#type'], self::WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_ELEMENT_TYPES)) { + + // Violation detected, mark form state with temporary key and return. + $message = $webformSubmission->getWebform()->getThirdPartySettings('os2forms')['os2forms_nemid_address_protection']['nemlogin_hide_message']; + + $formState->setTemporaryValue(self::TEMPORARY_KEY, [ + 'access' => FALSE, + 'message' => $message + ]); + + return; + } + } + } + } + } } From 49c1565d857307dfbe13701d8d32f1957e9a919f Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Thu, 21 Mar 2024 15:37:41 +0100 Subject: [PATCH 02/33] #867: Applied coding standards --- modules/os2forms_nemid/os2forms_nemid.module | 6 ++---- .../src/Service/FormsHelper.php | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/modules/os2forms_nemid/os2forms_nemid.module b/modules/os2forms_nemid/os2forms_nemid.module index 39520843..84d8477f 100644 --- a/modules/os2forms_nemid/os2forms_nemid.module +++ b/modules/os2forms_nemid/os2forms_nemid.module @@ -84,7 +84,6 @@ function os2forms_nemid_webform_third_party_settings_form_alter(&$form, FormStat '#description' => t('Redirection will happen right after user has is accessing the form, if user is already authenticated via NemID, redirection will not happen.'), ]; - $nemloginProtectionSettings = $webform->getThirdPartySetting('os2forms', 'os2forms_nemid_address_protection'); // OS2Forms NemID. @@ -94,7 +93,6 @@ function os2forms_nemid_webform_third_party_settings_form_alter(&$form, FormStat '#open' => TRUE, ]; - // Nemlogin auto redirect. $form['third_party_settings']['os2forms']['os2forms_nemid_address_protection']['nemlogin_hide_form'] = [ '#type' => 'select', @@ -119,7 +117,7 @@ function os2forms_nemid_webform_third_party_settings_form_alter(&$form, FormStat ], 'required' => [ [':input[name="third_party_settings[os2forms][os2forms_nemid_address_protection][nemlogin_hide_form]"]' => ['value' => FormsHelper::WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_DISPLAY_ERROR]], - ] + ], ], ]; } @@ -129,7 +127,7 @@ function os2forms_nemid_webform_third_party_settings_form_alter(&$form, FormStat */ function os2forms_nemid_webform_submission_form_alter(array &$form, FormStateInterface $form_state, $form_id) { - // Handle address protection + // Handle address protection. if ($tempValue = $form_state->getTemporaryValue(FormsHelper::TEMPORARY_KEY)) { if (FALSE === ($tempValue['access'] ?? TRUE)) { // Flattening the elements makes it much easier to access nested elements. diff --git a/modules/os2forms_nemid/src/Service/FormsHelper.php b/modules/os2forms_nemid/src/Service/FormsHelper.php index b7b21d18..d67723e8 100644 --- a/modules/os2forms_nemid/src/Service/FormsHelper.php +++ b/modules/os2forms_nemid/src/Service/FormsHelper.php @@ -46,7 +46,7 @@ class FormsHelper { 'os2forms_nemid_postal_code', 'os2forms_nemid_city', 'os2forms_nemid_kommunekode', - 'os2forms_nemid_coaddress' + 'os2forms_nemid_coaddress', ]; /** @@ -77,6 +77,8 @@ class FormsHelper { * Auth provider service. * @param \Drupal\os2web_datalookup\Plugin\DataLookupManager $dataLookPluginManager * Datalookup plugin manager. + * @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch + * Route match service. */ public function __construct(AuthProviderService $authProviderService, DataLookupManager $dataLookPluginManager, RouteMatchInterface $routeMatch) { $this->authProviderService = $authProviderService; @@ -361,7 +363,7 @@ public function webformSubmissionPrepareForm(WebformSubmissionInterface $webform return; } - // Check if hide address protection is selected + // Check if hide address protection is selected. $hideForm = $webformSubmission->getWebform()->getThirdPartySettings('os2forms')['os2forms_nemid_address_protection']['nemlogin_hide_form'] ?? NULL; if ($hideForm === self::WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_DISPLAY_ERROR) { @@ -369,19 +371,21 @@ public function webformSubmissionPrepareForm(WebformSubmissionInterface $webform if ($cprResult && $cprResult->isNameAddressProtected()) { - // Check if any element violating address protection is present in webform. - $elements = $webformSubmission->getWebform()->getElementsDecodedAndFlattened(); + // Check if any element violating address + // protection is present in webform. + $elements = $webformSubmission->getWebform()->getElementsDecodedAndFlattened(); foreach ($elements as $element) { - if(in_array($element['#type'], self::WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_ELEMENT_TYPES)) { + if (in_array($element['#type'], self::WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_ELEMENT_TYPES)) { - // Violation detected, mark form state with temporary key and return. + // Violation detected, + // mark form state with temporary key and return. $message = $webformSubmission->getWebform()->getThirdPartySettings('os2forms')['os2forms_nemid_address_protection']['nemlogin_hide_message']; $formState->setTemporaryValue(self::TEMPORARY_KEY, [ 'access' => FALSE, - 'message' => $message + 'message' => $message, ]); return; @@ -390,4 +394,5 @@ public function webformSubmissionPrepareForm(WebformSubmissionInterface $webform } } } + } From c64a39bad7a597ffd3a1c5773c6a691681f882f0 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 27 Mar 2024 13:26:53 +0100 Subject: [PATCH 03/33] #1039: Added base_url variable to maestro notification twig --- modules/os2forms_forloeb/src/MaestroHelper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/os2forms_forloeb/src/MaestroHelper.php b/modules/os2forms_forloeb/src/MaestroHelper.php index dfa65cae..c4d23b62 100644 --- a/modules/os2forms_forloeb/src/MaestroHelper.php +++ b/modules/os2forms_forloeb/src/MaestroHelper.php @@ -17,6 +17,7 @@ use Drupal\Core\Logger\LoggerChannelInterface; use Drupal\Core\Mail\MailManagerInterface; use Drupal\Core\Render\Markup; +use Drupal\Core\Site\Settings; use Drupal\Core\Url; use Drupal\entity_print\Plugin\EntityPrintPluginManagerInterface; use Drupal\maestro\Engine\MaestroEngine; @@ -615,6 +616,7 @@ private function renderHtml( 'action_label' => $actionLabel, 'webform_submission' => $submission, 'handler' => $this, + 'base_url' => Settings::get('base_url') ], ]; From 4d42d3bd88876558d05d48e384480d47ac56ae6a Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 27 Mar 2024 13:29:00 +0100 Subject: [PATCH 04/33] #1039: Updated CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1764f85..c69e495e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa - Adding Lat and Long fetching to DataAddress - [#84](https://github.com/OS2Forms/os2forms/pull/84) Added digital post test command. +- [#95](https://github.com/OS2Forms/os2forms/pull/95) + Added `base_url` variable to Maestro notification twig. ## [3.14.1] 2024-01-16 From 9186e26360bddee26535a224bacdf5729dd1e79e Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 27 Mar 2024 13:42:51 +0100 Subject: [PATCH 05/33] #1039: Applied coding standards --- modules/os2forms_forloeb/src/MaestroHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/os2forms_forloeb/src/MaestroHelper.php b/modules/os2forms_forloeb/src/MaestroHelper.php index c4d23b62..1f6b12bb 100644 --- a/modules/os2forms_forloeb/src/MaestroHelper.php +++ b/modules/os2forms_forloeb/src/MaestroHelper.php @@ -616,7 +616,7 @@ private function renderHtml( 'action_label' => $actionLabel, 'webform_submission' => $submission, 'handler' => $this, - 'base_url' => Settings::get('base_url') + 'base_url' => Settings::get('base_url'), ], ]; From f96b25fe60a2b205b4cb644063adf5fde588da9f Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 27 Mar 2024 14:22:00 +0100 Subject: [PATCH 06/33] #1039: Added base_url variable to twig variables --- CHANGELOG.md | 2 +- modules/os2forms_attachment/os2forms_attachment.module | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c69e495e..9a38c035 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ before starting to add changes. Use example [placed in the end of the page](#exa - [#84](https://github.com/OS2Forms/os2forms/pull/84) Added digital post test command. - [#95](https://github.com/OS2Forms/os2forms/pull/95) - Added `base_url` variable to Maestro notification twig. + Added `base_url` variable to twig templates. ## [3.14.1] 2024-01-16 diff --git a/modules/os2forms_attachment/os2forms_attachment.module b/modules/os2forms_attachment/os2forms_attachment.module index 9f8892c9..86f313a9 100644 --- a/modules/os2forms_attachment/os2forms_attachment.module +++ b/modules/os2forms_attachment/os2forms_attachment.module @@ -8,6 +8,7 @@ use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Site\Settings; use Drupal\os2forms_attachment\Entity\AttachmentComponent; /** @@ -317,3 +318,12 @@ function os2forms_attachment_module_implements_alter(&$implementations, $hook) { } } + +/** + * Implements hook_preprocess(). + * + * Add 'base_url' variable to be used by templates. + */ +function os2forms_attachment_preprocess(&$vars) { + $vars['base_url'] = Settings::get('base_url'); +} From 645154c3bbf94cacd70a8b1608b4cb878a2b723a Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 27 Mar 2024 14:36:18 +0100 Subject: [PATCH 07/33] #867: Update README --- modules/os2forms_nemid/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/os2forms_nemid/README.md b/modules/os2forms_nemid/README.md index d9f5e4e8..98ec5532 100644 --- a/modules/os2forms_nemid/README.md +++ b/modules/os2forms_nemid/README.md @@ -14,7 +14,7 @@ Besides this module adds a special settings to the Third Party Webform settings: - Webform type - Redirect to nemlogin automatically -- +- Hide form if under address protection Settings: admin/structure/webform/manage/[webform]/settings From f15c90eb0410396584082b20e9cc41734777e707 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 27 Mar 2024 16:04:11 +0100 Subject: [PATCH 08/33] #1039: Tokenize all notification html --- .../os2forms_forloeb/src/MaestroHelper.php | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/modules/os2forms_forloeb/src/MaestroHelper.php b/modules/os2forms_forloeb/src/MaestroHelper.php index 1f6b12bb..feb8c791 100644 --- a/modules/os2forms_forloeb/src/MaestroHelper.php +++ b/modules/os2forms_forloeb/src/MaestroHelper.php @@ -506,7 +506,7 @@ public function renderNotification(WebformSubmissionInterface $submission, strin $processValue = static function (string $value) use ($taskUrl) { // Replace href="[maestro:task-url]" with href="«$taskUrl»". $value = preg_replace('/href\s*=\s*["\']\[maestro:task-url\]["\']/', sprintf('href="%s"', htmlspecialchars($taskUrl)), $value); - $value = preg_replace('/\[(maestro:[^]]+)\]/', '[\1]', $value); + $value = preg_replace('/\[(maestro:[^]]+)\]/', '(\1)', $value); return $value; }; @@ -523,12 +523,7 @@ public function renderNotification(WebformSubmissionInterface $submission, strin $content = $notificationSetting[MaestroNotificationHandler::NOTIFICATION_CONTENT]; if (isset($content['value'])) { - // Process tokens in content. - $content['value'] = $this->tokenManager->replace( - $processValue($content['value']), - $submission, - $maestroTokenData - ); + $content['value'] = $processValue($content['value']); } $actionLabel = $this->tokenManager->replace($notificationSetting[MaestroNotificationHandler::NOTIFICATION_ACTION_LABEL], $submission); @@ -539,11 +534,11 @@ public function renderNotification(WebformSubmissionInterface $submission, strin switch ($contentType) { case 'email': - $content = $this->renderHtml($contentType, $subject, $content, $taskUrl, $actionLabel, $submission); + $content = $this->renderHtml($contentType, $subject, $content, $taskUrl, $actionLabel, $submission, $maestroTokenData); break; case 'pdf': - $pdfContent = $this->renderHtml($contentType, $subject, $content, $taskUrl, $actionLabel, $submission); + $pdfContent = $this->renderHtml($contentType, $subject, $content, $taskUrl, $actionLabel, $submission, $maestroTokenData); // Get dompdf plugin from entity_print module. /** @var \Drupal\entity_print\Plugin\EntityPrint\PrintEngine\PdfEngineBase $printer */ @@ -584,6 +579,8 @@ public function renderNotification(WebformSubmissionInterface $submission, strin * The action label. * @param \Drupal\webform\WebformSubmissionInterface $submission * The webform submission. + * @param array $maestroTokenData + * The Maestro token data. * * @return string|MarkupInterface * The rendered content. @@ -594,7 +591,8 @@ private function renderHtml( array $content, string $taskUrl, string $actionLabel, - WebformSubmissionInterface $submission + WebformSubmissionInterface $submission, + array $maestroTokenData, ): string|MarkupInterface { $template = $this->config->get('templates')['notification_' . $type] ?? NULL; if (file_exists($template)) { @@ -620,7 +618,16 @@ private function renderHtml( ], ]; - return Markup::create(trim((string) $this->webformThemeManager->renderPlain($build))); + + $html = trim((string) $this->webformThemeManager->renderPlain($build)); + + $html = $this->tokenManager->replace( + $html, + $submission, + $maestroTokenData + ); + + return Markup::create($html); } /** From e5fc11a5f7eea6d28522c4ec1195a9f345c0555d Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 27 Mar 2024 16:06:05 +0100 Subject: [PATCH 09/33] #1039: Applied coding standards --- modules/os2forms_forloeb/src/MaestroHelper.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/os2forms_forloeb/src/MaestroHelper.php b/modules/os2forms_forloeb/src/MaestroHelper.php index feb8c791..8f8e24a9 100644 --- a/modules/os2forms_forloeb/src/MaestroHelper.php +++ b/modules/os2forms_forloeb/src/MaestroHelper.php @@ -618,7 +618,6 @@ private function renderHtml( ], ]; - $html = trim((string) $this->webformThemeManager->renderPlain($build)); $html = $this->tokenManager->replace( From b815d6279dff3a3e6d564d9eab6b5265ee7b7ca1 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Tue, 2 Apr 2024 09:48:53 +0200 Subject: [PATCH 10/33] #1039: Cleanup --- CHANGELOG.md | 3 ++- modules/os2forms_attachment/README.md | 20 +++++++++++++++++++ modules/os2forms_forloeb/README.md | 18 ++++++++++++++++- .../os2forms_forloeb/src/MaestroHelper.php | 6 ++---- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a38c035..16547769 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa - [#84](https://github.com/OS2Forms/os2forms/pull/84) Added digital post test command. - [#95](https://github.com/OS2Forms/os2forms/pull/95) - Added `base_url` variable to twig templates. + - Added `base_url` variable to twig templates. + - Tokenized all Maestro notification html. ## [3.14.1] 2024-01-16 diff --git a/modules/os2forms_attachment/README.md b/modules/os2forms_attachment/README.md index 09ff6cf1..3dfea56d 100644 --- a/modules/os2forms_attachment/README.md +++ b/modules/os2forms_attachment/README.md @@ -13,3 +13,23 @@ To add custom headers/footer ```admin/structure/webform/config/os2forms_attachme To specify headers/footers that will override the default ones on a global level (**Third party settings** -> **Entity print** section): ```admin/structure/webform/config``` To specify headers/footers that will override the default ones on a form level (**Third party settings** -> **Entity print** section): ```/admin/structure/webform/manage/[webform]/settings``` + + +# Overwriting templates + +With some setups it might be necessary to overwrite templates +in order to access stylesheets. + +For this reason the `base_url` variable has been added for use in templates. +Set it in `settings.local.php` + +```php +/** + * Base url. + * + * Used to specify full path to stylesheets in templates. + */ +$settings['base_url'] = 'http://nginx:8080'; +``` + +and use it in templates with `{{ base_url }}`. diff --git a/modules/os2forms_forloeb/README.md b/modules/os2forms_forloeb/README.md index 5d00e940..b7d0ed0a 100644 --- a/modules/os2forms_forloeb/README.md +++ b/modules/os2forms_forloeb/README.md @@ -19,7 +19,7 @@ You can also install the module by using Drush: 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 +task. If the notification recipient is identified by 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. @@ -44,3 +44,19 @@ must be processed asynchronously. Specify the queue handling notification jobs. #### Templates Define templates for emails and digital post (PDF). + +With some setups it might be necessary to import stylesheets with a full path. + +For this reason the `base_url` variable has been added for use in templates. +Set it in `settings.local.php` + +```php +/** + * Base url. + * + * Used to specify full path to stylesheets in templates. + */ +$settings['base_url'] = 'http://nginx:8080'; +``` + +and use it in templates with `{{ base_url }}`. diff --git a/modules/os2forms_forloeb/src/MaestroHelper.php b/modules/os2forms_forloeb/src/MaestroHelper.php index 8f8e24a9..5adf6787 100644 --- a/modules/os2forms_forloeb/src/MaestroHelper.php +++ b/modules/os2forms_forloeb/src/MaestroHelper.php @@ -620,13 +620,11 @@ private function renderHtml( $html = trim((string) $this->webformThemeManager->renderPlain($build)); - $html = $this->tokenManager->replace( + return Markup::create($this->tokenManager->replace( $html, $submission, $maestroTokenData - ); - - return Markup::create($html); + )); } /** From b50d0f818e0f3656702036a7b59fe07b89327182 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Tue, 2 Apr 2024 09:50:59 +0200 Subject: [PATCH 11/33] #1039: Applied coding standards --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16547769..36342345 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,8 +15,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa - [#84](https://github.com/OS2Forms/os2forms/pull/84) Added digital post test command. - [#95](https://github.com/OS2Forms/os2forms/pull/95) - - Added `base_url` variable to twig templates. - - Tokenized all Maestro notification html. + - Added `base_url` variable to twig templates. + - Tokenized all Maestro notification html. ## [3.14.1] 2024-01-16 From 2cbaa9560aaef99090a8333723e85df2d49b6888 Mon Sep 17 00:00:00 2001 From: Jeppe Kuhlmann Andersen <78410897+jekuaitk@users.noreply.github.com> Date: Tue, 2 Apr 2024 10:16:56 +0200 Subject: [PATCH 12/33] Update CHANGELOG.md Co-authored-by: Mikkel Ricky --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36342345..47db00b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ before starting to add changes. Use example [placed in the end of the page](#exa Added digital post test command. - [#95](https://github.com/OS2Forms/os2forms/pull/95) - Added `base_url` variable to twig templates. - - Tokenized all Maestro notification html. + - Handled tokens in Maestro notification html. ## [3.14.1] 2024-01-16 From 6d0098df6a77ca609dd18b120adfdf40fccd938e Mon Sep 17 00:00:00 2001 From: Jeppe Kuhlmann Andersen <78410897+jekuaitk@users.noreply.github.com> Date: Tue, 2 Apr 2024 10:17:12 +0200 Subject: [PATCH 13/33] Update modules/os2forms_attachment/README.md Co-authored-by: Mikkel Ricky --- modules/os2forms_attachment/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/os2forms_attachment/README.md b/modules/os2forms_attachment/README.md index 3dfea56d..092408c0 100644 --- a/modules/os2forms_attachment/README.md +++ b/modules/os2forms_attachment/README.md @@ -14,7 +14,6 @@ To specify headers/footers that will override the default ones on a global level To specify headers/footers that will override the default ones on a form level (**Third party settings** -> **Entity print** section): ```/admin/structure/webform/manage/[webform]/settings``` - # Overwriting templates With some setups it might be necessary to overwrite templates From a3d114625c570d2a39d96618ac633752c73db060 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Tue, 2 Apr 2024 10:26:52 +0200 Subject: [PATCH 14/33] #1039: Cleanup --- modules/os2forms_attachment/README.md | 17 +++-------------- modules/os2forms_forloeb/README.md | 15 +++++++++------ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/modules/os2forms_attachment/README.md b/modules/os2forms_attachment/README.md index 092408c0..f732ad2f 100644 --- a/modules/os2forms_attachment/README.md +++ b/modules/os2forms_attachment/README.md @@ -17,18 +17,7 @@ To specify headers/footers that will override the default ones on a form level ( # Overwriting templates With some setups it might be necessary to overwrite templates -in order to access stylesheets. +in order to access stylesheets or images. -For this reason the `base_url` variable has been added for use in templates. -Set it in `settings.local.php` - -```php -/** - * Base url. - * - * Used to specify full path to stylesheets in templates. - */ -$settings['base_url'] = 'http://nginx:8080'; -``` - -and use it in templates with `{{ base_url }}`. +See [templates](modules/os2forms_forloeb/README.md#templates) +for more details on how to do this. diff --git a/modules/os2forms_forloeb/README.md b/modules/os2forms_forloeb/README.md index b7d0ed0a..7cf06186 100644 --- a/modules/os2forms_forloeb/README.md +++ b/modules/os2forms_forloeb/README.md @@ -45,18 +45,21 @@ must be processed asynchronously. Specify the queue handling notification jobs. Define templates for emails and digital post (PDF). -With some setups it might be necessary to import stylesheets with a full path. -For this reason the `base_url` variable has been added for use in templates. -Set it in `settings.local.php` +To reference assets, e.g. stylesheet or images, in your templates, +you can use the `base_url` Twig variable to get the base URL: + +```html + Date: Thu, 4 Apr 2024 07:14:06 +0000 Subject: [PATCH 16/33] OS-72: Styling af NemLog-in autologout pop-up --- modules/os2forms_forloeb/css/gin-custom.css | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/os2forms_forloeb/css/gin-custom.css b/modules/os2forms_forloeb/css/gin-custom.css index 396e4504..91d84887 100644 --- a/modules/os2forms_forloeb/css/gin-custom.css +++ b/modules/os2forms_forloeb/css/gin-custom.css @@ -1,3 +1,13 @@ -.ui-dialog:not(.ui-dialog-off-canvas) { +.ui-dialog:not(.ui-dialog-off-canvas, .os2web-nemlogin-autologout-dialog) { width: 70vw!important; } + + +.ui-dialog-titlebar-close:before { + content: '\2716'; + position: absolute; + transform: translateX(-50%) translateY(-45%); + font-size: 12px; + left: 50%; + top: 50%; +} \ No newline at end of file From 9c248ac054d1dbdb03c2383c74adf10a2e194ab2 Mon Sep 17 00:00:00 2001 From: "Simon L. Lange" Date: Thu, 4 Apr 2024 13:16:11 +0000 Subject: [PATCH 17/33] Updated CHANGELOG.md with pull request #96 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1764f85..b8210b55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa - Adding Lat and Long fetching to DataAddress - [#84](https://github.com/OS2Forms/os2forms/pull/84) Added digital post test command. +- [#96] (https://github.com/OS2Forms/os2forms/pull/96) + ## [3.14.1] 2024-01-16 From b27db0420ee1e3fbcf7d79a5e756ec07b8a291e0 Mon Sep 17 00:00:00 2001 From: "Simon L. Lange" Date: Thu, 4 Apr 2024 13:19:32 +0000 Subject: [PATCH 18/33] Changed CSS to follow php coding standards --- modules/os2forms_forloeb/css/gin-custom.css | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/os2forms_forloeb/css/gin-custom.css b/modules/os2forms_forloeb/css/gin-custom.css index 91d84887..9d1c0998 100644 --- a/modules/os2forms_forloeb/css/gin-custom.css +++ b/modules/os2forms_forloeb/css/gin-custom.css @@ -1,4 +1,5 @@ -.ui-dialog:not(.ui-dialog-off-canvas, .os2web-nemlogin-autologout-dialog) { +.ui-dialog:not(.ui-dialog-off-canvas, +.os2web-nemlogin-autologout-dialog) { width: 70vw!important; } @@ -10,4 +11,4 @@ font-size: 12px; left: 50%; top: 50%; -} \ No newline at end of file +} From fab2fcfc00e2e1a2b50e67a3d33871a61d296f31 Mon Sep 17 00:00:00 2001 From: "Simon L. Lange" Date: Thu, 4 Apr 2024 13:22:17 +0000 Subject: [PATCH 19/33] Updated CHANGELOG.md --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8210b55..7c7370c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,8 +14,7 @@ before starting to add changes. Use example [placed in the end of the page](#exa - Adding Lat and Long fetching to DataAddress - [#84](https://github.com/OS2Forms/os2forms/pull/84) Added digital post test command. -- [#96] (https://github.com/OS2Forms/os2forms/pull/96) - +- [#96](https://github.com/OS2Forms/os2forms/pull/96) ## [3.14.1] 2024-01-16 From f625a94e90583333e10141c861aa9ada9dbcb438 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 4 Apr 2024 15:35:07 +0200 Subject: [PATCH 20/33] 1062: Added helper function to toggle default webform encrypt --- CHANGELOG.md | 1 + composer.json | 3 +- .../install/encrypt.profile.webform.yml | 13 ++++ .../config/install/key.key.webform.yml | 17 ++++++ .../install/os2forms_encrypt.settings.yml | 1 + .../os2forms_encrypt.info.yml | 11 ++++ .../os2forms_encrypt.links.menu.yml | 5 ++ .../os2forms_encrypt/os2forms_encrypt.module | 22 +++++++ .../os2forms_encrypt.routing.yml | 7 +++ .../src/Element/WebformElementEncrypt.php | 31 ++++++++++ .../src/Form/SettingsForm.php | 59 +++++++++++++++++++ 11 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 modules/os2forms_encrypt/config/install/encrypt.profile.webform.yml create mode 100644 modules/os2forms_encrypt/config/install/key.key.webform.yml create mode 100644 modules/os2forms_encrypt/config/install/os2forms_encrypt.settings.yml create mode 100644 modules/os2forms_encrypt/os2forms_encrypt.info.yml create mode 100644 modules/os2forms_encrypt/os2forms_encrypt.links.menu.yml create mode 100644 modules/os2forms_encrypt/os2forms_encrypt.module create mode 100644 modules/os2forms_encrypt/os2forms_encrypt.routing.yml create mode 100644 modules/os2forms_encrypt/src/Element/WebformElementEncrypt.php create mode 100644 modules/os2forms_encrypt/src/Form/SettingsForm.php diff --git a/CHANGELOG.md b/CHANGELOG.md index e1764f85..935f5df2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] +- Added webform encryption modules - Adding Lat and Long fetching to DataAddress - [#84](https://github.com/OS2Forms/os2forms/pull/84) Added digital post test command. diff --git a/composer.json b/composer.json index a6e5c888..beee4327 100644 --- a/composer.json +++ b/composer.json @@ -55,6 +55,7 @@ "drupal/simple_ldap": "^1.0@alpha", "drupal/simplesamlphp_auth": "^3.2", "drupal/smtp": "^1.0@beta", + "drupal/sodium": "^2.4", "drupal/switch_page_theme": "^4.0", "drupal/telephone_validation": "^2.2", "drupal/token": "^1.5", @@ -62,7 +63,7 @@ "drupal/user_default_page": "^2.1", "drupal/webform": "^6.1", "drupal/webform_composite": "^1.0@RC", - "drupal/webform_encrypt": "^1.0@beta", + "drupal/webform_encrypt": "^2.0@alpha", "drupal/webform_migrate": "^1.1", "drupal/webform_node_element": "^1.2", "drupal/webform_remote_handlers": "^1.6.0", diff --git a/modules/os2forms_encrypt/config/install/encrypt.profile.webform.yml b/modules/os2forms_encrypt/config/install/encrypt.profile.webform.yml new file mode 100644 index 00000000..19891dfd --- /dev/null +++ b/modules/os2forms_encrypt/config/install/encrypt.profile.webform.yml @@ -0,0 +1,13 @@ +uuid: 98e9a380-a5d6-4d2a-9176-7c50a9ec7c47 +langcode: en +status: true +dependencies: + config: + - key.key.webform + module: + - sodium +id: webform +label: Webform +encryption_method: sodium +encryption_method_configuration: { } +encryption_key: webform diff --git a/modules/os2forms_encrypt/config/install/key.key.webform.yml b/modules/os2forms_encrypt/config/install/key.key.webform.yml new file mode 100644 index 00000000..aaabea7f --- /dev/null +++ b/modules/os2forms_encrypt/config/install/key.key.webform.yml @@ -0,0 +1,17 @@ +uuid: be3383e8-1b0e-4b50-989f-e132900d02a0 +langcode: en +status: true +dependencies: { } +id: webform +label: Webform +description: 'Encrypt webform submissions' +key_type: encryption +key_type_settings: + key_size: 256 +key_provider: config +key_provider_settings: + key_value: LWD5+0klWZn48ZVs13UVHaHJYawX62PAMd3sklkKj/w= + base64_encoded: true +key_input: text_field +key_input_settings: + base64_encoded: true diff --git a/modules/os2forms_encrypt/config/install/os2forms_encrypt.settings.yml b/modules/os2forms_encrypt/config/install/os2forms_encrypt.settings.yml new file mode 100644 index 00000000..cbd7f1bb --- /dev/null +++ b/modules/os2forms_encrypt/config/install/os2forms_encrypt.settings.yml @@ -0,0 +1 @@ +enabled: 1 diff --git a/modules/os2forms_encrypt/os2forms_encrypt.info.yml b/modules/os2forms_encrypt/os2forms_encrypt.info.yml new file mode 100644 index 00000000..5e1e7edf --- /dev/null +++ b/modules/os2forms_encrypt/os2forms_encrypt.info.yml @@ -0,0 +1,11 @@ +name: OS2Forms Encrypt +description: Encryption functionality for OS2Forms web-forms +package: OS2Forms +type: module +version: 1.0.0 +core_version_requirement: ^8 || ^9 || ^10 +dependencies: + - 'drupal:webform_encrypt' + - 'drupal:sodium' + +configure: os2forms_encrypt.admin_settings diff --git a/modules/os2forms_encrypt/os2forms_encrypt.links.menu.yml b/modules/os2forms_encrypt/os2forms_encrypt.links.menu.yml new file mode 100644 index 00000000..c7c63f8c --- /dev/null +++ b/modules/os2forms_encrypt/os2forms_encrypt.links.menu.yml @@ -0,0 +1,5 @@ +os2forms_encrypt.admin_settings: + title: 'OS2Forms Encrypt settings' + parent: system.admin_config_system + description: 'Settings for the OS2Forms Encrypt module' + route_name: os2forms_encrypt.admin_settings diff --git a/modules/os2forms_encrypt/os2forms_encrypt.module b/modules/os2forms_encrypt/os2forms_encrypt.module new file mode 100644 index 00000000..839b8a4d --- /dev/null +++ b/modules/os2forms_encrypt/os2forms_encrypt.module @@ -0,0 +1,22 @@ + &$definition) { + if ($element_id === 'webform_element_encrypt') { + $definition['#process'][] = [ + 'Drupal\os2forms_encrypt\Element\WebformElementEncrypt', + 'processWebformElementEncrypt', + ]; + } + } +} diff --git a/modules/os2forms_encrypt/os2forms_encrypt.routing.yml b/modules/os2forms_encrypt/os2forms_encrypt.routing.yml new file mode 100644 index 00000000..2b23f680 --- /dev/null +++ b/modules/os2forms_encrypt/os2forms_encrypt.routing.yml @@ -0,0 +1,7 @@ +os2forms_encrypt.admin_settings: + path: '/admin/config/os2forms_encrypt/settings' + defaults: + _form: '\Drupal\os2forms_encrypt\Form\SettingsForm' + _title: 'OS2Forms Encrypt settings' + requirements: + _permission: 'administer encrypt' diff --git a/modules/os2forms_encrypt/src/Element/WebformElementEncrypt.php b/modules/os2forms_encrypt/src/Element/WebformElementEncrypt.php new file mode 100644 index 00000000..f9dca529 --- /dev/null +++ b/modules/os2forms_encrypt/src/Element/WebformElementEncrypt.php @@ -0,0 +1,31 @@ +get('enabled')) { + $element['element_encrypt']['encrypt']['#default_value'] = TRUE; + } + + return $element; + } + +} diff --git a/modules/os2forms_encrypt/src/Form/SettingsForm.php b/modules/os2forms_encrypt/src/Form/SettingsForm.php new file mode 100644 index 00000000..a6827d8e --- /dev/null +++ b/modules/os2forms_encrypt/src/Form/SettingsForm.php @@ -0,0 +1,59 @@ +config('os2forms_encrypt.settings'); + + $form['enabled'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Enabled encryption'), + '#description' => $this->t('Enable encryption for all webform fields. Please note that encryption will be applied only to those fields that are modified after enabling this option.'), + '#default_value' => $config->get('enabled'), + ]; + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state): void { + parent::submitForm($form, $form_state); + + $this->config(self::$configName) + ->set('enabled', $form_state->getValue('enabled')) + ->save(); + } + +} From 4381d7ca5afdf0bdf3b4c0e2fbfd3e6be7c1fae4 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 5 Apr 2024 09:44:26 +0200 Subject: [PATCH 21/33] 1062: Added drush command to enable webform encrypt for all forms --- modules/os2forms_encrypt/drush.services.yml | 6 ++ .../src/Commands/Os2FormsEncryptCommands.php | 83 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 modules/os2forms_encrypt/drush.services.yml create mode 100644 modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php diff --git a/modules/os2forms_encrypt/drush.services.yml b/modules/os2forms_encrypt/drush.services.yml new file mode 100644 index 00000000..f5d6e418 --- /dev/null +++ b/modules/os2forms_encrypt/drush.services.yml @@ -0,0 +1,6 @@ +services: + os2forms_encrypt.commands: + class: Drupal\os2forms_encrypt\Commands\Os2FormsEncryptCommands + arguments: ['@entity_type.manager', '@plugin.manager.webform.element'] + tags: + - { name: drush.command } diff --git a/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php b/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php new file mode 100644 index 00000000..3639d2c3 --- /dev/null +++ b/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php @@ -0,0 +1,83 @@ +entityTypeManager = $entityTypeManager; + $this->webformElementManager = $webformElementManager; + parent::__construct(); + } + + /** + * Enable encrypt for all existing webform elements. + * + * @command os2forms-encrypt:enable + * + * @throws \Drupal\Core\Entity\EntityStorageException + */ + public function enabledEncrypt(): void { + $config = \Drupal::config(SettingsForm::$configName); + if (!$config->get('enabled')) { + $this->output()->writeln('Encrypt has not been enabled.'); + return; + } + + // Get the storage for Webform entity type. + $webformStorage = $this->entityTypeManager->getStorage('webform'); + + // Load all webform entities. + $webforms = $webformStorage->loadMultiple(); + + /** @var \Drupal\webform\Entity\Webform $webform */ + foreach ($webforms as $webform) { + // This will give you an associative array of all elements in the current webform. + $elements = $webform->getElementsDecoded(); + $config = $webform->getThirdPartySettings('webform_encrypt'); + + foreach ($elements as $key => $element) { + if (!isset($config['element'][$key])) { + $config['element'][$key] = [ + 'encrypt' => TRUE, + 'encrypt_profile' => 'webform', + ]; + } + } + + // After modifying the element array, encode it back into a string and set it back on the webform entity. + $webform->setThirdPartySetting('webform_encrypt', 'element', $config['element']); + + // Save the webform entity so the changes persist. + $webform->save(); + } + } +} From e5ff65937d934b4ca72462b3c358aeb583749213 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 5 Apr 2024 10:20:24 +0200 Subject: [PATCH 22/33] 1062: Fixed code style in module to enable webform encrypt --- modules/os2forms_encrypt/drush.services.yml | 2 +- .../os2forms_encrypt/os2forms_encrypt.module | 1 + .../src/Commands/Os2FormsEncryptCommands.php | 39 ++++++++++++------- .../src/Element/WebformElementEncrypt.php | 5 ++- .../src/Form/SettingsForm.php | 4 +- 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/modules/os2forms_encrypt/drush.services.yml b/modules/os2forms_encrypt/drush.services.yml index f5d6e418..ccb7a2aa 100644 --- a/modules/os2forms_encrypt/drush.services.yml +++ b/modules/os2forms_encrypt/drush.services.yml @@ -1,6 +1,6 @@ services: os2forms_encrypt.commands: class: Drupal\os2forms_encrypt\Commands\Os2FormsEncryptCommands - arguments: ['@entity_type.manager', '@plugin.manager.webform.element'] + arguments: ['@entity_type.manager', '@config.factory'] tags: - { name: drush.command } diff --git a/modules/os2forms_encrypt/os2forms_encrypt.module b/modules/os2forms_encrypt/os2forms_encrypt.module index 839b8a4d..daef0b2d 100644 --- a/modules/os2forms_encrypt/os2forms_encrypt.module +++ b/modules/os2forms_encrypt/os2forms_encrypt.module @@ -2,6 +2,7 @@ /** * @file + * This module enabled webform submission encryption as a default option. */ /** diff --git a/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php b/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php index 3639d2c3..29889fc1 100644 --- a/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php +++ b/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php @@ -2,9 +2,9 @@ namespace Drupal\os2forms_encrypt\Commands; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\os2forms_encrypt\Form\SettingsForm; -use Drupal\webform\Plugin\WebformElementManagerInterface; use Drush\Commands\DrushCommands; /** @@ -19,22 +19,28 @@ class Os2FormsEncryptCommands extends DrushCommands { * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityTypeManager; + protected EntityTypeManagerInterface $entityTypeManager; /** - * @var \Drupal\webform\Plugin\WebformElementManagerInterface + * Factory to get module configuration. + * + * @var \Drupal\Core\Config\ConfigFactoryInterface */ - private WebformElementManagerInterface $webformElementManager; + protected ConfigFactoryInterface $configFactory; /** - * Constructs a new Os2FormsEncryptCommands object. + * Class constructor. * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager - * The entity type manager. + * An instance of the entity type manager. + * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory + * An instance of the config factory. + * + * @return void */ - public function __construct(EntityTypeManagerInterface $entityTypeManager, WebformElementManagerInterface $webformElementManager) { + public function __construct(EntityTypeManagerInterface $entityTypeManager, ConfigFactoryInterface $configFactory) { $this->entityTypeManager = $entityTypeManager; - $this->webformElementManager = $webformElementManager; + $this->configFactory = $configFactory; parent::__construct(); } @@ -46,7 +52,7 @@ public function __construct(EntityTypeManagerInterface $entityTypeManager, Webfo * @throws \Drupal\Core\Entity\EntityStorageException */ public function enabledEncrypt(): void { - $config = \Drupal::config(SettingsForm::$configName); + $config = $this->configFactory->get(SettingsForm::$configName); if (!$config->get('enabled')) { $this->output()->writeln('Encrypt has not been enabled.'); return; @@ -60,24 +66,27 @@ public function enabledEncrypt(): void { /** @var \Drupal\webform\Entity\Webform $webform */ foreach ($webforms as $webform) { - // This will give you an associative array of all elements in the current webform. $elements = $webform->getElementsDecoded(); $config = $webform->getThirdPartySettings('webform_encrypt'); + $changed = FALSE; foreach ($elements as $key => $element) { if (!isset($config['element'][$key])) { $config['element'][$key] = [ 'encrypt' => TRUE, 'encrypt_profile' => 'webform', ]; + $changed = TRUE; } } - // After modifying the element array, encode it back into a string and set it back on the webform entity. - $webform->setThirdPartySetting('webform_encrypt', 'element', $config['element']); - - // Save the webform entity so the changes persist. - $webform->save(); + // Save the webform entity so the changes persist, if any changes where + // made. + if ($changed) { + $webform->setThirdPartySetting('webform_encrypt', 'element', $config['element']); + $webform->save(); + } } } + } diff --git a/modules/os2forms_encrypt/src/Element/WebformElementEncrypt.php b/modules/os2forms_encrypt/src/Element/WebformElementEncrypt.php index f9dca529..066e3db2 100644 --- a/modules/os2forms_encrypt/src/Element/WebformElementEncrypt.php +++ b/modules/os2forms_encrypt/src/Element/WebformElementEncrypt.php @@ -6,9 +6,10 @@ use Drupal\os2forms_encrypt\Form\SettingsForm; /** - * Class WebformElementEncrypt + * Class WebformElementEncrypt. * - * This class contains a static method to process element attributes for webforms. + * This class contains a static method to process element attributes for + * webforms. * * @package Drupal\Core\Extension\Module\YourModule\WebformElementEncrypt */ diff --git a/modules/os2forms_encrypt/src/Form/SettingsForm.php b/modules/os2forms_encrypt/src/Form/SettingsForm.php index a6827d8e..0fd05fcf 100644 --- a/modules/os2forms_encrypt/src/Form/SettingsForm.php +++ b/modules/os2forms_encrypt/src/Form/SettingsForm.php @@ -11,7 +11,9 @@ class SettingsForm extends ConfigFormBase { /** - * @var string $configName + * The name of the configuration setting. + * + * @var string */ public static string $configName = 'os2forms_encrypt.settings'; From 6f3fb497297671770180c218dbfd62348d46d3f0 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 5 Apr 2024 10:56:30 +0200 Subject: [PATCH 23/33] 1062: Added notification to encrypt settings page --- modules/os2forms_encrypt/src/Form/SettingsForm.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/os2forms_encrypt/src/Form/SettingsForm.php b/modules/os2forms_encrypt/src/Form/SettingsForm.php index 0fd05fcf..62e2c6a6 100644 --- a/modules/os2forms_encrypt/src/Form/SettingsForm.php +++ b/modules/os2forms_encrypt/src/Form/SettingsForm.php @@ -4,6 +4,7 @@ use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Link; /** * Class Os2FormsEncryptAdminForm. @@ -37,6 +38,17 @@ public function getFormId(): string { public function buildForm(array $form, FormStateInterface $form_state): array { $config = $this->config('os2forms_encrypt.settings'); + $link = Link::createFromRoute($this->t('administration'), 'entity.key.collection'); + $form['notice'] = [ + '#type' => 'inline_template', + '#template' => '

{{ title }}

{{ message|t }}

{{ adminMessage|t }}

', + '#context' => [ + 'title' => 'Please note', + 'message' => 'The encryption key that comes with this module should not be used and should be changed before encrypting anything.', + 'adminMessage' => 'You can modify the key (named "webform") in the keys ' . $link->toString() . ' panel. Additionally, the execution of this command can generate a new 256-bit key for you:
dd if=/dev/urandom bs=32 count=1 | base64 -i -
', + ], + ]; + $form['enabled'] = [ '#type' => 'checkbox', '#title' => $this->t('Enabled encryption'), From cfb29bf96e79ebb8721059962cd3cd726f272615 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 8 Apr 2024 10:17:28 +0200 Subject: [PATCH 24/33] 1062: Updated minor code style fixes in webform encrypt --- .../os2forms_encrypt/src/Element/WebformElementEncrypt.php | 2 -- modules/os2forms_encrypt/src/Form/SettingsForm.php | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/os2forms_encrypt/src/Element/WebformElementEncrypt.php b/modules/os2forms_encrypt/src/Element/WebformElementEncrypt.php index 066e3db2..4e271890 100644 --- a/modules/os2forms_encrypt/src/Element/WebformElementEncrypt.php +++ b/modules/os2forms_encrypt/src/Element/WebformElementEncrypt.php @@ -10,8 +10,6 @@ * * This class contains a static method to process element attributes for * webforms. - * - * @package Drupal\Core\Extension\Module\YourModule\WebformElementEncrypt */ class WebformElementEncrypt { diff --git a/modules/os2forms_encrypt/src/Form/SettingsForm.php b/modules/os2forms_encrypt/src/Form/SettingsForm.php index 62e2c6a6..14e1f819 100644 --- a/modules/os2forms_encrypt/src/Form/SettingsForm.php +++ b/modules/os2forms_encrypt/src/Form/SettingsForm.php @@ -7,7 +7,9 @@ use Drupal\Core\Link; /** - * Class Os2FormsEncryptAdminForm. + * Class SettingsForm. + * + * This is the settings for the module. */ class SettingsForm extends ConfigFormBase { From 41811ae9917cd7f5bc8aed9223574e82f287e018 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 8 Apr 2024 10:38:24 +0200 Subject: [PATCH 25/33] 1062: Fixed title translation in os2form encrypt Co-authored-by: Jeppe Kuhlmann Andersen <78410897+jekuaitk@users.noreply.github.com> --- modules/os2forms_encrypt/src/Form/SettingsForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/os2forms_encrypt/src/Form/SettingsForm.php b/modules/os2forms_encrypt/src/Form/SettingsForm.php index 14e1f819..35722d3a 100644 --- a/modules/os2forms_encrypt/src/Form/SettingsForm.php +++ b/modules/os2forms_encrypt/src/Form/SettingsForm.php @@ -43,7 +43,7 @@ public function buildForm(array $form, FormStateInterface $form_state): array { $link = Link::createFromRoute($this->t('administration'), 'entity.key.collection'); $form['notice'] = [ '#type' => 'inline_template', - '#template' => '

{{ title }}

{{ message|t }}

{{ adminMessage|t }}

', + '#template' => '

{{ title|t }}

{{ message|t }}

{{ adminMessage|t }}

', '#context' => [ 'title' => 'Please note', 'message' => 'The encryption key that comes with this module should not be used and should be changed before encrypting anything.', From 7517de8006e62e313adf6d4142903ecf09d760b5 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 24 Apr 2024 11:10:27 +0200 Subject: [PATCH 26/33] Apply coding standards --- CHANGELOG.md | 1 + .../Drush/Commands/DigitalPostTestCommands.php | 17 ++++++++++------- .../BeskedfordelerEventSubscriber.php | 3 ++- .../src/Form/SettingsForm.php | 2 +- .../src/Helper/AbstractMessageHelper.php | 2 +- .../src/Helper/BeskedfordelerHelper.php | 3 ++- .../src/Helper/CertificateLocatorHelper.php | 2 +- .../src/Helper/DigitalPostHelper.php | 2 +- .../src/Helper/WebformHelperSF1601.php | 2 +- .../src/Model/Document.php | 2 +- .../JobType/SendDigitalPostSF1601.php | 2 +- .../MaestroNotificationController.php | 2 +- .../os2forms_forloeb/src/Form/SettingsForm.php | 2 +- modules/os2forms_forloeb/src/MaestroHelper.php | 12 ++++++------ .../JobType/SendMeastroNotification.php | 2 +- .../NemloginRedirectSubscriber.php | 3 ++- .../WebformHandler/SaveToFileWebformHandler.php | 2 +- 17 files changed, 34 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c7370c3..1b1b2a2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ before starting to add changes. Use example [placed in the end of the page](#exa - [#84](https://github.com/OS2Forms/os2forms/pull/84) Added digital post test command. - [#96](https://github.com/OS2Forms/os2forms/pull/96) +- Fix ## [3.14.1] 2024-01-16 diff --git a/modules/os2forms_digital_post/src/Drush/Commands/DigitalPostTestCommands.php b/modules/os2forms_digital_post/src/Drush/Commands/DigitalPostTestCommands.php index 653783ff..8db7f4f1 100644 --- a/modules/os2forms_digital_post/src/Drush/Commands/DigitalPostTestCommands.php +++ b/modules/os2forms_digital_post/src/Drush/Commands/DigitalPostTestCommands.php @@ -26,7 +26,7 @@ public function __construct( private readonly DigitalPostHelper $digitalPostHelper, private readonly Token $token, private readonly EntityPrintPluginManagerInterface $entityPrintPluginManager, - private readonly Settings $digitalPostSettings + private readonly Settings $digitalPostSettings, ) { } @@ -53,12 +53,15 @@ public function __construct( * @command os2forms-digital-post:test:send * @usage os2forms-digital-post:test:send --help */ - public function send(array $recipients, array $options = [ - 'subject' => 'os2forms_digital_post', - 'message' => 'This is a test message from os2forms_digital_post sent on [current-date:html_datetime].', - 'digital-post-type' => SF1601::TYPE_AUTOMATISK_VALG, - 'dump-digital-post-settings' => FALSE, - ]): void { + public function send( + array $recipients, + array $options = [ + 'subject' => 'os2forms_digital_post', + 'message' => 'This is a test message from os2forms_digital_post sent on [current-date:html_datetime].', + 'digital-post-type' => SF1601::TYPE_AUTOMATISK_VALG, + 'dump-digital-post-settings' => FALSE, + ], + ): void { $io = new SymfonyStyle($this->input(), $this->output()); if ($options['dump-digital-post-settings']) { diff --git a/modules/os2forms_digital_post/src/EventSubscriber/BeskedfordelerEventSubscriber.php b/modules/os2forms_digital_post/src/EventSubscriber/BeskedfordelerEventSubscriber.php index 0ebbc4ef..cbef5ad4 100644 --- a/modules/os2forms_digital_post/src/EventSubscriber/BeskedfordelerEventSubscriber.php +++ b/modules/os2forms_digital_post/src/EventSubscriber/BeskedfordelerEventSubscriber.php @@ -23,7 +23,8 @@ public function __construct( private readonly BeskedfordelerHelper $beskedfordelerHelper, private readonly MessageHelper $messageHelper, private readonly WebformHelperSF1601 $webformHelper, - LoggerInterface $logger) { + LoggerInterface $logger, + ) { parent::__construct($logger); } diff --git a/modules/os2forms_digital_post/src/Form/SettingsForm.php b/modules/os2forms_digital_post/src/Form/SettingsForm.php index 0d968590..ad0fd962 100644 --- a/modules/os2forms_digital_post/src/Form/SettingsForm.php +++ b/modules/os2forms_digital_post/src/Form/SettingsForm.php @@ -32,7 +32,7 @@ final class SettingsForm extends FormBase { public function __construct( private readonly Settings $settings, private readonly CertificateLocatorHelper $certificateLocatorHelper, - EntityTypeManagerInterface $entityTypeManager + EntityTypeManagerInterface $entityTypeManager, ) { $this->queueStorage = $entityTypeManager->getStorage('advancedqueue_queue'); } diff --git a/modules/os2forms_digital_post/src/Helper/AbstractMessageHelper.php b/modules/os2forms_digital_post/src/Helper/AbstractMessageHelper.php index 100bac4b..d9fb96a3 100644 --- a/modules/os2forms_digital_post/src/Helper/AbstractMessageHelper.php +++ b/modules/os2forms_digital_post/src/Helper/AbstractMessageHelper.php @@ -24,7 +24,7 @@ abstract class AbstractMessageHelper { public function __construct( readonly protected Settings $settings, readonly protected ElementInfoManager $elementInfoManager, - readonly protected WebformTokenManagerInterface $webformTokenManager + readonly protected WebformTokenManagerInterface $webformTokenManager, ) { } diff --git a/modules/os2forms_digital_post/src/Helper/BeskedfordelerHelper.php b/modules/os2forms_digital_post/src/Helper/BeskedfordelerHelper.php index e24b5093..5b93da5e 100644 --- a/modules/os2forms_digital_post/src/Helper/BeskedfordelerHelper.php +++ b/modules/os2forms_digital_post/src/Helper/BeskedfordelerHelper.php @@ -24,7 +24,8 @@ class BeskedfordelerHelper { public function __construct( private readonly Connection $database, private readonly MeMoHelper $meMoHelper, - LoggerInterface $logger) { + LoggerInterface $logger, + ) { $this->setLogger($logger); } diff --git a/modules/os2forms_digital_post/src/Helper/CertificateLocatorHelper.php b/modules/os2forms_digital_post/src/Helper/CertificateLocatorHelper.php index 1e5d9f12..7c4d4117 100644 --- a/modules/os2forms_digital_post/src/Helper/CertificateLocatorHelper.php +++ b/modules/os2forms_digital_post/src/Helper/CertificateLocatorHelper.php @@ -23,7 +23,7 @@ class CertificateLocatorHelper { * {@inheritdoc} */ public function __construct( - private readonly Settings $settings + private readonly Settings $settings, ) { } diff --git a/modules/os2forms_digital_post/src/Helper/DigitalPostHelper.php b/modules/os2forms_digital_post/src/Helper/DigitalPostHelper.php index 78972ef4..c51f0dee 100644 --- a/modules/os2forms_digital_post/src/Helper/DigitalPostHelper.php +++ b/modules/os2forms_digital_post/src/Helper/DigitalPostHelper.php @@ -34,7 +34,7 @@ public function __construct( private readonly ForsendelseHelper $forsendelseHelper, private readonly BeskedfordelerHelper $beskedfordelerHelper, private readonly LoggerChannelInterface $logger, - private readonly LoggerChannelInterface $submissionLogger + private readonly LoggerChannelInterface $submissionLogger, ) { } diff --git a/modules/os2forms_digital_post/src/Helper/WebformHelperSF1601.php b/modules/os2forms_digital_post/src/Helper/WebformHelperSF1601.php index 4fb86767..f3054f8b 100644 --- a/modules/os2forms_digital_post/src/Helper/WebformHelperSF1601.php +++ b/modules/os2forms_digital_post/src/Helper/WebformHelperSF1601.php @@ -57,7 +57,7 @@ public function __construct( private readonly BeskedfordelerHelper $beskedfordelerHelper, private readonly LoggerChannelInterface $logger, private readonly LoggerChannelInterface $submissionLogger, - private readonly DigitalPostHelper $digitalPostHelper + private readonly DigitalPostHelper $digitalPostHelper, ) { $this->webformSubmissionStorage = $entityTypeManager->getStorage('webform_submission'); $this->queueStorage = $entityTypeManager->getStorage('advancedqueue_queue'); diff --git a/modules/os2forms_digital_post/src/Model/Document.php b/modules/os2forms_digital_post/src/Model/Document.php index 42768ad3..d34c5a57 100644 --- a/modules/os2forms_digital_post/src/Model/Document.php +++ b/modules/os2forms_digital_post/src/Model/Document.php @@ -17,7 +17,7 @@ public function __construct( readonly public string $content, readonly public string $mimeType, readonly public string $filename, - readonly public string $language = self::LANGUAGE_DEFAULT + readonly public string $language = self::LANGUAGE_DEFAULT, ) { } diff --git a/modules/os2forms_digital_post/src/Plugin/AdvancedQueue/JobType/SendDigitalPostSF1601.php b/modules/os2forms_digital_post/src/Plugin/AdvancedQueue/JobType/SendDigitalPostSF1601.php index 6e10480d..3e9cd0a0 100644 --- a/modules/os2forms_digital_post/src/Plugin/AdvancedQueue/JobType/SendDigitalPostSF1601.php +++ b/modules/os2forms_digital_post/src/Plugin/AdvancedQueue/JobType/SendDigitalPostSF1601.php @@ -50,7 +50,7 @@ public function __construct( array $configuration, $plugin_id, $plugin_definition, - WebformHelperSF1601 $helper + WebformHelperSF1601 $helper, ) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->helper = $helper; diff --git a/modules/os2forms_forloeb/src/Controller/MaestroNotificationController.php b/modules/os2forms_forloeb/src/Controller/MaestroNotificationController.php index 989607a0..e60a51f8 100644 --- a/modules/os2forms_forloeb/src/Controller/MaestroNotificationController.php +++ b/modules/os2forms_forloeb/src/Controller/MaestroNotificationController.php @@ -23,7 +23,7 @@ class MaestroNotificationController extends ControllerBase { */ public function __construct( private readonly WebformSubmissionStorageInterface $webformSubmissionStorage, - private readonly MaestroHelper $maestroHelper + private readonly MaestroHelper $maestroHelper, ) { } diff --git a/modules/os2forms_forloeb/src/Form/SettingsForm.php b/modules/os2forms_forloeb/src/Form/SettingsForm.php index d6f1eb8e..deb91bb6 100644 --- a/modules/os2forms_forloeb/src/Form/SettingsForm.php +++ b/modules/os2forms_forloeb/src/Form/SettingsForm.php @@ -30,7 +30,7 @@ public function __construct( ConfigFactoryInterface $configFactory, private readonly RoleStorageInterface $roleStorage, private readonly EntityStorageInterface $queueStorage, - private readonly ModuleExtensionList $moduleHandler + private readonly ModuleExtensionList $moduleHandler, ) { parent::__construct($configFactory); } diff --git a/modules/os2forms_forloeb/src/MaestroHelper.php b/modules/os2forms_forloeb/src/MaestroHelper.php index dfa65cae..0323fa18 100644 --- a/modules/os2forms_forloeb/src/MaestroHelper.php +++ b/modules/os2forms_forloeb/src/MaestroHelper.php @@ -80,7 +80,7 @@ public function __construct( private readonly EntityPrintPluginManagerInterface $entityPrintPluginManager, private readonly DigitalPostHelper $digitalPostHelper, private readonly LoggerChannelInterface $logger, - private readonly LoggerChannelInterface $submissionLogger + private readonly LoggerChannelInterface $submissionLogger, ) { $this->config = $configFactory->get(SettingsForm::SETTINGS); $this->webformSubmissionStorage = $entityTypeManager->getStorage('webform_submission'); @@ -148,7 +148,7 @@ private function handleSubmissionNotification( string $notificationType, WebformSubmissionInterface $submission, array $templateTask, - int $maestroQueueID + int $maestroQueueID, ): ?Job { $context = [ 'webform_submission' => $submission, @@ -225,7 +225,7 @@ private function sendNotification( string $notificationType, WebformSubmissionInterface $submission, array $templateTask, - int $maestroQueueID + int $maestroQueueID, ) { $context = [ 'webform_submission' => $submission, @@ -309,7 +309,7 @@ private function sendNotificationEmail( string $subject, string $body, WebformSubmissionInterface $submission, - string $notificationType + string $notificationType, ): void { try { $message = [ @@ -376,7 +376,7 @@ private function sendNotificationDigitalPost( string $taskUrl, string $actionLabel, WebformSubmissionInterface $submission, - string $notificationType + string $notificationType, ): void { try { $document = new Document( @@ -593,7 +593,7 @@ private function renderHtml( array $content, string $taskUrl, string $actionLabel, - WebformSubmissionInterface $submission + WebformSubmissionInterface $submission, ): string|MarkupInterface { $template = $this->config->get('templates')['notification_' . $type] ?? NULL; if (file_exists($template)) { diff --git a/modules/os2forms_forloeb/src/Plugin/AdvancedQueue/JobType/SendMeastroNotification.php b/modules/os2forms_forloeb/src/Plugin/AdvancedQueue/JobType/SendMeastroNotification.php index 8968e03e..7c236f61 100644 --- a/modules/os2forms_forloeb/src/Plugin/AdvancedQueue/JobType/SendMeastroNotification.php +++ b/modules/os2forms_forloeb/src/Plugin/AdvancedQueue/JobType/SendMeastroNotification.php @@ -40,7 +40,7 @@ public function __construct( array $configuration, $plugin_id, $plugin_definition, - private readonly MaestroHelper $helper + private readonly MaestroHelper $helper, ) { parent::__construct($configuration, $plugin_id, $plugin_definition); } diff --git a/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php b/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php index 6297a076..bbc734e9 100644 --- a/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php +++ b/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php @@ -88,7 +88,8 @@ public function __construct( EntityFieldManagerInterface $entity_field_manager, ConfigFactoryInterface $config_factory, MessengerInterface $messenger, - KillSwitch $page_cache_kill_switch) { + KillSwitch $page_cache_kill_switch, + ) { $this->nemloginAuthProvider = $nemloginAuthProvider; $this->account = $account; $this->entityFieldManager = $entity_field_manager; diff --git a/src/Plugin/WebformHandler/SaveToFileWebformHandler.php b/src/Plugin/WebformHandler/SaveToFileWebformHandler.php index fcb783fa..58910d17 100644 --- a/src/Plugin/WebformHandler/SaveToFileWebformHandler.php +++ b/src/Plugin/WebformHandler/SaveToFileWebformHandler.php @@ -764,7 +764,7 @@ protected function handleError($state, $message, $file_path, $file_type) { */ protected function buildTokenTreeElement( array $token_types = ['webform', 'webform_submission'], - $description = NULL + $description = NULL, ) { $description = $description ?: $this->t('Use [webform_submission:values:ELEMENT_KEY:raw] to get plain text values.'); return parent::buildTokenTreeElement($token_types, $description); From 558fa8429d853d957639a6ed15e5bcd5c148546e Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 24 Apr 2024 11:15:02 +0200 Subject: [PATCH 27/33] Updated CHANGELOG --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b1b2a2a..e6cd32dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,9 @@ before starting to add changes. Use example [placed in the end of the page](#exa - [#84](https://github.com/OS2Forms/os2forms/pull/84) Added digital post test command. - [#96](https://github.com/OS2Forms/os2forms/pull/96) -- Fix + NemLogin autologout pop-up styling. +- [#99](https://github.com/OS2Forms/os2forms/pull/99) + Fix coding standards. ## [3.14.1] 2024-01-16 From 8fef06abedffd0e5e8089445fc551faf46a74eed Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Mon, 29 Apr 2024 13:57:40 +0200 Subject: [PATCH 28/33] Ensure array key exists before accessing it --- modules/os2forms_forloeb/os2forms_forloeb.module | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/os2forms_forloeb/os2forms_forloeb.module b/modules/os2forms_forloeb/os2forms_forloeb.module index 7720908f..4636ec3d 100644 --- a/modules/os2forms_forloeb/os2forms_forloeb.module +++ b/modules/os2forms_forloeb/os2forms_forloeb.module @@ -149,9 +149,9 @@ function os2forms_forloeb_webform_create(WebformInterface $webform) { if (empty($webform->getSetting('purge_days'))) { /** @var \Drupal\webform\WebformThirdPartySettingsManagerInterface $third_party_settings_manager */ $third_party_settings_manager = \Drupal::service('webform.third_party_settings_manager'); - $os2forms_forloeb_settings = $third_party_settings_manager->getThirdPartySetting('os2forms', 'os2forms_forloeb') ?: 30; + $os2forms_forloeb_settings = $third_party_settings_manager->getThirdPartySetting('os2forms', 'os2forms_forloeb'); - $webform->setSetting('purge_days', $os2forms_forloeb_settings['purge_days']); + $webform->setSetting('purge_days', $os2forms_forloeb_settings['purge_days'] ?? 30); } } @@ -165,9 +165,9 @@ function os2forms_forloeb_webform_presave(WebformInterface $webform) { if (empty($webform->getSetting('purge_days'))) { /** @var \Drupal\webform\WebformThirdPartySettingsManagerInterface $third_party_settings_manager */ $third_party_settings_manager = \Drupal::service('webform.third_party_settings_manager'); - $os2forms_forloeb_settings = $third_party_settings_manager->getThirdPartySetting('os2forms', 'os2forms_forloeb') ?: 30; + $os2forms_forloeb_settings = $third_party_settings_manager->getThirdPartySetting('os2forms', 'os2forms_forloeb'); - $webform->setSetting('purge_days', $os2forms_forloeb_settings['purge_days']); + $webform->setSetting('purge_days', $os2forms_forloeb_settings['purge_days'] ?? 30); } } @@ -392,12 +392,12 @@ function _os2forms_forloeb_helper(): MaestroHelper { function os2forms_forloeb_form_os2forms_settings_alter(&$form, FormStateInterface $form_state) { /** @var \Drupal\webform\WebformThirdPartySettingsManagerInterface $third_party_settings_manager */ $third_party_settings_manager = \Drupal::service('webform.third_party_settings_manager'); - $os2forms_forloeb_settings = $third_party_settings_manager->getThirdPartySetting('os2forms', 'os2forms_forloeb') ?: 30; + $os2forms_forloeb_settings = $third_party_settings_manager->getThirdPartySetting('os2forms', 'os2forms_forloeb'); $form['third_party_settings']['os2forms']['os2forms_forloeb']['purge_days'] = [ '#type' => 'textfield', '#title' => t('Default number of days to retain submissions'), - '#default_value' => !(empty($os2forms_forloeb_settings)) ? $os2forms_forloeb_settings['purge_days'] : 30, + '#default_value' => $os2forms_forloeb_settings['purge_days'] ?? 30, '#description' => t('Default value is used when creating a new form, after that it is saved on a form level'), ]; } From 2472c13348c87603dac87d1db0f37b44429884d1 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Mon, 29 Apr 2024 14:04:05 +0200 Subject: [PATCH 29/33] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6cd32dd..13817971 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa NemLogin autologout pop-up styling. - [#99](https://github.com/OS2Forms/os2forms/pull/99) Fix coding standards. +- [#102](https://github.com/OS2Forms/os2forms/pull/102) + Fix array access with `purge_days` configuration. ## [3.14.1] 2024-01-16 From 7769ce30bf8b3f26bd03618c79143d0043f8327f Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Fri, 3 May 2024 12:54:07 +0200 Subject: [PATCH 30/33] #867: Cleanup --- modules/os2forms_nemid/os2forms_nemid.module | 22 +++++++++---------- .../src/Service/FormsHelper.php | 4 ++-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/modules/os2forms_nemid/os2forms_nemid.module b/modules/os2forms_nemid/os2forms_nemid.module index 84d8477f..2d11ae88 100644 --- a/modules/os2forms_nemid/os2forms_nemid.module +++ b/modules/os2forms_nemid/os2forms_nemid.module @@ -100,14 +100,14 @@ function os2forms_nemid_webform_third_party_settings_form_alter(&$form, FormStat FormsHelper::WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_DEFAULT_BEHAVIOUR => t('No'), FormsHelper::WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_DISPLAY_ERROR => t('Yes'), ], - '#title' => t('Hide form if user is under protection'), + '#title' => t('Hide form if user is under address protection'), '#default_value' => !(empty($nemloginProtectionSettings)) ? $nemloginProtectionSettings['nemlogin_hide_form'] : FormsHelper::WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_DEFAULT_BEHAVIOUR, '#description' => t('Hides elements and displays error if nemlogin reveals that citizen is under address protection and an address element is found on the webform'), ]; // Nemlogin address protection. $form['third_party_settings']['os2forms']['os2forms_nemid_address_protection']['nemlogin_hide_message'] = [ - '#title' => t('Hide message'), + '#title' => t('Access denied message'), '#type' => 'textarea', '#default_value' => !(empty($nemloginProtectionSettings)) ? $nemloginProtectionSettings['nemlogin_hide_message'] : '', '#description' => t('Message shown to user when visiting form'), @@ -128,21 +128,19 @@ function os2forms_nemid_webform_third_party_settings_form_alter(&$form, FormStat function os2forms_nemid_webform_submission_form_alter(array &$form, FormStateInterface $form_state, $form_id) { // Handle address protection. - if ($tempValue = $form_state->getTemporaryValue(FormsHelper::TEMPORARY_KEY)) { + if ($tempValue = $form_state->getTemporaryValue(FormsHelper::ADDRESS_PROTECTION_STATE)) { if (FALSE === ($tempValue['access'] ?? TRUE)) { // Flattening the elements makes it much easier to access nested elements. $elements = &WebformFormHelper::flattenElements($form['elements']); - \Drupal::messenger()->addError(t('Access to form denied')); + $message = $tempValue['message'] ?? t('This form cannot be shown because you have address protection'); - if (isset($tempValue['message'])) { - $form['os2forms_nemlogin_message'] = [ - '#theme' => 'status_messages', - '#message_list' => [ - 'error' => [$tempValue['message']], - ], - ]; - } + $form['os2forms_nemlogin_message'] = [ + '#theme' => 'status_messages', + '#message_list' => [ + 'error' => [$message], + ], + ]; // Hide all actions …. $form['actions']['#access'] = FALSE; diff --git a/modules/os2forms_nemid/src/Service/FormsHelper.php b/modules/os2forms_nemid/src/Service/FormsHelper.php index d67723e8..5f01296d 100644 --- a/modules/os2forms_nemid/src/Service/FormsHelper.php +++ b/modules/os2forms_nemid/src/Service/FormsHelper.php @@ -22,7 +22,7 @@ * @package Drupal\os2forms_nemid\Service */ class FormsHelper { - const TEMPORARY_KEY = 'os2forms_nemlogin_address_protection'; + const ADDRESS_PROTECTION_STATE = 'os2forms_nemlogin_address_protection'; /** * Defines NemID login address protection display error option. @@ -383,7 +383,7 @@ public function webformSubmissionPrepareForm(WebformSubmissionInterface $webform // mark form state with temporary key and return. $message = $webformSubmission->getWebform()->getThirdPartySettings('os2forms')['os2forms_nemid_address_protection']['nemlogin_hide_message']; - $formState->setTemporaryValue(self::TEMPORARY_KEY, [ + $formState->setTemporaryValue(self::ADDRESS_PROTECTION_STATE, [ 'access' => FALSE, 'message' => $message, ]); From 4dd2fbf7dcc933b2cca27ca0dde21cb636f1e506 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Fri, 3 May 2024 13:01:05 +0200 Subject: [PATCH 31/33] #867: Update CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d8ab3d7..a3fddac0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa - Adding Lat and Long fetching to DataAddress - [#84](https://github.com/OS2Forms/os2forms/pull/84) Added digital post test command. -- Allow denying address protected citizen from webform. +- [#92](https://github.com/OS2Forms/os2forms/pull/92) + Allow denying address protected citizen from webform. ## [3.14.1] 2024-01-16 From 0a647d1d85ee0b4e1621a6577f41d2f1334a3f3f Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 3 May 2024 13:31:37 +0200 Subject: [PATCH 32/33] 1062: Disabled default encrypt, to allow admin to set new key first --- .../config/install/os2forms_encrypt.settings.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/os2forms_encrypt/config/install/os2forms_encrypt.settings.yml b/modules/os2forms_encrypt/config/install/os2forms_encrypt.settings.yml index cbd7f1bb..b2c9a5f5 100644 --- a/modules/os2forms_encrypt/config/install/os2forms_encrypt.settings.yml +++ b/modules/os2forms_encrypt/config/install/os2forms_encrypt.settings.yml @@ -1 +1 @@ -enabled: 1 +enabled: 0 From 7c9b5e481a9f80dceabcefb1808f9d5c35281192 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 3 May 2024 13:33:51 +0200 Subject: [PATCH 33/33] 1062: Removed empty void return docblock --- .../os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php b/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php index 29889fc1..e8920546 100644 --- a/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php +++ b/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php @@ -35,8 +35,6 @@ class Os2FormsEncryptCommands extends DrushCommands { * An instance of the entity type manager. * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory * An instance of the config factory. - * - * @return void */ public function __construct(EntityTypeManagerInterface $entityTypeManager, ConfigFactoryInterface $configFactory) { $this->entityTypeManager = $entityTypeManager;