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

refactor: flarum 2.0 upgrade #43

Merged
merged 37 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e4452a0
chore(2.0): update dependencies
SychO9 Oct 25, 2024
1528e21
chore(2.0): update infrastructure
SychO9 Oct 25, 2024
2151570
chore(2.0): adapt to extending lazy modules
SychO9 Oct 25, 2024
2e104c7
chore(2.0): misc frontend changes
SychO9 Oct 25, 2024
f26591e
chore(2.0): misc backend changes
SychO9 Oct 25, 2024
0bd04c1
chore(2.0): code formatting with prettier
SychO9 Oct 25, 2024
9b82f15
chore: conventional naming to help the tool
SychO9 Oct 26, 2024
9ab645d
chore(2.0): JSON:API changes
SychO9 Oct 27, 2024
edf01a6
chore(2.0): Backend tests + PHPUnit 9 to 11 changes
SychO9 Oct 27, 2024
4985831
chore(2.0): `LESS` code changes
SychO9 Oct 27, 2024
2241425
chore: misc fixes & namespace change
SychO9 Nov 1, 2024
52ed8b5
fix: conventional view namespace
SychO9 Nov 1, 2024
add2dbe
chore(2.0): notification emails now require both plain text and HTML …
SychO9 Nov 1, 2024
73d54db
fix: emails
SychO9 Nov 1, 2024
9d449e6
chore: todo
SychO9 Nov 1, 2024
4e036ee
fix: misc compatibility changes
SychO9 Nov 1, 2024
96d4bd4
feat: set cancellation data
SychO9 Nov 1, 2024
cc56a02
feat: less chances of guessing files even if deleted after 1 day
SychO9 Nov 1, 2024
ff0ec67
chore: component based
SychO9 Nov 2, 2024
9a2caa6
fix
SychO9 Nov 2, 2024
6daac07
fix: cannot replace itself
luceos Nov 2, 2024
9eeeea8
chore: switch to yarn
SychO9 Nov 15, 2024
8bd5aea
chore: move conditional logic to fof/oauth
SychO9 Nov 15, 2024
a4e8ea5
chore: more types
SychO9 Nov 15, 2024
fe1d1bd
chore: misc fixes & changes
SychO9 Nov 15, 2024
1a2bb63
chore: migrate settings to flarum
SychO9 Nov 15, 2024
7fde414
chore: update workflow
SychO9 Nov 15, 2024
9abfe6f
chore: migrate migrations
SychO9 Nov 15, 2024
6128f9c
chore: use UserList userActionItems
SychO9 Nov 15, 2024
30e408e
fix: unable to cancel erasure request after confirmation
SychO9 Nov 15, 2024
c96c8cc
chore: move user-bio tests to fof/user-bio, update header comment
SychO9 Nov 15, 2024
4a6f30f
chore: move modules
SychO9 Nov 15, 2024
785906f
docs: fix install command
SychO9 Nov 15, 2024
f2c5bab
Apply fixes from StyleCI
StyleCIBot Nov 15, 2024
44c4594
chore: no more beta (well technically yes, but..)
SychO9 Dec 9, 2024
7475662
fix
SychO9 Dec 9, 2024
aac8ef6
chore
SychO9 Dec 9, 2024
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
21 changes: 19 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 4
[*.md]
indent_size = 2

[*.{diff,md}]
trim_trailing_whitespace = false

[*.{php,xml,json}]
indent_size = 4

[{tsconfig.json,prettierrc.json}]
indent_size = 2

[*.neon]
indent_style = tab

[{install,update}.php]
indent_size = 2
2 changes: 1 addition & 1 deletion .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@1.x
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@2.x
with:
enable_backend_testing: true
enable_phpstan: true
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@1.x
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@2.x
with:
enable_bundlewatch: false
enable_prettier: true
enable_typescript: false

frontend_directory: ./js
backend_directory: .
js_package_manager: npm
main_git_branch: master
js_package_manager: yarn
main_git_branch: 2.x

secrets:
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ This extension allows users increasing control over their data.

### Requirements

- `flarum/core` - `v1.8.3` or higher
- `PHP` - `8.0` or higher
- `flarum/core` - `v2.0` or higher
- `PHP` - `8.2` or higher

### Installation or update

Install manually with composer:

```sh
composer require blomstra/gdpr:@beta
composer require flarum/gdpr:^2.0.0
```

### Use

All forum users now have a `Personal Data` section within their account settings page:

