Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add audit log #17

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,30 @@ jobs:
run: |
# We need a Drupal project to run drupal-check (cf. https://github.com/mglaman/drupal-check#usage)
# Install Drupal
composer --no-interaction create-project drupal/recommended-project:^9 --stability=dev drupal
composer --no-interaction create-project drupal/recommended-project:^10 --stability=dev drupal

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

# Copy our module source code into the Drupal module folder.
mkdir -p drupal/web/modules/contrib/os2forms_get_organized
cp -r os2forms_get_organized.* composer.json src drupal/web/modules/contrib/os2forms_get_organized

# Allow all plugins
composer --working-dir=drupal config --no-plugins allow-plugins true

# Add our module as a composer repository.
composer --no-interaction --working-dir=drupal config repositories.os2forms/os2forms_get_organized path web/modules/contrib/os2forms_get_organized
composer --working-dir=drupal --no-interaction config --append repositories.os2forms/os2forms_get_organized path web/modules/contrib/os2forms_get_organized

# Restore Drupal composer repository.
composer --no-interaction --working-dir=drupal config repositories.drupal composer https://packages.drupal.org/8

composer --no-interaction --working-dir=drupal config --no-plugins allow-plugins.cweagans/composer-patches true
composer --no-interaction --working-dir=drupal config --no-plugins allow-plugins.zaporylie/composer-drupal-optimizations true
composer --no-interaction --working-dir=drupal config --no-plugins allow-plugins.simplesamlphp/composer-module-installer true
# @see https://getcomposer.org/doc/03-cli.md#modifying-extra-values
composer --no-interaction --working-dir=drupal config --no-plugins --json extra.enable-patching true
# Make Drupal 10 compatible
composer --working-dir=drupal --no-interaction require psr/http-message:^1.0
composer --working-dir=drupal --no-interaction require 'mglaman/composer-drupal-lenient'
composer --working-dir=drupal config --no-plugins --merge --json extra.drupal-lenient.allowed-list '["drupal/coc_forms_auto_export", "drupal/webform_node_element"]'

# Require our module.
composer --no-interaction --working-dir=drupal require 'os2forms/os2forms_get_organized:*'
composer --working-dir=drupal --no-interaction require 'os2forms/os2forms_get_organized:*'

# Check code
composer --no-interaction --working-dir=drupal require --dev drupal/core-dev
composer --working-dir=drupal --no-interaction require --dev drupal/core-dev
cd drupal/web/modules/contrib/os2forms_get_organized
# Remove our non-dev dependencies to prevent duplicated Drupal installation
# 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
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ about writing changes to this log.

## [Unreleased]

* Added audit logging.

## [1.2.0] 05.07.2024

