Skip to content

Commit a53c32e

Browse files
committed
Add audit log
1 parent 96281f6 commit a53c32e

File tree

4 files changed

+38
-32
lines changed

4 files changed

+38
-32
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
],
2020
"require": {
2121
"itk-dev/getorganized-api-client-php": "^1.2",
22-
"drupal/webform": "^6.1",
23-
"drupal/advancedqueue": "^1.0",
24-
"symfony/options-resolver": "^5.4",
25-
"os2forms/os2forms": "^3.13"
22+
"drupal/webform": "^6.2",
23+
"drupal/advancedqueue": "^1.2",
24+
"symfony/options-resolver": "^5.4 || ^6.0",
25+
"os2forms/os2forms": "^3.17"
2626
},
2727
"require-dev": {
2828
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",

os2forms_get_organized.info.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ dependencies:
88
- drupal:advancedqueue
99
- drupal:webform_entity_print_attachment
1010
- os2forms:os2forms_attachment
11+
- os2web:os2web_audit
1112
configure: os2forms_get_organized.admin.settings

os2forms_get_organized.services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ services:
88
- '@entity_type.manager'
99
- '@event_dispatcher'
1010
- '@Drupal\os2forms_get_organized\Helper\Settings'
11+
- '@os2web_audit.logger'

src/Helper/ArchiveHelper.php

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Drupal\os2forms_get_organized\Exception\ArchivingMethodException;
1010
use Drupal\os2forms_get_organized\Exception\CitizenArchivingException;
1111
use Drupal\os2forms_get_organized\Exception\GetOrganizedCaseIdException;
12+
use Drupal\os2web_audit\Service\Logger;
1213
use Drupal\webform\Entity\WebformSubmission;
1314
use Drupal\webform_attachment\Element\WebformAttachmentBase;
1415
use ItkDev\GetOrganized\Client;
@@ -44,27 +45,6 @@ class ArchiveHelper {
4445
*/
4546
private ?Cases $caseService = NULL;
4647

47-
/**
48-
* The EntityTypeManagerInterface.
49-
*
50-
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
51-
*/
52-
private EntityTypeManagerInterface $entityTypeManager;
53-
54-
/**
55-
* The EventDispatcherInterface.
56-
*
57-
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
58-
*/
59-
private EventDispatcherInterface $eventDispatcher;
60-
61-
/**
62-
* The settings.
63-
*
64-
* @var \Drupal\os2forms_get_organized\Helper\Settings
65-
*/
66-
private Settings $settings;
67-
6848
/**
6949
* File element types.
7050
*/
@@ -79,10 +59,12 @@ class ArchiveHelper {
7959
/**
8060
* Constructs an ArchiveHelper object.
8161
*/
82-
public function __construct(EntityTypeManagerInterface $entityTypeManager, EventDispatcherInterface $eventDispatcher, Settings $settings) {
83-
$this->entityTypeManager = $entityTypeManager;
84-
$this->eventDispatcher = $eventDispatcher;
85-
$this->settings = $settings;
62+
public function __construct(
63+
private readonly EntityTypeManagerInterface $entityTypeManager,
64+
private readonly EventDispatcherInterface $eventDispatcher,
65+
private readonly Settings $settings,
66+
private readonly Logger $auditLogger,
67+
) {
8668
}
8769

8870
/**
@@ -303,9 +285,15 @@ private function createCitizenCase(string $cprElementValue, string $cprNameEleme
303285
if (empty($response)) {
304286
throw new CitizenArchivingException('Could not create citizen case');
305287
}
288+
306289
// Example response.
307290
// {"CaseID":"BOR-2022-000046","CaseRelativeUrl":"\/cases\/BOR12\/BOR-2022-000046",...}.
308-
return $response['CaseID'];
291+
$caseId = $response['CaseID'];
292+
293+
$msg = sprintf('Created GetOrganized case %s', $caseId);
294+
$this->auditLogger->info('GetOrganized', $msg);
295+
296+
return $caseId;
309297
}
310298

311299
/**
@@ -325,7 +313,12 @@ private function createSubCase(string $caseId, string $caseName): string {
325313

326314
// Example response.
327315
// {"CaseID":"BOR-2022-000046-001","CaseRelativeUrl":"\/cases\/BOR12\/BOR-2022-000046",...}.
328-
return $response['CaseID'];
316+
$caseId = $response['CaseID'];
317+
318+
$msg = sprintf('Created GetOrganized case %s', $caseId);
319+
$this->auditLogger->info('GetOrganized', $msg);
320+
321+
return $caseId;
329322
}
330323

331324
/**
@@ -382,11 +375,19 @@ private function uploadDocumentToCase(string $caseId, string $webformAttachmentE
382375

383376
$documentIdsForFinalizing = array_merge($documentIdsForFinalizing, $childDocumentIds);
384377

385-
$this->documentService->RelateDocuments($parentDocumentId, $childDocumentIds, 1);
378+
if (!empty($childDocumentIds)) {
379+
$this->documentService->RelateDocuments($parentDocumentId, $childDocumentIds, 1);
380+
381+
$msg = sprintf('Added relation between document %s and documents %s', $parentDocumentId, implode(', ', $childDocumentIds));
382+
$this->auditLogger->info('GetOrganized', $msg);
383+
}
386384
}
387385

388386
if ($shouldBeFinalized) {
389387
$this->documentService->FinalizeMultiple($documentIdsForFinalizing);
388+
389+
$msg = sprintf('Finalized documents %s', implode(', ', $documentIdsForFinalizing));
390+
$this->auditLogger->info('GetOrganized', $msg);
390391
}
391392
}
392393

@@ -427,6 +428,9 @@ private function archiveDocumentToGetOrganizedCase(string $caseId, string $getOr
427428
unlink($tempFile);
428429
}
429430

431+
$msg = sprintf('Archived document %s to GetOrganized case %s', $getOrganizedFileName, $caseId);
432+
$this->auditLogger->info('GetOrganized', $msg);
433+
430434
return (int) $documentId;
431435
}
432436

0 commit comments

Comments
 (0)