Skip to content
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 @@ -13,6 +13,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa

- [#101](https://github.com/OS2Forms/os2forms/pull/101)
- Added support for `os2web_key` in Digital post
- Switched from saving settings in key value store to config, i.e
the module needs to be reconfigured.
- Added support for `os2web_key` in Fasit handler.
- Switched from saving settings in key value store to config, i.e
the module needs to be reconfigured.
Expand Down
6 changes: 1 addition & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"itk-dev/serviceplatformen": "^1.5",
"mglaman/composer-drupal-lenient": "^1.0",
"os2web/os2web_audit": "^0.1.6",
"os2web/os2web_datalookup": "dev-feature/os2web_key as 2.0.0",
"os2web/os2web_datalookup": "^2.0",
"os2web/os2web_key": "^1.0",
"os2web/os2web_nemlogin": "^1.0",
"os2web/os2web_simplesaml": "dev-master",
Expand All @@ -81,10 +81,6 @@
"wsdltophp/packagegenerator": "^4.0"
},
"repositories": {
"os2web/os2web_datalookup": {
"type": "vcs",
"url": "https://github.com/itk-dev/os2web_datalookup"
},
"drupal": {
"type": "composer",
"url": "https://packages.drupal.org/8"
Expand Down
10 changes: 0 additions & 10 deletions modules/os2forms_digital_post/drush.services.yml

This file was deleted.

51 changes: 8 additions & 43 deletions modules/os2forms_digital_post/os2forms_digital_post.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,64 +8,29 @@ services:
arguments: [ 'webform_submission' ]

Drupal\os2forms_digital_post\Helper\Settings:
arguments:
- "@config.factory"
- "@key.repository"
autowire: true

Drupal\os2forms_digital_post\Helper\CertificateLocatorHelper:
arguments:
- "@Drupal\\os2forms_digital_post\\Helper\\Settings"
- "@key.repository"
autowire: true

Drupal\os2forms_digital_post\Helper\MeMoHelper:
arguments:
- "@Drupal\\os2forms_digital_post\\Helper\\Settings"
- "@plugin.manager.element_info"
- "@webform.token_manager"
autowire: true

Drupal\os2forms_digital_post\Helper\ForsendelseHelper:
arguments:
- "@Drupal\\os2forms_digital_post\\Helper\\Settings"
- "@plugin.manager.element_info"
- "@webform.token_manager"
autowire: true

Drupal\os2forms_digital_post\Helper\DigitalPostHelper:
arguments:
- "@Drupal\\os2forms_digital_post\\Helper\\Settings"
- "@Drupal\\os2web_key\\KeyHelper"
- "@plugin.manager.os2web_datalookup"
- "@Drupal\\os2forms_digital_post\\Helper\\MeMoHelper"
- "@Drupal\\os2forms_digital_post\\Helper\\ForsendelseHelper"
- "@Drupal\\os2forms_digital_post\\Helper\\BeskedfordelerHelper"
- "@logger.channel.os2forms_digital_post"
- "@logger.channel.os2forms_digital_post_submission"
- "@os2web_audit.logger"
autowire: true

Drupal\os2forms_digital_post\Helper\WebformHelperSF1601:
arguments:
- "@Drupal\\os2forms_digital_post\\Helper\\Settings"
- "@entity_type.manager"
- "@plugin.manager.os2web_datalookup"
- "@Drupal\\os2forms_digital_post\\Helper\\MeMoHelper"
- "@Drupal\\os2forms_digital_post\\Helper\\ForsendelseHelper"
- "@Drupal\\os2forms_digital_post\\Helper\\BeskedfordelerHelper"
- "@logger.channel.os2forms_digital_post"
- "@logger.channel.os2forms_digital_post_submission"
- "@Drupal\\os2forms_digital_post\\Helper\\DigitalPostHelper"
autowire: true

Drupal\os2forms_digital_post\Helper\SF1461Helper:

Drupal\os2forms_digital_post\EventSubscriber\BeskedfordelerEventSubscriber:
arguments:
- '@Drupal\os2forms_digital_post\Helper\BeskedfordelerHelper'
- '@Drupal\beskedfordeler\Helper\MessageHelper'
- '@Drupal\os2forms_digital_post\Helper\WebformHelperSF1601'
- '@logger.channel.os2forms_digital_post'
autowire: true
tags:
- { name: 'event_subscriber' }

Drupal\os2forms_digital_post\Helper\BeskedfordelerHelper:
arguments:
- '@database'
- '@Drupal\os2forms_digital_post\Helper\MeMoHelper'
- '@logger.channel.os2forms_digital_post'
autowire: true
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

namespace Drupal\os2forms_digital_post\Commands;
namespace Drupal\os2forms_digital_post\Drush\Commands;

use Drupal\Component\Serialization\Yaml;
use Drupal\Core\DependencyInjection\AutowireTrait;
use Drupal\Core\Utility\Token;
use Drupal\entity_print\Plugin\EntityPrintPluginManagerInterface;
use Drupal\os2forms_digital_post\Helper\DigitalPostHelper;
Expand All @@ -12,19 +13,22 @@
use ItkDev\Serviceplatformen\Service\SF1601\SF1601;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;

/**
* Test commands for digital post.
*/
class DigitalPostTestCommands extends DrushCommands {
final class DigitalPostTestCommands extends DrushCommands {
use AutowireTrait;

/**
* Constructor.
*/
public function __construct(
private readonly DigitalPostHelper $digitalPostHelper,
private readonly Token $token,
#[Autowire(service: 'plugin.manager.entity_print.print_engine')]
private readonly EntityPrintPluginManagerInterface $entityPrintPluginManager,
private readonly Settings $digitalPostSettings,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Drupal\os2forms_digital_post\Helper\BeskedfordelerHelper;
use Drupal\os2forms_digital_post\Helper\WebformHelperSF1601;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

/**
* Event subscriber for PostStatusBeskedModtagEvent.
Expand All @@ -23,6 +24,7 @@ public function __construct(
private readonly BeskedfordelerHelper $beskedfordelerHelper,
private readonly MessageHelper $messageHelper,
private readonly WebformHelperSF1601 $webformHelper,
#[Autowire(service: 'logger.channel.os2forms_digital_post')]
LoggerInterface $logger,
) {
parent::__construct($logger);
Expand Down
149 changes: 140 additions & 9 deletions modules/os2forms_digital_post/src/Form/SettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;
use Drupal\os2forms_digital_post\Helper\CertificateLocatorHelper;
use Drupal\os2forms_digital_post\Helper\Settings;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -134,17 +135,127 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
'#type' => 'fieldset',
'#title' => $this->t('Certificate'),
'#tree' => TRUE,
];

$form[Settings::CERTIFICATE][Settings::CERTIFICATE_PROVIDER] = [
'#type' => 'select',
'#title' => $this->t('Provider'),
'#options' => [
Settings::PROVIDER_TYPE_FORM => $this->t('Form'),
Settings::PROVIDER_TYPE_KEY => $this->t('Key'),
],
'#default_value' => $this->settings->getEditableValue([Settings::CERTIFICATE, Settings::CERTIFICATE_PROVIDER]) ?? Settings::PROVIDER_TYPE_FORM,
'#description' => $this->t('Specifies which provider to use'),
];

$form[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_TYPE] = [
'#type' => 'select',
'#title' => $this->t('Certificate locator type'),
'#options' => [
CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT => $this->t('Azure key vault'),
CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM => $this->t('File system'),
],
'#default_value' => $this->settings->getEditableValue([
Settings::CERTIFICATE,
CertificateLocatorHelper::LOCATOR_TYPE,
]) ?? NULL,
'#states' => [
'visible' => [':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_FORM]],
],
'#description' => $this->t('Specifies which locator to use'),
];

Settings::KEY => [
'#type' => 'key_select',
'#key_filters' => [
'type' => 'os2web_key_certificate',
$form[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT] = [
'#type' => 'fieldset',
'#title' => $this->t('Azure key vault'),
'#states' => [
'visible' => [
':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_FORM],
':input[name="certificate[locator_type]"]' => ['value' => CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT],
],
],
];

$settings = [
CertificateLocatorHelper::LOCATOR_AZURE_KEY_VAULT_TENANT_ID => ['title' => $this->t('Tenant id')],
CertificateLocatorHelper::LOCATOR_AZURE_KEY_VAULT_APPLICATION_ID => ['title' => $this->t('Application id')],
CertificateLocatorHelper::LOCATOR_AZURE_KEY_VAULT_CLIENT_SECRET => ['title' => $this->t('Client secret')],
CertificateLocatorHelper::LOCATOR_AZURE_KEY_VAULT_NAME => ['title' => $this->t('Name')],
CertificateLocatorHelper::LOCATOR_AZURE_KEY_VAULT_SECRET => ['title' => $this->t('Secret')],
CertificateLocatorHelper::LOCATOR_AZURE_KEY_VAULT_VERSION => ['title' => $this->t('Version')],
];

foreach ($settings as $key => $info) {
$form[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT][$key] = [
'#type' => 'textfield',
'#title' => $info['title'],
'#default_value' => $this->settings->getEditableValue([
Settings::CERTIFICATE,
CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT,
$key,
]) ?? NULL,
'#states' => [
'required' => [
':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_FORM],
':input[name="certificate[locator_type]"]' => ['value' => CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT],
],
],
];
}

$form[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM] = [
'#type' => 'fieldset',
'#title' => $this->t('File system'),
'#states' => [
'visible' => [
':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_FORM],
':input[name="certificate[locator_type]"]' => ['value' => CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM],
],
'#key_description' => FALSE,
'#title' => $this->t('Key'),
'#default_value' => $this->settings->getEditableValue([Settings::CERTIFICATE, Settings::KEY]),
'#required' => TRUE,
'#description' => $this->createDescription([Settings::CERTIFICATE, Settings::KEY]),
],

CertificateLocatorHelper::LOCATOR_FILE_SYSTEM_PATH => [
'#type' => 'textfield',
'#title' => $this->t('Path'),
'#default_value' => $this->settings->getEditableValue([
Settings::CERTIFICATE,
CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM,
CertificateLocatorHelper::LOCATOR_FILE_SYSTEM_PATH,
]) ?? NULL,
'#states' => [
'required' => [
':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_FORM],
':input[name="certificate[locator_type]"]' => ['value' => CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM],
],
],
],
];

$form[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_PASSPHRASE] = [
'#type' => 'textfield',
'#title' => $this->t('Passphrase'),
'#default_value' => $this->settings->getEditableValue([
Settings::CERTIFICATE,
CertificateLocatorHelper::LOCATOR_PASSPHRASE,
]) ?? '',
'#states' => [
'visible' => [
':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_FORM],
],
],
];

$form[Settings::CERTIFICATE][Settings::PROVIDER_TYPE_KEY] = [
'#type' => 'key_select',
'#key_filters' => [
'type' => 'os2web_key_certificate',
],
'#key_description' => FALSE,
'#title' => $this->t('Key'),
'#default_value' => $this->settings->getEditableValue([Settings::CERTIFICATE, Settings::PROVIDER_TYPE_KEY]),
'#description' => $this->createDescription([Settings::CERTIFICATE, Settings::PROVIDER_TYPE_KEY]),
'#states' => [
'visible' => [':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_KEY]],
'required' => [':input[name="certificate[certificate_provider]"]' => ['value' => Settings::PROVIDER_TYPE_KEY]],
],
];

Expand Down Expand Up @@ -179,6 +290,26 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
return $form;
}

/**
* {@inheritdoc}
*
* @phpstan-param array<string, mixed> $form
*/
public function validateForm(array &$form, FormStateInterface $form_state): void {
$values = $form_state->getValues();

if (Settings::PROVIDER_TYPE_FORM === $values[Settings::CERTIFICATE][Settings::CERTIFICATE_PROVIDER]) {
if (CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM === $values[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_TYPE]) {
$path = $values[Settings::CERTIFICATE][CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM][CertificateLocatorHelper::LOCATOR_FILE_SYSTEM_PATH] ?? NULL;
if (!file_exists($path)) {
$form_state->setErrorByName('certificate][file_system][path', $this->t('Invalid certificate path: %path', ['%path' => $path]));
}
}
}

parent::validateForm($form, $form_state);
}

/**
* {@inheritdoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Drupal\webform_attachment\Element\WebformAttachmentBase;
use ItkDev\Serviceplatformen\Service\SF1601\Serializer;
use Oio\Fjernprint\ForsendelseI;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

/**
* Abstract message helper.
Expand All @@ -23,6 +24,7 @@ abstract class AbstractMessageHelper {
*/
public function __construct(
readonly protected Settings $settings,
#[Autowire(service: 'plugin.manager.element_info')]
readonly protected ElementInfoManager $elementInfoManager,
readonly protected WebformTokenManagerInterface $webformTokenManager,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Drupal\webform\WebformSubmissionInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

/**
* Beskedfordeler helper.
Expand All @@ -24,6 +25,7 @@ class BeskedfordelerHelper {
public function __construct(
private readonly Connection $database,
private readonly MeMoHelper $meMoHelper,
#[Autowire(service: 'logger.channel.os2forms_digital_post')]
LoggerInterface $logger,
) {
$this->setLogger($logger);
Expand Down
Loading
Loading