Skip to content

Commit

Permalink
Added Digital post module
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi-itk committed Oct 3, 2023
1 parent 0bfde65 commit 950f87a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 119 deletions.
74 changes: 17 additions & 57 deletions modules/os2forms_digital_post/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,9 @@ This module provides functionality for sending digital post to danish citizens.
A WebformHandler is provided that you can add to your webform, and if configured
it will send the submitted data as digital post.

## Beskedfordeler endpoint

This module provides an endpoint,
`/os2forms_digital_post/PostStatusBeskedModtag`, for
[PostStatusBeskedModtag](https://digitaliseringskataloget.dk/integration/sf1601)
to get information on how or why not a digital post has been delivered. See
“PostStatusBeskedHent” on
<https://digitaliseringskataloget.dk/integration/sf1601> for details.

## Installation

Require it with composer:

```shell
composer require "os2forms/os2forms_digital_post"
```

Enable it with drush:
Enable the module with [`drush`](https://drush.org/)

```shell
drush pm:enable os2forms_digital_post
Expand All @@ -46,24 +31,17 @@ examples](modules/os2forms_digital_post_examples/README.md).
Go to `/admin/os2forms_digital_post/settings` to set up global settings for
digital post.

## Drush commands

```sh
drush --uri=$(itkdev-docker-compose url) os2forms_digital_post:digital-post:send --help

drush --uri=$(itkdev-docker-compose url) os2forms_digital_post:digital-post:memo-show --help
```
### Queue

## Queue
The actual sending of digital post is handled by jobs in an [Advanced
Queue](https://www.drupal.org/project/advancedqueue) queue.

Digital post is sent via jobs via an [Advanced
Queue](https://www.drupal.org/project/advancedqueue) called
`os2forms_digital_post`.
The default queue, OSForms digital post (`os2forms_digital_post`), must be
processed by a server `cron` job (cf.
`/admin/config/system/queues/manage/os2forms_digital_post?destination=/en/admin/config/system/queues`),
but this can be changed or a completely diffent queue can be used if nedd be.

The queue is processed via [Drupal's cron
run](https://www.drupal.org/docs/administering-a-drupal-site/cron-automated-tasks/cron-automated-tasks-overview),
but you can manually process the queue with `drush` if you want to process it
more often than other Drupal cron jobs:
If using the default queue, it can be processed by running the command

```sh
drush advancedqueue:queue:process os2forms_digital_post
Expand All @@ -78,31 +56,13 @@ drush advancedqueue:queue:list
or go to `/admin/config/system/queues/jobs/os2forms_digital_post` for a
graphical overview of jobs in the queue.

<!-- markdownlint-enable MD013 -->
<!-- markdownlint-enable MD022 -->
<!-- markdownlint-enable MD025 -->
<!-- markdownlint-enable MD031 -->
<!-- markdownlint-enable MD032 -->
## Coding standards
## Beskedfordeler

All coding standards are checked with [GitHub
Actions](https://github.com/features/actions) when a pull request is made (cf.
<.github/workflows/pr.yaml>).
Thie digital post module depends on [Beskedfordeler for
Drupal](https://github.com/itk-dev/beskedfordeler-drupalon) to get get
information on how or why not a digital post has been delivered (cf.
[BeskedfordelerEventSubscriber](src/EventSubscriber/BeskedfordelerEventSubscriber.php)).

Check coding standards:

```sh
docker run --rm --interactive --tty --volume ${PWD}:/app itkdev/php8.1-fpm:latest composer install
docker run --rm --interactive --tty --volume ${PWD}:/app itkdev/php8.1-fpm:latest composer coding-standards-check

docker run --rm --interactive --tty --volume ${PWD}:/app node:18 yarn --cwd /app install
docker run --rm --interactive --tty --volume ${PWD}:/app node:18 yarn --cwd /app coding-standards-check
```

Apply coding standards:

```shell
docker run --rm --interactive --tty --volume ${PWD}:/app itkdev/php8.1-fpm:latest composer coding-standards-apply

docker run --rm --interactive --tty --volume ${PWD}:/app node:18 yarn --cwd /app coding-standards-apply
```
See the [documentation for Beskedfordeler for
Drupal](https://github.com/itk-dev/beskedfordeler-drupal#beskedfordeler) for
details on how to set up the Beskedfordeler module.
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,15 @@ final class BeskedfordelerEventSubscriber extends AbstractBeskedfordelerEventSub
private const KANAL_KODE = 'Digital Post';
private const MESSAGE_UUID_KEY = 'MessageUUID';

/**
* The Beskedfordeler helper.
*
* @var \Drupal\os2forms_digital_post\Helper\BeskedfordelerHelper
*/
private BeskedfordelerHelper $beskedfordelerHelper;

/**
* The message helper.
*
* @var \Drupal\beskedfordeler\Helper\MessageHelper
*/
private MessageHelper $messageHelper;

/**
* The webform helper.
*
* @var \Drupal\os2forms_digital_post\Helper\WebformHelperSF1601
*/
private WebformHelperSF1601 $webformHelper;

/**
* Constructor.
*/
public function __construct(BeskedfordelerHelper $beskedfordelerHelper, MessageHelper $messageHelper, WebformHelperSF1601 $webformHelper, LoggerInterface $logger) {
public function __construct(
private readonly BeskedfordelerHelper $beskedfordelerHelper,
private readonly MessageHelper $messageHelper,
private readonly WebformHelperSF1601 $webformHelper,
LoggerInterface $logger) {
parent::__construct($logger);
$this->beskedfordelerHelper = $beskedfordelerHelper;
$this->messageHelper = $messageHelper;
$this->webformHelper = $webformHelper;
}

/**
Expand Down
28 changes: 8 additions & 20 deletions modules/os2forms_digital_post/src/Form/SettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,22 @@
final class SettingsForm extends FormBase {
use StringTranslationTrait;

/**
* The settings.
*
* @var \Drupal\os2forms_digital_post\Helper\Settings
*/
private Settings $settings;

/**
* The queue storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected EntityStorageInterface $queueStorage;

/**
* The certificate locator helper.
*
* @var \Drupal\os2forms_digital_post\Helper\CertificateLocatorHelper
*/
private CertificateLocatorHelper $certificateLocatorHelper;
private readonly EntityStorageInterface $queueStorage;

/**
* Constructor.
*/
public function __construct(Settings $settings, EntityTypeManagerInterface $entityTypeManager, CertificateLocatorHelper $certificateLocatorHelper) {
$this->settings = $settings;
public function __construct(
private readonly Settings $settings,
private readonly CertificateLocatorHelper $certificateLocatorHelper,
EntityTypeManagerInterface $entityTypeManager
) {
$this->queueStorage = $entityTypeManager->getStorage('advancedqueue_queue');
$this->certificateLocatorHelper = $certificateLocatorHelper;
}

/**
Expand All @@ -57,8 +45,8 @@ public function __construct(Settings $settings, EntityTypeManagerInterface $enti
public static function create(ContainerInterface $container) {
return new static(
$container->get(Settings::class),
$container->get('entity_type.manager'),
$container->get(CertificateLocatorHelper::class)
$container->get(CertificateLocatorHelper::class),
$container->get('entity_type.manager')
);
}

Expand Down
21 changes: 4 additions & 17 deletions modules/os2forms_digital_post/src/Helper/BeskedfordelerHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,13 @@ class BeskedfordelerHelper {

private const TABLE_NAME = 'os2forms_digital_post_beskedfordeler';

/**
* The database.
*
* @var \Drupal\Core\Database\Connection
*/
private Connection $database;

/**
* The MeMo helper.
*
* @var MeMoHelper
*/
private MeMoHelper $meMoHelper;

/**
* Constructor.
*/
public function __construct(Connection $database, MeMoHelper $meMoHelper, LoggerInterface $logger) {
$this->database = $database;
$this->meMoHelper = $meMoHelper;
public function __construct(
private readonly Connection $database,
private readonly MeMoHelper $meMoHelper,
LoggerInterface $logger) {
$this->setLogger($logger);
}

Expand Down

0 comments on commit 950f87a

Please sign in to comment.