Skip to content

Commit 1920b4b

Browse files
authored
Merge pull request #17 from OS2Forms/feature/audit-log
Add audit log
2 parents 96281f6 + a5faeac commit 1920b4b

8 files changed

Lines changed: 62 additions & 48 deletions

File tree

.github/workflows/pr.yaml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,26 +113,30 @@ jobs:
113113
run: |
114114
# We need a Drupal project to run drupal-check (cf. https://github.com/mglaman/drupal-check#usage)
115115
# Install Drupal
116-
composer --no-interaction create-project drupal/recommended-project:^9 --stability=dev drupal
116+
composer --no-interaction create-project drupal/recommended-project:^10 --stability=dev drupal
117117
# Copy our module source code into the Drupal module folder.
118118
mkdir -p drupal/web/modules/contrib/os2forms_get_organized
119119
cp -r os2forms_get_organized.* composer.json src drupal/web/modules/contrib/os2forms_get_organized
120+
121+
# Allow all plugins
122+
composer --working-dir=drupal config --no-plugins allow-plugins true
123+
120124
# Add our module as a composer repository.
121-
composer --no-interaction --working-dir=drupal config repositories.os2forms/os2forms_get_organized path web/modules/contrib/os2forms_get_organized
125+
composer --working-dir=drupal --no-interaction config --append repositories.os2forms/os2forms_get_organized path web/modules/contrib/os2forms_get_organized
126+
122127
# Restore Drupal composer repository.
123128
composer --no-interaction --working-dir=drupal config repositories.drupal composer https://packages.drupal.org/8
124129
125-
composer --no-interaction --working-dir=drupal config --no-plugins allow-plugins.cweagans/composer-patches true
126-
composer --no-interaction --working-dir=drupal config --no-plugins allow-plugins.zaporylie/composer-drupal-optimizations true
127-
composer --no-interaction --working-dir=drupal config --no-plugins allow-plugins.simplesamlphp/composer-module-installer true
128-
# @see https://getcomposer.org/doc/03-cli.md#modifying-extra-values
129-
composer --no-interaction --working-dir=drupal config --no-plugins --json extra.enable-patching true
130+
# Make Drupal 10 compatible
131+
composer --working-dir=drupal --no-interaction require psr/http-message:^1.0
132+
composer --working-dir=drupal --no-interaction require 'mglaman/composer-drupal-lenient'
133+
composer --working-dir=drupal config --no-plugins --merge --json extra.drupal-lenient.allowed-list '["drupal/coc_forms_auto_export", "drupal/webform_node_element"]'
130134
131135
# Require our module.
132-
composer --no-interaction --working-dir=drupal require 'os2forms/os2forms_get_organized:*'
136+
composer --working-dir=drupal --no-interaction require 'os2forms/os2forms_get_organized:*'
133137
134138
# Check code
135-
composer --no-interaction --working-dir=drupal require --dev drupal/core-dev
139+
composer --working-dir=drupal --no-interaction require --dev drupal/core-dev
136140
cd drupal/web/modules/contrib/os2forms_get_organized
137141
# Remove our non-dev dependencies to prevent duplicated Drupal installation
138142
# PHP Fatal error: Cannot redeclare drupal_get_filename() (previously declared in /home/runner/work/os2forms_get_organized/os2forms_get_organized/drupal/web/modules/contrib/os2forms_get_organized/vendor/drupal/core/includes/bootstrap.inc:190) in /home/runner/work/os2forms_get_organized/os2forms_get_organized/drupal/web/core/includes/bootstrap.inc on line 190

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ about writing changes to this log.
88

99
## [Unreleased]
1010

11+
* Added audit logging.
12+
1113
## [1.2.0] 05.07.2024
1214

1315
* Drupal 10 compatibility

composer.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@
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": {
28-
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
2928
"drupal/coder": "^8.3",
30-
"mglaman/drupal-check": "^1.4"
29+
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
30+
"mglaman/drupal-check": "^1.4",
31+
"mglaman/phpstan-drupal": "~1.2.0"
3132
},
3233
"scripts": {
3334
"code-analysis/drupal-check": [
@@ -55,7 +56,8 @@
5556
"dealerdirect/phpcodesniffer-composer-installer": true,
5657
"zaporylie/composer-drupal-optimizations": true,
5758
"cweagans/composer-patches": true,
58-
"simplesamlphp/composer-module-installer": true
59+
"simplesamlphp/composer-module-installer": true,
60+
"mglaman/composer-drupal-lenient": true
5961
}
6062
}
6163
}

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

src/Plugin/AdvancedQueue/JobType/ArchiveDocument.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace Drupal\os2forms_get_organized\Plugin\AdvancedQueue\JobType;
44

5-
use Drupal\advancedqueue\Job;
6-
use Drupal\advancedqueue\JobResult;
7-
use Drupal\advancedqueue\Plugin\AdvancedQueue\JobType\JobTypeBase;
85
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
96
use Drupal\Core\Logger\LoggerChannelInterface;
107
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
8+
use Drupal\advancedqueue\Job;
9+
use Drupal\advancedqueue\JobResult;
10+
use Drupal\advancedqueue\Plugin\AdvancedQueue\JobType\JobTypeBase;
1111
use Drupal\os2forms_get_organized\Helper\ArchiveHelper;
1212
use Drupal\webform\Entity\WebformSubmission;
1313
use Symfony\Component\DependencyInjection\ContainerInterface;

src/Plugin/WebformHandler/GetOrganizedWebformHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace Drupal\os2forms_get_organized\Plugin\WebformHandler;
44

5-
use Drupal\advancedqueue\Job;
65
use Drupal\Core\Config\ConfigFactoryInterface;
76
use Drupal\Core\Entity\EntityTypeManagerInterface;
87
use Drupal\Core\Form\FormStateInterface;
98
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
109
use Drupal\Core\Logger\LoggerChannelInterface;
1110
use Drupal\Core\Render\RendererInterface;
11+
use Drupal\advancedqueue\Job;
1212
use Drupal\os2forms_get_organized\Plugin\AdvancedQueue\JobType\ArchiveDocument;
1313
use Drupal\webform\Plugin\WebformHandlerBase;
1414
use Drupal\webform\WebformSubmissionConditionsValidatorInterface;

0 commit comments

Comments
 (0)