Skip to content

Commit

Permalink
Merge pull request #43 from flarum/sm/2.x
Browse files Browse the repository at this point in the history
refactor: flarum 2.0 upgrade
  • Loading branch information
SychO9 authored Dec 9, 2024
2 parents 94e3475 + aac8ef6 commit b7598e9
Show file tree
Hide file tree
Showing 128 changed files with 3,096 additions and 9,908 deletions.
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,52 +30,42 @@
->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)
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

0 comments on commit b7598e9

Please sign in to comment.