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

WIP: Creating the module #1

Merged
merged 17 commits into from
May 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
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.
137 changes: 137 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
on: pull_request
name: Review
jobs:
changelog:
runs-on: ubuntu-latest
name: Changelog should be updated
strategy:
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 2

- name: Git fetch
run: git fetch

- 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

php-code-analysis:
name: PHP code analysis
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: Code analysis
run: |
./scripts/code-analysis

markdownlint:
runs-on: ubuntu-latest
name: markdownlint
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Cache yarn packages
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Yarn install
uses: actions/setup-node@v2
with:
node-version: '20'
- run: yarn install
- name: markdownlint
run: yarn coding-standards-check/markdownlint
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
composer.lock
vendor/
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- markdownlint-disable MD024 -->
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- First version of the module

[Unreleased]: https://github.com/OS2web/os2web_audit/compare/develop...HEAD
59 changes: 33 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
# OS2Form Audit Module
# OS2Web Audit

OS2Form Audit is a Drupal module that helps track changes and perform audit on
OS2Form events.

## Requirements
-
- PHP 8.1 or higher
- Drupal 8 or 9
- Composer for managing PHP dependencies
This audit module can be used to track changes and perform audit logging on
drupal sites.

## Features
-
- Detailed audit log entries.
- Support for all OS2Form entity types.
- Easily extendable for custom use case.

## Installation
This module includes three plugins that facilitate logging information to Loki,
files, or to the database through Drupal's watchdog logger.

### Composer
These logging providers are designed using Drupal's plugin APIs. Consequently,
it opens up possibilities for creating new AuditLogger plugins within other
modules, thus enhancing the functionality of this audit logging.

### Drush
## Installation

cableman marked this conversation as resolved.
Show resolved Hide resolved
Enable the module and go to the modules setting page at
`/admin/config/os2web_audit/settings/`.

### Admin UI
```shell
composer require os2web/os2web_audit
drush pm:enable os2web_audit
```

Alternatively, you can enable this module via Drupal admin UI by visiting the
extent page (`/admin/modules`).
### Drush

## Configuration
The module provides a Drush command named audit:log. This command enables you
to log a test message to the configured logger. The audit:log command accepts a
string that represents the message to be logged.

Navigate to `/admin/config/os2form/audit` to configure the module.
The message provided, will be logged twice, once as an informational message
and once as an error message.

Some additional (brief) information on Usage, Extending/Overriding, and
Maintainers could go here.
```shell
drush audit:log 'This is a test message'
```

## Usage

Describe how to use this module after installation.
The module exposes a simple `Logger` service which can log an `info` and `error`
messages.

## Extending and Overriding
Inject the logger service named `os2web_audit.logger` and send messages into the
logger as shown below:

Describe how to extend or override this module's functionality.
```php
$msg = sprintf('Fetch personal data from service with parameter: %s', $param);
$this->auditLogger->info('Lookup', $msg);
```
64 changes: 64 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "os2web/os2web_audit",
"type": "drupal-module",
"description": "Drupal OS2 module that provides audit logging for Danish Municipalities",
"minimum-stability": "dev",
"prefer-stable": true,
"license": "EUPL-1.2",
"repositories": {
"drupal": {
"type": "composer",
"url": "https://packages.drupal.org/8"
},
"assets": {
"type": "composer",
"url": "https://asset-packagist.org"
}
},
"require": {
"ext-curl": "*",
"php": "^8.1",
"drush/drush": "^11.6"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
"drupal/coder": "^8.3",
"mglaman/phpstan-drupal": "^1.1",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpunit/phpunit": "^9.5"
},
"extra" : {
"composer-exit-on-patch-failure": false,
"enable-patching" : true,
"patches": {
}
},
"scripts": {
"code-analysis/phpstan": [
"phpstan analyse"
],
"code-analysis": [
"@code-analysis/phpstan"
],
"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": {
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
5 changes: 5 additions & 0 deletions os2web_audit.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: "OS2web Audit"
description: 'OS2web Audit Module (log events in the system)'
type: module
core_version_requirement: ^8 || ^9 || ^10
configure: os2web_audit.plugin_settings_local_tasks
5 changes: 5 additions & 0 deletions os2web_audit.links.menu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
os2web_audit.admin_settings:
title: 'OS2web Audit settings'
parent: system.admin_config_system
description: 'Settings for the OS2 Audit module'
route_name: os2web_audit.plugin_settings_local_tasks
5 changes: 5 additions & 0 deletions os2web_audit.links.task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
os2web_audit.plugin_settings_tasks:
title: 'OS2web Audit settings'
route_name: os2web_audit.plugin_settings_local_tasks
base_route: os2web_audit.plugin_settings_local_tasks
deriver: Drupal\os2web_audit\Plugin\Derivative\LocalTask
8 changes: 8 additions & 0 deletions os2web_audit.routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
os2web_audit.plugin_settings_local_tasks:
path: '/admin/config/os2web_audit/settings/{type}'
defaults:
_controller: '\Drupal\os2web_audit\Controller\LocalTasksController::dynamicTasks'
_title: 'OS2web Audit settings'
type: ''
requirements:
_permission: 'administer site'
14 changes: 14 additions & 0 deletions os2web_audit.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
plugin.manager.os2web_audit_logger:
class: Drupal\os2web_audit\Plugin\LoggerManager
parent: default_plugin_manager

os2web_audit.logger:
class: Drupal\os2web_audit\Service\Logger
arguments: ['@plugin.manager.os2web_audit_logger', '@config.factory', '@current_user', '@logger.factory']

os2web_audit.commands:
class: Drupal\os2web_audit\Commands\AuditLogDrushCommands
arguments: ['@os2web_audit.logger']
tags:
- { name: drush.command }
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"license": "UNLICENSED",
"private": true,
"devDependencies": {
"markdownlint-cli": "^0.32.2"
},
"scripts": {
"coding-standards-check/markdownlint": "yarn markdownlint --ignore LICENSE.md --ignore vendor --ignore node_modules '*.md' 'modules/os2forms_digital_post/**/*.md'",
"coding-standards-check": "yarn coding-standards-check/markdownlint",
"coding-standards-apply/markdownlint": "yarn markdownlint --ignore LICENSE.md --ignore vendor --ignore node_modules '*.md' 'modules/os2forms_digital_post/**/*.md' --fix",
"coding-standards-apply": "yarn coding-standards-apply/markdownlint"
}
}
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 Audit 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>
Loading
Loading