Skip to content

Commit

Permalink
feat: Add support for GDPR exports (#349)
Browse files Browse the repository at this point in the history
* feat: add support for blomstra/gdpr

* Bump js deps, modify default downloader

* Apply fixes from StyleCI

* chore: disable ts for now

---------

Co-authored-by: StyleCI Bot <bot@styleci.io>
  • Loading branch information
imorland and StyleCIBot committed Oct 12, 2023
1 parent 0e82c49 commit 57ddc06
Show file tree
Hide file tree
Showing 12 changed files with 2,414 additions and 633 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: FoF Upload PHP

on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main
with:
enable_backend_testing: false

backend_directory: .
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Javascript
name: FoF Upload JS

on: [workflow_dispatch, push, pull_request]

Expand All @@ -14,5 +14,6 @@ jobs:
backend_directory: .
js_package_manager: npm
main_git_branch: master

secrets:
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
19 changes: 15 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
"name": "fof/upload",
"description": "The file upload extension for the Flarum forum with insane intelligence.",
"keywords": [
"upload", "uploader",
"upload",
"uploader",
"flarum",
"file", "image", "video", "document"
"file",
"image",
"video",
"document"
],
"type": "flarum-extension",
"license": "MIT",
Expand All @@ -31,7 +35,7 @@
"php": ">=8.0",
"ext-json": "*",
"enshrined/svg-sanitize": "^0.15.4",
"flarum/core": "^1.2.0",
"flarum/core": "^1.8.0",
"guzzlehttp/guzzle": "^6.0 || ^7.0",
"ramsey/uuid": "^3.5.2 || ^4",
"softcreatr/php-mime-detector": "^3.0"
Expand All @@ -45,7 +49,8 @@
},
"require-dev": {
"league/flysystem-aws-s3-v3": "^1.0",
"overtrue/flysystem-qiniu": "1.0.4"
"overtrue/flysystem-qiniu": "1.0.4",
"blomstra/gdpr": "@beta"
},
"extra": {
"flarum-extension": {
Expand All @@ -59,6 +64,12 @@
},
"flagrow": {
"discuss": "https://discuss.flarum.org/d/4154"
},
"flarum-cli": {
"modules": {
"githubActions": true,
"typescript": true
}
}
},
"autoload": {
Expand Down
6 changes: 6 additions & 0 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace FoF\Upload;

use Blomstra\Gdpr\Extend\UserData;
use Flarum\Api\Serializer\CurrentUserSerializer;
use Flarum\Api\Serializer\ForumSerializer;
use Flarum\Api\Serializer\UserSerializer;
Expand Down Expand Up @@ -85,4 +86,9 @@

(new Extend\ErrorHandling())
->handler(InvalidUploadException::class, ExceptionHandler::class),

(new Extend\Conditional())
->whenExtensionEnabled('blomstra-gdpr', [
class_exists(UserData::class) ? (new UserData())->addType(Data\Uploads::class) : null,
]),
];
2,919 changes: 2,301 additions & 618 deletions js/package-lock.json

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@
"@flarum/prettier-config": "^1.0.0",
"flarum-tsconfig": "^1.0.2",
"flarum-webpack-config": "^2.0.0",
"webpack": "^5.76.0",
"webpack-cli": "^4.9.2"
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4"
},
"devDependencies": {
"prettier": "^2.6.0"
"prettier": "^3.0.3",
"flarum-tsconfig": "^1.0.2",
"typescript": "^4.5.4",
"typescript-coverage-report": "^0.6.1"
},
"scripts": {
"dev": "webpack --mode development --watch",
"build": "webpack --mode production",
"format": "prettier --write src",
"format-check": "prettier --check src"
"format-check": "prettier --check src",
"clean-typings": "npx rimraf dist-typings && mkdir dist-typings",
"build-typings": "npm run clean-typings && ([ -e src/@types ] && cp -r src/@types dist-typings/@types || true) && tsc && npm run post-build-typings",
"post-build-typings": "find dist-typings -type f -name '*.d.ts' -print0 | xargs -0 sed -i 's,../src/@types,@types,g'",
"check-typings": "tsc --noEmit --emitDeclarationOnly false",
"check-typings-coverage": "typescript-coverage-report"
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion js/src/admin/index.js → js/src/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import UploadPage from './components/UploadPage';

export * from './components';

app.initializers.add('fof-upload', (app) => {
app.initializers.add('fof-upload', () => {
app.extensionData
.for('fof-upload')
.registerPage(UploadPage)
Expand Down
12 changes: 10 additions & 2 deletions js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@
// This will match all .ts, .tsx, .d.ts, .js, .jsx files in your `src` folder
// and also tells your Typescript server to read core's global typings for
// access to `dayjs` and `$` in the global namespace.
"include": ["src/**/*", "../vendor/flarum/core/js/dist-typings/@types/**/*"],
"include": [
"src/**/*",
"../vendor/*/*/js/dist-typings/@types/**/*",
// <CUSTOM-1>
// </CUSTOM-1>
"@types/**/*"
],
"compilerOptions": {
// This will output typings to `dist-typings`
"declarationDir": "./dist-typings",
"baseUrl": ".",
"paths": {
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"]
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"],
// <CUSTOM-2>
// </CUSTOM-2>
}
}
}
54 changes: 54 additions & 0 deletions src/Data/Uploads.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/*
* This file is part of fof/upload.
*
* Copyright (c) FriendsOfFlarum.
* Copyright (c) Flagrow.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FoF\Upload\Data;

use Blomstra\Gdpr\Data\Type;
use FoF\Upload\Downloader\DefaultDownloader;
use FoF\Upload\File;
use PhpZip\ZipFile;

class Uploads extends Type
{
public function export(ZipFile $zip): void
{
/** @var DefaultDownloader $downloader */
$downloader = resolve(DefaultDownloader::class);

File::query()
->where('actor_id', $this->user->id)
->orderBy('id', 'asc')
->each(function (File $file) use ($zip, $downloader) {
$fileContent = $downloader->download($file)->getBody()->getContents();
$zip->addFromString(
"uploads/{$file->path}",
$fileContent
);
});
}

public function anonymize(): void
{
File::query()
->where('user_id', $this->user->id)
->update([
'actor_id' => null,
]);
}

public function delete(): void
{
File::query()
->where('user_id', $this->user->id)
->delete();
}
}
2 changes: 1 addition & 1 deletion src/Downloader/DefaultDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function forFile(File $file)
*
* @return ResponseInterface
*/
public function download(File $file, Download $command): ResponseInterface
public function download(File $file, ?Download $command = null): ResponseInterface
{
if ($file->upload_method === 'local') {
return $this->retrieveFromLocal($file);
Expand Down
3 changes: 1 addition & 2 deletions src/Events/File/WillBeDownloaded.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public function __construct(
public File $file,
public &$response,
public ?Download $download = null
)
{
) {
}
}

0 comments on commit 57ddc06

Please sign in to comment.