![image](https://github.com/blomstra/flarum-ext-gdpr/assets/16573496/4e469956-709f-4ba3-a5fe-d3fcb0401b73)
![image](https://github.com/flarum/gdpr/assets/16573496/4e469956-709f-4ba3-a5fe-d3fcb0401b73)

From here, users may self-service export their data from the forum, or start an erasure request. Erasure requests are queued up for admins/moderators to process. Any unprocessed requests that are still pending after 30 days will be processed automatically using the configured default method (Deletion or Anonymization).

Expand All @@ -36,7 +36,7 @@ return [

### For developers

You can easily register a new Data type, remove an existing Data type, or exclude specific columns from the user table during export by leveraging the `Flarum\Gdpr\Extend\UserData` extender. Ensure that you wrap the GDPR extender in a conditional extend, so that forum owners can choose if they want to enable GDPR functionality or not. This functionality requires `flarum/core` `v1.8.3` or higher, so that should be set as your extension's minimum requirement.
You can easily register a new Data type, remove an existing Data type, or exclude specific columns from the user table during export by leveraging the `Flarum\Gdpr\Extend\UserData` extender. Ensure that you wrap the GDPR extender in a conditional extend, so that forum owners can choose if they want to enable GDPR functionality or not. This functionality requires `flarum/core` `v2.0` or higher, so that should be set as your extension's minimum requirement.

#### Registering a new Data Type:

Expand All @@ -49,7 +49,7 @@ use Blomstra\Extend;

return [
(new Extend\Conditional())
->whenExtensionEnabled('blomstra-gdpr', fn () => [
->whenExtensionEnabled('flarum-gdpr', fn () => [
(new UserData())
->addType(Your\Own\DataType::class),

Expand All @@ -60,7 +60,7 @@ return [

The implementation you create needs a export method, it will receive a ZipArchive resource.
You can use that to add any strings or actual files to the archive. Make sure to properly
name the file and always prefix it with your extension slug (blomstra-something-filename).
name the file and always prefix it with your extension slug (flarum-something-filename).

#### Removing a Data Type:
If for any reason you want to exclude a certain DataType from the export:
Expand All @@ -70,7 +70,7 @@ use Blomstra\Extend;

return [
(new Extend\Conditional())
->whenExtensionEnabled('blomstra-gdpr', fn () => [
->whenExtensionEnabled('flarum-gdpr', fn () => [
(new UserData())
->removeType(Your\Own\DataType::class),

Expand All @@ -85,7 +85,7 @@ use Blomstra\Gdpr\Extend\UserData;

return [
(new Extend\Conditional())
->whenExtensionEnabled('blomstra-gdpr', fn () => [
->whenExtensionEnabled('flarum-gdpr', fn () => [
(new UserData())
->removeUserColumn('column_name') // For a single column
->removeUserColumns(['column1', 'column2']), // For multiple columns
Expand All @@ -98,16 +98,16 @@ return [

These are the known extensions which offer GDPR data integration with this extension. Don't see a required extension listed? Contact the author to request it

- [2FA](https://github.com/imorland/flarum-ext-twofactor), since `1.0.9`
- [Boring Avatars](https://github.com/imorland/flarum-ext-boring-avatars), since `1.0.0`
- [FoF Ban IPs](https://github.com/FriendsOfFlarum/ban-ips), since `1.1.0`
- [FoF Drafts](https://github.com/FriendsOfFlarum/drafts), since `1.2.8`
- [FoF Follow Tags](https://github.com/FriendsOfFlarum/follow-tags), since `1.2.2`
- [FoF Terms](https://github.com/FriendsOfFlarum/terms), since `1.3.0`
- [FoF Upload](https://github.com/FriendsOfFlarum/upload), since `1.4.4`
- [Follow Users](https://github.com/imorland/follow-users), since `1.4.1`
- [2FA](https://github.com/imorland/flarum-ext-twofactor), since `2.0`
- [Boring Avatars](https://github.com/imorland/flarum-ext-boring-avatars), since `2.0`
- [FoF Ban IPs](https://github.com/FriendsOfFlarum/ban-ips), since `2.0`
- [FoF Drafts](https://github.com/FriendsOfFlarum/drafts), since `2.0`
- [FoF Follow Tags](https://github.com/FriendsOfFlarum/follow-tags), since `2.0`
- [FoF Terms](https://github.com/FriendsOfFlarum/terms), since `2.0`
- [FoF Upload](https://github.com/FriendsOfFlarum/upload), since `2.0`
- [FoF User Bio](https://github.com/FriendsOfFlarum/user-bio), since `2.0`
- [Follow Users](https://github.com/imorland/follow-users), since `2.0`

### FAQ & Recommendations

- Generating the zip archive can be pushed to [queue functionality](https://extiverse.com/?filter[q]=queue). This is exceptionally important on larger communities and with more extensions that work with the gdpr extension to allow data exports.

- Generating the zip archive can be pushed to queue functionality. This is exceptionally important on larger communities and with more extensions that work with the gdpr extension to allow data exports.
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
"source": "https://github.com/flarum/gdpr"
},
"require": {
"php": "8.*",
"flarum/core": "^1.8.3",
"flarum/core": "^2.0.0",
"nelexa/zip": "^4.0.2"
},
"autoload": {
Expand Down Expand Up @@ -95,9 +94,9 @@
"analyse:phpstan": "Run static analysis"
},
"require-dev": {
"flarum/testing": "^1.0.0",
"flarum/nicknames": "^1.8",
"fof/user-bio": "^1.3",
"flarum/testing": "^2.0.0",
"flarum/nicknames": "^2.0.0",
"flarum/phpstan": "*"
}
},
"minimum-stability": "dev"
}
87 changes: 32 additions & 55 deletions extend.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
<?php

/*
* This file is part of blomstra/flarum-gdpr
* This file is part of Flarum.
*
* Copyright (c) 2021 Blomstra Ltd
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

namespace Flarum\Gdpr;

use Flarum\Gdpr\Api\Serializer\ExportSerializer;
use Flarum\Gdpr\Api\Serializer\RequestErasureSerializer;
use Flarum\Gdpr\Models\ErasureRequest;
use Flarum\Api\Controller\ShowUserController;
use Flarum\Api\Serializer\BasicUserSerializer;
use Flarum\Api\Serializer\ForumSerializer;
use Flarum\Api\Serializer\UserSerializer;
use Flarum\Api\Endpoint;
use Flarum\Api\Resource;
use Flarum\Extend;
use Flarum\Gdpr\Models\ErasureRequest;
use Flarum\User\User;

return [
Expand All @@ -36,58 +30,48 @@
->get('/gdpr/export/{file}', 'gdpr.export', Http\Controller\ExportController::class)
->get('/gdpr/erasure/confirm/{token}', 'gdpr.erasure.confirm', Http\Controller\ConfirmErasureController::class),

(new Extend\Routes('api'))
->remove('users.delete')
->delete('/users/{id}', 'users.delete', Api\Controller\DeleteUserController::class)
->delete('/users/{id}/gdpr/{mode}', 'users.delete.mode', Api\Controller\DeleteUserController::class)
->post('/gdpr/export', 'gdpr.request-export', Api\Controller\RequestExportController::class)
->get('/user-erasure-requests', 'gdpr.erasure.index', Api\Controller\ListErasureRequestsController::class)
->post('/user-erasure-requests', 'gdpr.erasure.create', Api\Controller\RequestErasureController::class)
->patch('/user-erasure-requests/{id}', 'gdpr.erasure.process', Api\Controller\ProcessErasureController::class)
->delete('/user-erasure-requests/{id}', 'gdpr.erasure.cancel', Api\Controller\CancelErasureController::class)
->get('/gdpr/datatypes', 'gdpr.datatypes.index', Api\Controller\ListDataTypesController::class)
->get('/gdpr/datatypes/user-columns', 'gdpr.datatypes.user-columns', Api\Controller\ListUserColumnsDataController::class),

(new Extend\Notification())
->type(Notifications\ExportAvailableBlueprint::class, ExportSerializer::class, ['alert', 'email'])
->type(Notifications\ConfirmErasureBlueprint::class, RequestErasureSerializer::class, ['email'])
->type(Notifications\ErasureRequestCancelledBlueprint::class, RequestErasureSerializer::class, ['alert', 'email']),
->type(Notifications\ExportAvailableBlueprint::class, ['alert', 'email'])
->type(Notifications\ConfirmErasureBlueprint::class, ['email'])
->type(Notifications\ErasureRequestCancelledBlueprint::class, ['alert', 'email']),

(new Extend\Model(User::class))
->cast('anonymized', 'boolean')
->hasOne('erasureRequest', ErasureRequest::class),

(new Extend\ApiController(ShowUserController::class))
->addInclude('erasureRequest'),
new Extend\ApiResource(Api\Resource\DataTypeResource::class),
new Extend\ApiResource(Api\Resource\ExportResource::class),
new Extend\ApiResource(Api\Resource\ErasureRequestResource::class),

(new Extend\ApiSerializer(ForumSerializer::class))
->attributes(AddForumAttributes::class),

(new Extend\ApiSerializer(BasicUserSerializer::class))
->attributes(Api\AddBasicUserAttributes::class),

(new Extend\ApiSerializer(UserSerializer::class))
->attribute('canModerateExports', function (UserSerializer $serializer, User $user) {
return $serializer->getActor()->can('exportFor', $user);
(new Extend\ApiResource(Resource\UserResource::class))
->endpoint(Endpoint\Show::class, function (Endpoint\Show $endpoint) {
return $endpoint->addDefaultInclude(['erasureRequest']);
})
->hasOne('erasureRequest', RequestErasureSerializer::class),
->endpoint(Endpoint\Delete::class, Api\UserResourceDeleteEndpoint::class)
->fields(Api\UserResourceFields::class),

(new Extend\ApiResource(Resource\ForumResource::class))
->fields(Api\ForumResourceFields::class)
->endpoint(Endpoint\Show::class, function (Endpoint\Show $endpoint) {
return $endpoint->addDefaultInclude(['actor.erasureRequest']);
}),

(new Extend\Settings())
->default('blomstra-gdpr.allow-anonymization', true)
->default('blomstra-gdpr.allow-deletion', false)
->default('blomstra-gdpr.default-anonymous-username', 'Anonymous')
->default('blomstra-gdpr.default-erasure', ErasureRequest::MODE_ANONYMIZATION)
->serializeToForum('erasureAnonymizationAllowed', 'blomstra-gdpr.allow-anonymization', 'boolVal')
->serializeToForum('erasureDeletionAllowed', 'blomstra-gdpr.allow-deletion', 'boolVal'),
->default('flarum-gdpr.allow-anonymization', true)
->default('flarum-gdpr.allow-deletion', false)
->default('flarum-gdpr.default-anonymous-username', 'Anonymous')
->default('flarum-gdpr.default-erasure', ErasureRequest::MODE_ANONYMIZATION)
->serializeToForum('erasureAnonymizationAllowed', 'flarum-gdpr.allow-anonymization', 'boolVal')
->serializeToForum('erasureDeletionAllowed', 'flarum-gdpr.allow-deletion', 'boolVal'),

(new Extend\View())
->namespace('gdpr', __DIR__.'/resources/views'),
->namespace('flarum-gdpr', __DIR__.'/resources/views'),

(new Extend\Console())
->command(Console\DestroyExportsCommand::class)

Check failure on line 71 in extend.php

View workflow job for this annotation

GitHub Actions / run / PHPStan PHP 8.3

Parameter #1 $command of method Flarum\Extend\Console::command() expects class-string<Flarum\Console\AbstractCommand>, string given.
->command(Console\ProcessEraseRequests::class)

Check failure on line 72 in extend.php

View workflow job for this annotation

GitHub Actions / run / PHPStan PHP 8.3

Parameter #1 $command of method Flarum\Extend\Console::command() expects class-string<Flarum\Console\AbstractCommand>, string given.
->schedule(Console\ProcessEraseRequests::class, Console\DailySchedule::class)

Check failure on line 73 in extend.php

View workflow job for this annotation

GitHub Actions / run / PHPStan PHP 8.3

Parameter #1 $command of method Flarum\Extend\Console::schedule() expects class-string<Flarum\Console\AbstractCommand>, string given.
->schedule(Console\DestroyExportsCommand::class, Console\DailySchedule::class),

Check failure on line 74 in extend.php

View workflow job for this annotation

GitHub Actions / run / PHPStan PHP 8.3

Parameter #1 $command of method Flarum\Extend\Console::schedule() expects class-string<Flarum\Console\AbstractCommand>, string given.

(new Extend\ServiceProvider())
->register(Providers\GdprProvider::class),
Expand All @@ -96,13 +80,6 @@
->disk('gdpr-export', ExportDiskConfig::class),

(new Extend\Policy())
->modelPolicy(User::class, Access\UserPolicy::class),

(new Extend\Conditional())
->whenExtensionEnabled('fof-oauth', fn () => [
(new Extend\ApiSerializer(ForumSerializer::class))
->attribute('passwordlessSignUp', function (ForumSerializer $serializer) {
return !$serializer->getActor()->isGuest() && $serializer->getActor()->loginProviders()->count() > 0;
}),
]),
->modelPolicy(User::class, Access\UserPolicy::class)
->modelPolicy(ErasureRequest::class, Access\ErasureRequestPolicy::class),
];
Loading
Loading