Skip to content

Commit 254adf0

Browse files
committed
Merge branch 'release/3.20.0'
2 parents b0c0e73 + 8410760 commit 254adf0

File tree

7 files changed

+44
-7
lines changed

7 files changed

+44
-7
lines changed

CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ before starting to add changes. Use example [placed in the end of the page](#exa
1111

1212
## [Unreleased]
1313

14+
## [3.20.0] 2024-12-09
15+
16+
- Added webform ID to digital post audit logging messages.
17+
- Added audit logging to `os2forms_fasit`
18+
- Added audit logging to `os2forms_fbs_handler`
19+
1420
## [3.19.0] 2024-12-06
1521

1622
- Ensured installation of `os2web_audit`
@@ -308,7 +314,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa
308314
- Security in case of vulnerabilities.
309315
```
310316

311-
[Unreleased]: https://github.com/OS2Forms/os2forms/compare/3.19.0...HEAD
317+
[Unreleased]: https://github.com/OS2Forms/os2forms/compare/3.20.0...HEAD
318+
[3.20.0]: https://github.com/OS2Forms/os2forms/compare/3.19.0...3.20.0
312319
[3.19.0]: https://github.com/OS2Forms/os2forms/compare/3.18.0...3.19.0
313320
[3.18.0]: https://github.com/OS2Forms/os2forms/compare/3.17.0...3.18.0
314321
[3.17.0]: https://github.com/OS2Forms/os2forms/compare/3.16.2...3.17.0

modules/os2forms_digital_post/src/Helper/DigitalPostHelper.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ public function sendDigitalPost(string $type, Message $message, ?ForsendelseI $f
7676

7777
// RecipientID should be the same in Message and Forsendelse,
7878
// so fetch it from Message as it is always set.
79-
$msg = sprintf('Sent digital post of type %s to %s', $type, $message->getMessageHeader()->getRecipient()->getRecipientID());
79+
$msg = sprintf('Sent digital post of type %s to %s.', $type, $message->getMessageHeader()->getRecipient()->getRecipientID());
80+
// If the cause is a submission, add webform id to audit logging message.
81+
$msg .= $submission ? sprintf(' Webform id %s.', $submission->getWebform()->id()) : '';
8082
$this->auditLogger->info('DigitalPost', $msg);
8183

8284
return [$response, $service->getLastKombiMeMoMessage()];

modules/os2forms_fasit/os2forms_fasit.info.yml

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ dependencies:
77
- drupal:webform
88
- drupal:advancedqueue
99
- os2forms:os2forms_attachment
10+
- os2web:os2web_audit
1011
configure: os2forms_fasit.admin.settings

modules/os2forms_fasit/os2forms_fasit.services.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ services:
1313
- '@entity_type.manager'
1414
- "@Drupal\\os2forms_fasit\\Helper\\Settings"
1515
- "@Drupal\\os2forms_fasit\\Helper\\CertificateLocatorHelper"
16+
- "@os2web_audit.logger"

modules/os2forms_fasit/src/Helper/FasitHelper.php

+23-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Drupal\os2forms_fasit\Exception\InvalidSettingException;
1212
use Drupal\os2forms_fasit\Exception\InvalidSubmissionException;
1313
use Drupal\os2forms_fasit\Plugin\WebformHandler\FasitWebformHandler;
14+
use Drupal\os2web_audit\Service\Logger;
1415
use Drupal\webform\Entity\WebformSubmission;
1516
use GuzzleHttp\ClientInterface;
1617
use GuzzleHttp\Exception\GuzzleException;
@@ -33,7 +34,13 @@ class FasitHelper {
3334
'managed_file',
3435
];
3536

36-
public function __construct(private readonly ClientInterface $client, private readonly EntityTypeManagerInterface $entityTypeManager, private readonly Settings $settings, private readonly CertificateLocatorHelper $certificateLocator) {
37+
public function __construct(
38+
private readonly ClientInterface $client,
39+
private readonly EntityTypeManagerInterface $entityTypeManager,
40+
private readonly Settings $settings,
41+
private readonly CertificateLocatorHelper $certificateLocator,
42+
private readonly Logger $auditLogger,
43+
) {
3744
}
3845

3946
/**
@@ -231,6 +238,9 @@ private function uploadDocument(array $uploads, string $submissionId, array $han
231238
if (Response::HTTP_OK !== $response->getStatusCode()) {
232239
throw new FasitResponseException(sprintf('Expected status code 200, received %d', $response->getStatusCode()));
233240
}
241+
242+
$msg = sprintf('Successfully uploaded document %s to cpr %s in Fasit. Webform id %s.', $fasitDocumentTitle, $fasitCpr, $submission->getWebform()->id());
243+
$this->auditLogger->info('Fasit', $msg);
234244
}
235245

236246
/**
@@ -307,7 +317,7 @@ private function uploadAttachment(string $submissionId, array $handlerConfigurat
307317
$tempAttachmentFilename = tempnam(sys_get_temp_dir(), 'attachment');
308318
file_put_contents($tempAttachmentFilename, $fileContent);
309319

310-
return $this->uploadFile($fileName, $tempAttachmentFilename);
320+
return $this->uploadFile($fileName, $tempAttachmentFilename, $submission->getWebform()->id());
311321
}
312322

313323
/**
@@ -317,6 +327,8 @@ private function uploadAttachment(string $submissionId, array $handlerConfigurat
317327
* The original filename.
318328
* @param string $tempFilename
319329
* The temp filename.
330+
* @param string $webformId
331+
* The webform id.
320332
*
321333
* @throws \Drupal\os2forms_fasit\Exception\CertificateLocatorException
322334
* Certificate locator exception.
@@ -325,7 +337,7 @@ private function uploadAttachment(string $submissionId, array $handlerConfigurat
325337
*
326338
* @phpstan-return array<string, mixed>
327339
*/
328-
private function uploadFile(string $originalFilename, string $tempFilename): array {
340+
private function uploadFile(string $originalFilename, string $tempFilename, string $webformId): array {
329341
$endpoint = sprintf('%s/%s/%s/documents/%s',
330342
$this->settings->getFasitApiBaseUrl(),
331343
$this->settings->getFasitApiTenant(),
@@ -371,6 +383,12 @@ private function uploadFile(string $originalFilename, string $tempFilename): arr
371383
throw new FasitResponseException('Could not get upload id from response');
372384
}
373385

386+
// Note, that this does not mean a document has been sent,
387+
// to a citizen case in Fasit yet. This is done later by uploadDocument.
388+
// The file has simply been made ready.
389+
$msg = sprintf('Successfully uploaded file %s to Fasit. Webform id %s.', $originalFilename, $webformId);
390+
$this->auditLogger->info('Fasit', $msg);
391+
374392
return ['filename' => $originalFilename, 'id' => $content['id']];
375393
}
376394

@@ -392,6 +410,7 @@ private function uploadFileElements(string $submissionId): array {
392410
// Fetch element ids that may contain pdf files.
393411
/** @var \Drupal\webform\Entity\WebformSubmission $submission */
394412
$submission = $this->getSubmission($submissionId);
413+
$webformId = $submission->getWebform()->id();
395414
$fileIds = $this->getFileElementKeysFromSubmission($submission);
396415
$fileStorage = $this->entityTypeManager->getStorage('file');
397416

@@ -412,7 +431,7 @@ private function uploadFileElements(string $submissionId): array {
412431
$tempFilename = tempnam(sys_get_temp_dir(), 'attachment');
413432
file_put_contents($tempFilename, $fileContent);
414433

415-
$uploads[] = $this->uploadFile($filename, $tempFilename);
434+
$uploads[] = $this->uploadFile($filename, $tempFilename, $webformId);
416435
}
417436

418437
return $uploads;

modules/os2forms_fbs_handler/os2forms_fbs_handler.info.yml

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ core_version_requirement: ^9 || ^10
66
dependencies:
77
- 'webform:webform'
88
- 'advancedqueue:advancedqueue'
9+
- 'os2web:os2web_audit'

modules/os2forms_fbs_handler/src/Plugin/AdvancedQueue/JobType/FbsCreateUser.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Drupal\os2forms_fbs_handler\Client\FBS;
1212
use Drupal\os2forms_fbs_handler\Client\Model\Guardian;
1313
use Drupal\os2forms_fbs_handler\Client\Model\Patron;
14+
use Drupal\os2web_audit\Service\Logger;
1415
use Drupal\webform\Entity\WebformSubmission;
1516
use GuzzleHttp\Client;
1617
use GuzzleHttp\Exception\GuzzleException;
@@ -41,6 +42,7 @@ public function __construct(
4142
$plugin_definition,
4243
LoggerChannelFactoryInterface $loggerFactory,
4344
protected readonly Client $client,
45+
protected readonly Logger $auditLogger,
4446
) {
4547
parent::__construct($configuration, $plugin_id, $plugin_definition);
4648
$this->submissionLogger = $loggerFactory->get('webform_submission');
@@ -55,7 +57,8 @@ public static function create(ContainerInterface $container, array $configuratio
5557
$plugin_id,
5658
$plugin_definition,
5759
$container->get('logger.factory'),
58-
$container->get('http_client')
60+
$container->get('http_client'),
61+
$container->get('os2web_audit.logger'),
5962
);
6063
}
6164

@@ -121,6 +124,9 @@ public function process(Job $job): JobResult {
121124

122125
$this->submissionLogger->notice($this->t('The submission #@serial was successfully delivered', ['@serial' => $webformSubmission->serial()]), $logger_context);
123126

127+
$msg = sprintf('Successfully created FBS patron with cpr %s and guardian with cpr %s. Webform id %s.', $data['barn_cpr'], $data['cpr'], $webformSubmission->getWebform()->id());
128+
$this->auditLogger->info('FBS', $msg);
129+
124130
return JobResult::success();
125131
}
126132
catch (\Exception | GuzzleException $e) {

0 commit comments

Comments
 (0)