Skip to content

Commit 9edd266

Browse files
authored
Merge pull request #8 from nswdpc/feat-ci-files
Automated updates
2 parents c3cd07b + 01f6ec9 commit 9edd266

File tree

13 files changed

+165
-185
lines changed

13 files changed

+165
-185
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: CI
2+
3+
on:
4+
pull_request: null
5+
6+
jobs:
7+
Silverstripe:
8+
name: 'Silverstripe (bundle)'
9+
uses: nswdpc/ci-files/.github/workflows/silverstripe_53_83.yml@v-4
10+
PHPStan:
11+
name: 'PHPStan (analyse)'
12+
uses: nswdpc/ci-files/.github/workflows/phpstan.silverstripe_83.yml@v-4
13+
needs: Silverstripe

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
/vendor/
33
.DS_Store
44
/.php-cs-fixer.cache
5+
/.phpactor.json
6+
/app/
7+
/public/
8+
/composer.lock

.php-cs-fixer.dist.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Datawrapper support for Silverstripe
22

3-
This module provides an iframe element to embed [Datawrapper](https://datawrapper.de) charts and maps on a page, along with the script to enable responsiveness.
3+
This module provides an iframe element to embed [Datawrapper](https://datawrapper.de) charts and maps on a page, as an Elemental content block, along with the script to enable responsiveness.
44

55
### Features
66

@@ -15,7 +15,7 @@ See [composer.json](./composer.json)
1515

1616
## Installation
1717

18-
```
18+
```sh
1919
composer require nswdpc/silverstripe-datawrapper
2020
```
2121

@@ -25,34 +25,27 @@ composer require nswdpc/silverstripe-datawrapper
2525

2626
## Documentation
2727

28-
2928
Further [documentation for content authors](./docs/en/001_index.md) is available.
3029

3130
## Configuration
3231

33-
### Webhooks
32+
### Enable the element
3433

35-
```yaml
36-
Name: 'app-datawrapper'
37-
After:
38-
- '#nswdpc-datawrapper'
39-
NSWDPC\Datawrapper\WebhookController:
40-
webhooks_enabled: true|false
41-
webhooks_random_code: 'a random unguessable code'
42-
```
34+
Add the following to a project configuration,e.g. 'app/_config/datawrapper.yml` to enable the content block on Page records:
4335

44-
If you are using Datwrapper custom webhooks, add a `webhooks_random_code` value.
45-
46-
As there is no shared webhook signing key, anyone with the webhook URL and the Datawrapper Id of an element on your website will be able to publish elements.
47-
You can change this random code at any time but you must ensure the custom webhook URL value at Datawrapper is updated to match.
36+
```yml
37+
Page:
38+
allowed_elements:
39+
- 'NSWDPC\Elemental\Models\Datawrapper\ElementDatawrapper'
40+
```
4841
49-
You can set elements to ignore webhook publishing requests by unchecking the "Auto publish" value on an element.
42+
### Webhooks
5043
51-
Datawrapper custom webhook URLs are Team-based. Only charts in that team will receive a webhook request when they are published.
44+
[See webhooks documentation](./docs/en/002_webhooks.md) for further information.
5245
5346
## Maintainers
5447
55-
+ [dpcdigital@NSWDPC:~$](https://dpc.nsw.gov.au)
48+
+ PD Web Team
5649
5750
## Bugtracker
5851

composer.json

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"authors": [
1616
{
1717
"name": "James Ellis",
18-
"homepage": "https://dpc.nsw.gov.au",
1918
"role": "Developer"
2019
}
2120
],
@@ -26,7 +25,13 @@
2625
},
2726
"require-dev": {
2827
"phpunit/phpunit": "^9.5",
29-
"friendsofphp/php-cs-fixer": "^3"
28+
"friendsofphp/php-cs-fixer": "^3",
29+
"cambis/silverstripe-rector": "^2",
30+
"cambis/silverstan": "^2",
31+
"nswdpc/ci-files": "dev-v-4",
32+
"phpstan/phpstan": "^2",
33+
"phpstan/phpstan-phpunit": "^2",
34+
"rector/rector": "^2"
3035
},
3136
"autoload": {
3237
"psr-4": {
@@ -44,9 +49,23 @@
4449
]
4550
}
4651
},
52+
"scripts": {
53+
"phpstan-analyse": "./vendor/bin/phpstan analyse --ansi --no-progress --no-interaction --configuration vendor/nswdpc/ci-files/phpstan/.phpstan.silverstripe.neon src/ tests/",
54+
"rector-dryrun": "./vendor/bin/rector process --dry-run --ansi --config vendor/nswdpc/ci-files/rector/.rector.silverstripe_53_83.php src/ tests/",
55+
"rector-process": "./vendor/bin/rector process --no-diffs --ansi --config vendor/nswdpc/ci-files/rector/.rector.silverstripe_53_83.php src/ tests/",
56+
"phpcsfixer-fix": "./vendor/bin/php-cs-fixer fix --ansi --no-interaction --config vendor/nswdpc/ci-files/php-cs-fixer/.php-cs-fixer.php src/ tests/"
57+
},
4758
"extra": {
4859
"expose": [
4960
"client/static"
5061
]
62+
},
63+
"config": {
64+
"allow-plugins": {
65+
"composer/installers": true,
66+
"silverstripe/vendor-plugin": true,
67+
"silverstripe/recipe-plugin": true,
68+
"phpstan/extension-installer": true
69+
}
5170
}
5271
}

