Skip to content

Commit

Permalink
Merge pull request #12 from itk-dev/feature/os2form-audit
Browse files Browse the repository at this point in the history
Audit logging and code style
  • Loading branch information
jekuaitk authored Nov 21, 2024
2 parents 17f86a6 + 2387bb1 commit 9126c98
Show file tree
Hide file tree
Showing 31 changed files with 728 additions and 271 deletions.
23 changes: 23 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#### Link to ticket

Please add a link to the ticket being addressed by this change.

#### Description

Please include a short description of the suggested change and the reasoning behind the approach you have chosen.

#### Screenshot of the result

If your change affects the user interface you should include a screenshot of the result with the pull request.

#### Checklist

- [ ] My code passes our static analysis suite.
- [ ] My code passes our continuous integration process.

If your code does not pass all the requirements on the checklist you have to add a comment explaining why this change
should be exempt from the list.

#### Additional comments or questions

If you have any further comments or questions for the reviewer please add them here.
64 changes: 64 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,67 @@ jobs:

- name: Check that changelog has been updated.
run: git diff --exit-code origin/${{ github.base_ref }} -- CHANGELOG.md && exit 1 || exit 0

test-composer-files:
name: Validate composer
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [ '8.1' ]
dependency-version: [ prefer-lowest, prefer-stable ]
steps:
- uses: actions/checkout@master
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: json
coverage: none
tools: composer:v2
# https://github.com/shivammathur/setup-php#cache-composer-dependencies
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Validate composer files
run: |
composer validate --strict composer.json
# Check that dependencies resolve.
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
php-coding-standards:
name: PHP coding standards
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [ '8.1' ]
steps:
- uses: actions/checkout@master
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: json
coverage: none
tools: composer:v2
# https://github.com/shivammathur/setup-php#cache-composer-dependencies
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Dependencies
run: |
composer install --no-interaction --no-progress
- name: PHPCS
run: |
composer coding-standards-check/phpcs
57 changes: 34 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
# OS2Web Data lookup [![Build Status](https://travis-ci.org/OS2web/os2web_datalookup.svg?branch=8.x)](https://travis-ci.org/OS2web/os2web_datalookup)

## Install

OS2Web Data lookup provides integration with Danish data lookup services such as Service platformen or Datafordeler.
Module is available to download via composer.
```
OS2Web Data lookup provides integration with Danish data lookup services such as
Service platformen or Datafordeler. Module is available to download via
composer.

```shell
composer require os2web/os2web_datalookup
drush en os2web_datalookup
```

## Update
Updating process for OS2Web Data lookup module is similar to usual Drupal 8 module.
Use Composer's built-in command for listing packages that have updates available:

```
Updating process for OS2Web Data lookup module is similar to the usual Drupal 8
module. Use Composer's built-in command for listing packages that have updates
available:

```shell
composer outdated os2web/os2web_datalookup
```

## Automated testing and code quality