* Drupal 10 compatibility
Expand Down
16 changes: 9 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
],
"require": {
"itk-dev/getorganized-api-client-php": "^1.2",
"drupal/webform": "^6.1",
"drupal/advancedqueue": "^1.0",
"symfony/options-resolver": "^5.4",
"os2forms/os2forms": "^3.13"
"drupal/webform": "^6.2",
"drupal/advancedqueue": "^1.2",
"symfony/options-resolver": "^5.4 || ^6.0",
"os2forms/os2forms": "^3.17"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"drupal/coder": "^8.3",
"mglaman/drupal-check": "^1.4"
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
"mglaman/drupal-check": "^1.4",
"mglaman/phpstan-drupal": "~1.2.0"
},
"scripts": {
"code-analysis/drupal-check": [
Expand Down Expand Up @@ -55,7 +56,8 @@
"dealerdirect/phpcodesniffer-composer-installer": true,
"zaporylie/composer-drupal-optimizations": true,
"cweagans/composer-patches": true,
"simplesamlphp/composer-module-installer": true
"simplesamlphp/composer-module-installer": true,
"mglaman/composer-drupal-lenient": true
}
}
}
1 change: 1 addition & 0 deletions os2forms_get_organized.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ dependencies:
- drupal:advancedqueue
- drupal:webform_entity_print_attachment
- os2forms:os2forms_attachment
- os2web:os2web_audit
configure: os2forms_get_organized.admin.settings
1 change: 1 addition & 0 deletions os2forms_get_organized.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ services:
- '@entity_type.manager'
- '@event_dispatcher'
- '@Drupal\os2forms_get_organized\Helper\Settings'
- '@os2web_audit.logger'
60 changes: 32 additions & 28 deletions src/Helper/ArchiveHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Drupal\os2forms_get_organized\Exception\ArchivingMethodException;
use Drupal\os2forms_get_organized\Exception\CitizenArchivingException;
use Drupal\os2forms_get_organized\Exception\GetOrganizedCaseIdException;
use Drupal\os2web_audit\Service\Logger;
use Drupal\webform\Entity\WebformSubmission;
use Drupal\webform_attachment\Element\WebformAttachmentBase;
use ItkDev\GetOrganized\Client;
Expand Down Expand Up @@ -44,27 +45,6 @@ class ArchiveHelper {
*/
private ?Cases $caseService = NULL;

/**
* The EntityTypeManagerInterface.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
private EntityTypeManagerInterface $entityTypeManager;

/**
* The EventDispatcherInterface.
*
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
private EventDispatcherInterface $eventDispatcher;

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

/**
* File element types.
*/
Expand All @@ -79,10 +59,12 @@ class ArchiveHelper {
/**
* Constructs an ArchiveHelper object.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager, EventDispatcherInterface $eventDispatcher, Settings $settings) {
$this->entityTypeManager = $entityTypeManager;
$this->eventDispatcher = $eventDispatcher;
$this->settings = $settings;
public function __construct(
private readonly EntityTypeManagerInterface $entityTypeManager,
private readonly EventDispatcherInterface $eventDispatcher,
private readonly Settings $settings,
private readonly Logger $auditLogger,
) {
}

/**
Expand Down Expand Up @@ -303,9 +285,15 @@ private function createCitizenCase(string $cprElementValue, string $cprNameEleme
if (empty($response)) {
throw new CitizenArchivingException('Could not create citizen case');
}

// Example response.
// {"CaseID":"BOR-2022-000046","CaseRelativeUrl":"\/cases\/BOR12\/BOR-2022-000046",...}.
return $response['CaseID'];
$caseId = $response['CaseID'];

$msg = sprintf('Created GetOrganized case %s', $caseId);
$this->auditLogger->info('GetOrganized', $msg);

return $caseId;
}

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

// Example response.
// {"CaseID":"BOR-2022-000046-001","CaseRelativeUrl":"\/cases\/BOR12\/BOR-2022-000046",...}.
return $response['CaseID'];
$caseId = $response['CaseID'];

$msg = sprintf('Created GetOrganized case %s', $caseId);
$this->auditLogger->info('GetOrganized', $msg);

return $caseId;
}

/**
Expand Down Expand Up @@ -382,11 +375,19 @@ private function uploadDocumentToCase(string $caseId, string $webformAttachmentE

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

$this->documentService->RelateDocuments($parentDocumentId, $childDocumentIds, 1);
if (!empty($childDocumentIds)) {
$this->documentService->RelateDocuments($parentDocumentId, $childDocumentIds, 1);

$msg = sprintf('Added relation between document %s and documents %s', $parentDocumentId, implode(', ', $childDocumentIds));
$this->auditLogger->info('GetOrganized', $msg);
}
}

if ($shouldBeFinalized) {
$this->documentService->FinalizeMultiple($documentIdsForFinalizing);

$msg = sprintf('Finalized documents %s', implode(', ', $documentIdsForFinalizing));
$this->auditLogger->info('GetOrganized', $msg);
}
}

Expand Down Expand Up @@ -427,6 +428,9 @@ private function archiveDocumentToGetOrganizedCase(string $caseId, string $getOr
unlink($tempFile);
}

$msg = sprintf('Archived document %s to GetOrganized case %s', $getOrganizedFileName, $caseId);
$this->auditLogger->info('GetOrganized', $msg);

return (int) $documentId;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Plugin/AdvancedQueue/JobType/ArchiveDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Drupal\os2forms_get_organized\Plugin\AdvancedQueue\JobType;

use Drupal\advancedqueue\Job;
use Drupal\advancedqueue\JobResult;
use Drupal\advancedqueue\Plugin\AdvancedQueue\JobType\JobTypeBase;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\advancedqueue\Job;
use Drupal\advancedqueue\JobResult;
use Drupal\advancedqueue\Plugin\AdvancedQueue\JobType\JobTypeBase;
use Drupal\os2forms_get_organized\Helper\ArchiveHelper;
use Drupal\webform\Entity\WebformSubmission;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/WebformHandler/GetOrganizedWebformHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Drupal\os2forms_get_organized\Plugin\WebformHandler;

use Drupal\advancedqueue\Job;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\advancedqueue\Job;
use Drupal\os2forms_get_organized\Plugin\AdvancedQueue\JobType\ArchiveDocument;
use Drupal\webform\Plugin\WebformHandlerBase;
use Drupal\webform\WebformSubmissionConditionsValidatorInterface;
Expand Down
Loading