docs/en/001_index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Documentation
22

3+
> This requires the Datawrapper content block to be enabled by a developer.
4+
35
## How to create a element
46

57
> Audience: content editors, authors and creators
@@ -19,7 +21,10 @@ In the "Share & Embed" section on your chart/map:
1921
* You will see a URL like "https://datawrapper.dwcdn.net/abcd1/5/"
2022

2123
<img src="../img/url.png" alt="image showing URL to be copied per instructions" style="border:1px solid #000;">
24+
25+
## Page editing
2226

27+
Add a "Datawrapper visualisation" content block to the Page.
2328

2429
In the "Datawrapper" CMS element you have created, add the URL value provided. You can right click and copy the URL then paste it in the field.
2530

@@ -43,4 +48,6 @@ To update the version on your website, simply set the "Datawrapper version" fiel
4348

4449
Then save the element to review changes or, optionally, publish.
4550

51+
## Automatic updates on publish
52+
4653
See [webhook setup for options to automatically publish](.002_webhooks.md).

docs/en/002_webhooks.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ POST /webhook HTTP/1.1
2323
content-type: application/json
2424
content-length: 32
2525
26-
{"id":"abcd1","publicVersion":6}
26+
{"id":"abcd1","publicVersion":6, "user":{"id":123,"email":"user@your-org.com"}}
2727
```
2828

2929
You can use a system such as Pipedream to inspect and debug webhook requests.
@@ -33,12 +33,19 @@ You can use a system such as Pipedream to inspect and debug webhook requests.
3333

3434
Turn off|on via project configuration, the default is `true`
3535

36-
```yaml
37-
NSWDPC\Datawrapper\Webhook:
38-
webhooks_enabled: true|false
36+
```yml
37+
---
38+
Name: app-datawrapper
39+
After:
40+
- '#nswdpc-datawrapper'
41+
---
42+
NSWDPC\Datawrapper\WebHookController:
43+
webhooks_enabled: true
3944
webhooks_random_code: 'some_random_code_string'
4045
```
4146
4247
Use `webhooks_random_code` to randomise the URL. Using this example, the submission URL will look something like `https://mysite.example.com/_datawrapperwebhook/submit/some_random_code_string/`
4348

4449
This is empty by default. It's a good idea to have this value set as anyone who knows the URL and a Datawrapper chart ID you are using will be able to submit webhook requests.
50+
51+
To invalidate webhook requests, change the `webhooks_random_code` value and flush the configuration. Any webhooks configured at DataWrapper will need to be updated in this event.

phpunit.xml.dist

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
2-
<testsuite name="nswdpc/silverstripe-datawrapper">
3-
<directory>tests/</directory>
4-
</testsuite>
5-
<filter>
6-
<whitelist addUncoveredFilesFromWhitelist="true">
7-
<directory suffix=".php">src/</directory>
8-
<exclude>
9-
<directory suffix=".php">tests/</directory>
10-
</exclude>
11-
</whitelist>
12-
</filter>
1+
<?xml version="1.0"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage includeUncoveredFiles="true">
4+
<include>
5+
<directory suffix=".php">src/</directory>
6+
</include>
7+
<exclude>
8+
<directory suffix=".php">tests/</directory>
9+
</exclude>
10+
</coverage>
11+
<testsuite name="nswdpc/silverstripe-datawrapper">
12+
<directory>tests/</directory>
13+
</testsuite>
1314
</phpunit>

0 commit comments

Comments
 (0)