diff --git a/CHANGELOG.md b/CHANGELOG.md index e95164e..005317f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] +- Added webform ID to digital post audit logging messages. +- Added audit logging to `os2forms_fasit` +- Added audit logging to `os2forms_fbs_handler` + ## [3.19.0] 2024-12-06 - Ensured installation of `os2web_audit` diff --git a/modules/os2forms_digital_post/src/Helper/DigitalPostHelper.php b/modules/os2forms_digital_post/src/Helper/DigitalPostHelper.php index 2e0d563..8681cf3 100644 --- a/modules/os2forms_digital_post/src/Helper/DigitalPostHelper.php +++ b/modules/os2forms_digital_post/src/Helper/DigitalPostHelper.php @@ -76,7 +76,9 @@ public function sendDigitalPost(string $type, Message $message, ?ForsendelseI $f // RecipientID should be the same in Message and Forsendelse, // so fetch it from Message as it is always set. - $msg = sprintf('Sent digital post of type %s to %s', $type, $message->getMessageHeader()->getRecipient()->getRecipientID()); + $msg = sprintf('Sent digital post of type %s to %s.', $type, $message->getMessageHeader()->getRecipient()->getRecipientID()); + // If the cause is a submission, add webform id to audit logging message. + $msg .= $submission ? sprintf(' Webform id %s.', $submission->getWebform()->id()) : ''; $this->auditLogger->info('DigitalPost', $msg); return [$response, $service->getLastKombiMeMoMessage()]; diff --git a/modules/os2forms_fasit/os2forms_fasit.info.yml b/modules/os2forms_fasit/os2forms_fasit.info.yml index 0142493..43309b4 100644 --- a/modules/os2forms_fasit/os2forms_fasit.info.yml +++ b/modules/os2forms_fasit/os2forms_fasit.info.yml @@ -7,4 +7,5 @@ dependencies: - drupal:webform - drupal:advancedqueue - os2forms:os2forms_attachment + - os2web:os2web_audit configure: os2forms_fasit.admin.settings diff --git a/modules/os2forms_fasit/os2forms_fasit.services.yml b/modules/os2forms_fasit/os2forms_fasit.services.yml index 23e41d4..4397c83 100644 --- a/modules/os2forms_fasit/os2forms_fasit.services.yml +++ b/modules/os2forms_fasit/os2forms_fasit.services.yml @@ -13,3 +13,4 @@ services: - '@entity_type.manager' - "@Drupal\\os2forms_fasit\\Helper\\Settings" - "@Drupal\\os2forms_fasit\\Helper\\CertificateLocatorHelper" + - "@os2web_audit.logger" diff --git a/modules/os2forms_fasit/src/Helper/FasitHelper.php b/modules/os2forms_fasit/src/Helper/FasitHelper.php index fb14351..2bd84d6 100644 --- a/modules/os2forms_fasit/src/Helper/FasitHelper.php +++ b/modules/os2forms_fasit/src/Helper/FasitHelper.php @@ -11,6 +11,7 @@ use Drupal\os2forms_fasit\Exception\InvalidSettingException; use Drupal\os2forms_fasit\Exception\InvalidSubmissionException; use Drupal\os2forms_fasit\Plugin\WebformHandler\FasitWebformHandler; +use Drupal\os2web_audit\Service\Logger; use Drupal\webform\Entity\WebformSubmission; use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\GuzzleException; @@ -33,7 +34,13 @@ class FasitHelper { 'managed_file', ]; - public function __construct(private readonly ClientInterface $client, private readonly EntityTypeManagerInterface $entityTypeManager, private readonly Settings $settings, private readonly CertificateLocatorHelper $certificateLocator) { + public function __construct( + private readonly ClientInterface $client, + private readonly EntityTypeManagerInterface $entityTypeManager, + private readonly Settings $settings, + private readonly CertificateLocatorHelper $certificateLocator, + private readonly Logger $auditLogger, + ) { } /** @@ -231,6 +238,9 @@ private function uploadDocument(array $uploads, string $submissionId, array $han if (Response::HTTP_OK !== $response->getStatusCode()) { throw new FasitResponseException(sprintf('Expected status code 200, received %d', $response->getStatusCode())); } + + $msg = sprintf('Successfully uploaded document %s to cpr %s in Fasit. Webform id %s.', $fasitDocumentTitle, $fasitCpr, $submission->getWebform()->id()); + $this->auditLogger->info('Fasit', $msg); } /** @@ -307,7 +317,7 @@ private function uploadAttachment(string $submissionId, array $handlerConfigurat $tempAttachmentFilename = tempnam(sys_get_temp_dir(), 'attachment'); file_put_contents($tempAttachmentFilename, $fileContent); - return $this->uploadFile($fileName, $tempAttachmentFilename); + return $this->uploadFile($fileName, $tempAttachmentFilename, $submission->getWebform()->id()); } /** @@ -317,6 +327,8 @@ private function uploadAttachment(string $submissionId, array $handlerConfigurat * The original filename. * @param string $tempFilename * The temp filename. + * @param string $webformId + * The webform id. * * @throws \Drupal\os2forms_fasit\Exception\CertificateLocatorException * Certificate locator exception. @@ -325,7 +337,7 @@ private function uploadAttachment(string $submissionId, array $handlerConfigurat * * @phpstan-return array */ - private function uploadFile(string $originalFilename, string $tempFilename): array { + private function uploadFile(string $originalFilename, string $tempFilename, string $webformId): array { $endpoint = sprintf('%s/%s/%s/documents/%s', $this->settings->getFasitApiBaseUrl(), $this->settings->getFasitApiTenant(), @@ -371,6 +383,12 @@ private function uploadFile(string $originalFilename, string $tempFilename): arr throw new FasitResponseException('Could not get upload id from response'); } + // Note, that this does not mean a document has been sent, + // to a citizen case in Fasit yet. This is done later by uploadDocument. + // The file has simply been made ready. + $msg = sprintf('Successfully uploaded file %s to Fasit. Webform id %s.', $originalFilename, $webformId); + $this->auditLogger->info('Fasit', $msg); + return ['filename' => $originalFilename, 'id' => $content['id']]; } @@ -392,6 +410,7 @@ private function uploadFileElements(string $submissionId): array { // Fetch element ids that may contain pdf files. /** @var \Drupal\webform\Entity\WebformSubmission $submission */ $submission = $this->getSubmission($submissionId); + $webformId = $submission->getWebform()->id(); $fileIds = $this->getFileElementKeysFromSubmission($submission); $fileStorage = $this->entityTypeManager->getStorage('file'); @@ -412,7 +431,7 @@ private function uploadFileElements(string $submissionId): array { $tempFilename = tempnam(sys_get_temp_dir(), 'attachment'); file_put_contents($tempFilename, $fileContent); - $uploads[] = $this->uploadFile($filename, $tempFilename); + $uploads[] = $this->uploadFile($filename, $tempFilename, $webformId); } return $uploads; diff --git a/modules/os2forms_fbs_handler/os2forms_fbs_handler.info.yml b/modules/os2forms_fbs_handler/os2forms_fbs_handler.info.yml index 7d43a27..e6251ac 100644 --- a/modules/os2forms_fbs_handler/os2forms_fbs_handler.info.yml +++ b/modules/os2forms_fbs_handler/os2forms_fbs_handler.info.yml @@ -6,3 +6,4 @@ core_version_requirement: ^9 || ^10 dependencies: - 'webform:webform' - 'advancedqueue:advancedqueue' + - 'os2web:os2web_audit' diff --git a/modules/os2forms_fbs_handler/src/Plugin/AdvancedQueue/JobType/FbsCreateUser.php b/modules/os2forms_fbs_handler/src/Plugin/AdvancedQueue/JobType/FbsCreateUser.php index daf3479..3afe322 100644 --- a/modules/os2forms_fbs_handler/src/Plugin/AdvancedQueue/JobType/FbsCreateUser.php +++ b/modules/os2forms_fbs_handler/src/Plugin/AdvancedQueue/JobType/FbsCreateUser.php @@ -11,6 +11,7 @@ use Drupal\os2forms_fbs_handler\Client\FBS; use Drupal\os2forms_fbs_handler\Client\Model\Guardian; use Drupal\os2forms_fbs_handler\Client\Model\Patron; +use Drupal\os2web_audit\Service\Logger; use Drupal\webform\Entity\WebformSubmission; use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; @@ -41,6 +42,7 @@ public function __construct( $plugin_definition, LoggerChannelFactoryInterface $loggerFactory, protected readonly Client $client, + protected readonly Logger $auditLogger, ) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->submissionLogger = $loggerFactory->get('webform_submission'); @@ -55,7 +57,8 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_id, $plugin_definition, $container->get('logger.factory'), - $container->get('http_client') + $container->get('http_client'), + $container->get('os2web_audit.logger'), ); } @@ -121,6 +124,9 @@ public function process(Job $job): JobResult { $this->submissionLogger->notice($this->t('The submission #@serial was successfully delivered', ['@serial' => $webformSubmission->serial()]), $logger_context); + $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()); + $this->auditLogger->info('FBS', $msg); + return JobResult::success(); } catch (\Exception | GuzzleException $e) {