See [OS2Web testing and CI information](https://github.com/OS2Web/docs#testing-and-ci)

## Contribution

Project is opened for new features and os course bugfixes.
If you have any suggestion or you found a bug in project, you are very welcome
to create an issue in github repository issue tracker.
For issue description there is expected that you will provide clear and
sufficient information about your feature request or bug report.
If you have any suggestion, or you found a bug in project, you are very welcome
to create an issue in GitHub repository issue tracker. For issue description,
there is expected that you will provide clear and sufficient information about
your feature request or bug report.

### Code review policy

See [OS2Web code review policy](https://github.com/OS2Web/docs#code-review)

### Git name convention

See [OS2Web git name convention](https://github.com/OS2Web/docs#git-guideline)

### Using services in other modules

```
```php
// CVR lookup
/** @var \Drupal\os2web_datalookup\Plugin\DataLookupManager $pluginManager */
$pluginManager = \Drupal::service('plugin.manager.os2web_datalookup');
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterfaceCompany $cvrPlugin */
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupCompanyInterface $cvrPlugin */
$cvrPlugin = $pluginManager->createDefaultInstanceByGroup('cvr_lookup');

if ($cvrPlugin->isReady()) {
Expand All @@ -49,7 +57,7 @@ if ($cvrPlugin->isReady()) {
// CPR lookup.
/** @var \Drupal\os2web_datalookup\Plugin\DataLookupManager $pluginManager */
$pluginManager = \Drupal::service('plugin.manager.os2web_datalookup');
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterfaceCpr $cprPlugin */
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupCprInterface $cprPlugin */
$cprPlugin = $pluginManager->createDefaultInstanceByGroup('cpr_lookup');

if ($cprPlugin->isReady()) {
Expand All @@ -68,22 +76,25 @@ if ($cprPlugin->isReady()) {

### Datafordeler integration (https://datafordeler.dk)

In scope of os2forms project already implemented light integration
with Danmarks Adresseregister (DAR) via fetching data for form elements
autocomplete. See [os2forms_dawa submodule](https://github.com/OS2Forms/os2forms)
In the scope of os2forms project already implemented light integration with
Danmarks Adresseregister (DAR) via fetching data for form elements autocomplete.

See [os2forms_dawa submodule](https://github.com/OS2Forms/os2forms)

As soon as it is clear how the integration is going to be used, then
os2forms_dawa will be refactored to OS2Web Data lookup plugin plugin.
os2forms_dawa will be refactored to OS2Web Data lookup plugin.

## Important notes

### Serviceplatformen plugins
Settings for CPR and CVR serviceplantormen plugins are storing as configuration
in db and will(could) be exported as `yml` file via Drupal configuration
management system. And afterwards could be tracked by `git`.

If case you have public access to your git repository all setting from plugins
Settings for CPR and CVR serviceplatformen plugins are storing as configuration
in db and will(could) be exported as `yml` file via Drupal's configuration
management system. And afterward could be tracked by `git`.

If case you have public access to your git repository, all settings from plugins
will be exposed for third persons.

To avoid/prevent this behavior we recommend use `Config ignore` module, where
you can add all settings you do not want to export/import via configuration
To avoid/prevent this behavior, we recommend use `Config ignore` module, where
you can add all settings you do not want to export/import via the configuration
management system.
25 changes: 25 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,30 @@
"type": "composer",
"url": "https://asset-packagist.org"
}
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"drupal/coder": "^8.3",
"phpunit/phpunit": "^9.5",
"os2web/os2web_audit": "^0.1"
},
"scripts": {
"coding-standards-check/phpcs": [
"phpcs --standard=phpcs.xml.dist"
],
"coding-standards-check": [
"@coding-standards-check/phpcs"
],
"coding-standards-apply/phpcs": [
"phpcbf --standard=phpcs.xml.dist"
],
"coding-standards-apply": [
"@coding-standards-apply/phpcs"
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
2 changes: 2 additions & 0 deletions os2web_datalookup.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ type: module
description: 'Provides integration with Danish data lookup services such as Service platformen or Datafordeler.'
package: 'OS2web'
core_version_requirement: ^8 || ^9 || ^10
dependencies:
- 'os2web:os2web_audit'
11 changes: 8 additions & 3 deletions os2web_datalookup.install
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<?php

/**
* @file
* Install, uninstall and update hooks for the module.
*/

use Drupal\os2web_datalookup\Form\DataLookupPluginGroupSettingsForm;

/**
* Setting "serviceplatformen_cpr_extended" as default CPR lookup plugin.
*/
function os2web_datalookup_update_9001() {
function os2web_datalookup_update_9001(): void {
$config = \Drupal::service('config.factory')->getEditable(DataLookupPluginGroupSettingsForm::$configName);
$config->set("cpr_lookup.default_plugin", 'serviceplatformen_cpr_extended');
$config->save();
Expand All @@ -14,7 +19,7 @@ function os2web_datalookup_update_9001() {
/**
* Setting "datafordeler_cvr" as default CVR lookup plugin.
*/
function os2web_datalookup_update_9002() {
function os2web_datalookup_update_9002(): void {
$config = \Drupal::service('config.factory')->getEditable(DataLookupPluginGroupSettingsForm::$configName);
$config->set("cvr_lookup.default_plugin", 'datafordeler_cvr');
$config->save();
Expand All @@ -23,7 +28,7 @@ function os2web_datalookup_update_9002() {
/**
* Setting "datafordeler_pnumber" as default P-Number lookup plugin.
*/
function os2web_datalookup_update_9003() {
function os2web_datalookup_update_9003(): void {
$config = \Drupal::service('config.factory')->getEditable(DataLookupPluginGroupSettingsForm::$configName);
$config->set("pnumber_lookup.default_plugin", 'datafordeler_pnumber');
$config->save();
Expand Down
23 changes: 23 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="PHP_CodeSniffer">
<description>OS2web Datalookup PHP Code Sniffer configuration</description>

<file>.</file>
<exclude-pattern>vendor/</exclude-pattern>
<exclude-pattern>node_modules/</exclude-pattern>

<!-- Show progress of the run -->
<arg value="p"/>

<arg name="extensions" value="php,module,inc,install,test,profile,theme,css,info,txt,yml"/>
<config name="drupal_core_version" value="9"/>


<rule ref="Drupal">
<!-- We want to be able to use "package" and "version" in our custom modules -->
<exclude name="Drupal.InfoFiles.AutoAddedKeys.Project"/>
<exclude name="Drupal.InfoFiles.AutoAddedKeys.Version"/>
</rule>

<rule ref="DrupalPractice"/>
</ruleset>
13 changes: 7 additions & 6 deletions src/Annotation/DataLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\os2web_datalookup\Annotation;

use Drupal\Component\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;

/**
* Defines a AuthProvider annotation object.
Expand All @@ -22,7 +23,7 @@ class DataLookup extends Plugin {
*
* @var string
*/
public $id;
public string $id;

/**
* The human-readable name of the consent storage.
Expand All @@ -31,24 +32,24 @@ class DataLookup extends Plugin {
*
* @ingroup plugin_translatable
*/
public $label;
public Translation $label;

/**
* A brief description of the consent storage.
*
* This will be shown when adding or configuring this consent storage.
*
* @var \Drupal\Core\Annotation\Translation
* @var \Drupal\Core\Annotation\Translation|string
*
* @ingroup plugin_translatable
*/
public $description = '';
public Translation|string $description = '';

/**
* Group of the plugin lookup plugin.
* Group of the plugin lookup plugins.
*
* @var string
*/
public $group = '';
public string $group = '';

}
19 changes: 13 additions & 6 deletions src/Controller/DatalookupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Link;
use Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Class DatalookupController.
* Data lookup controller.
*
* @package Drupal\os2web_datalookup\Controller
*/
Expand All @@ -20,10 +19,13 @@ class DatalookupController extends ControllerBase {
*
* @var \Drupal\Component\Plugin\PluginManagerInterface
*/
protected $manager;
protected PluginManagerInterface $manager;

/**
* {@inheritdoc}
* Default constructor.
*
* @param \Drupal\Component\Plugin\PluginManagerInterface $manager
* The plugin manger.
*/
public function __construct(PluginManagerInterface $manager) {
$this->manager = $manager;
Expand All @@ -40,8 +42,13 @@ public static function create(ContainerInterface $container) {

/**
* Status list callback.
*
* @return array<string, mixed>
* An render array.
*
* @throws \Drupal\Component\Plugin\Exception\PluginException
*/
public function statusList() {
public function statusList(): array {
$headers = [
'title' => $this
->t('Title'),
Expand All @@ -55,7 +62,7 @@ public function statusList() {

$rows = [];
foreach ($this->manager->getDefinitions() as $id => $plugin_definition) {
/** @var DataLookupInterface $plugin */
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface $plugin */
$plugin = $this->manager->createInstance($id);
$status = $plugin->getStatus();
$rows[$id] = [
Expand Down
Loading

0 comments on commit 9126c98

Please sign in to comment.