diff --git a/Events.php b/Events.php index 350e958..8c463d1 100644 --- a/Events.php +++ b/Events.php @@ -8,6 +8,16 @@ namespace humhub\modules\rest; use humhub\components\Event; +use humhub\modules\comment\models\Comment; +use humhub\modules\file\models\File; +use humhub\modules\legal\events\UserDataCollectionEvent; +use humhub\modules\like\models\Like; +use humhub\modules\post\models\Post; +use humhub\modules\rest\definitions\CommentDefinitions; +use humhub\modules\rest\definitions\FileDefinitions; +use humhub\modules\rest\definitions\LikeDefinitions; +use humhub\modules\rest\definitions\PostDefinitions; +use humhub\modules\rest\definitions\UserDefinitions; use Yii; class Events @@ -157,4 +167,30 @@ private static function addModuleNotFoundRoutes($moduleId) ['pattern' => "{$moduleId}/", 'route' => "rest/{$moduleId}/{$moduleId}/not-supported"], ]); } + + public static function onLegalModuleUserDataExport(UserDataCollectionEvent $event) + { + $event->addExportData('user', UserDefinitions::getUser($event->user)); + + $event->addExportData('post', array_map(function ($post) { + return PostDefinitions::getPost($post); + }, Post::findAll(['created_by' => $event->user->id]))); + + $event->addExportData('comment', array_map(function ($comment) { + return CommentDefinitions::getComment($comment); + }, Comment::findAll(['created_by' => $event->user->id]))); + + $event->addExportData('like', array_map(function ($like) { + return LikeDefinitions::getLike($like); + }, Like::findAll(['created_by' => $event->user->id]))); + + $files = File::findAll(['created_by' => $event->user->id]); + $event->addExportData('file', array_map(function ($file) { + return FileDefinitions::getFile($file); + }, $files)); + + foreach ($files as $file) { + $event->addExportFile($file->file_name, $file->store->get()); + } + } } diff --git a/config.php b/config.php index 78b1b3e..f8a4212 100644 --- a/config.php +++ b/config.php @@ -8,13 +8,12 @@ use humhub\components\Application; -/** @noinspection MissedFieldInspection */ return [ 'id' => 'rest', 'class' => 'humhub\modules\rest\Module', 'namespace' => 'humhub\modules\rest', 'events' => [ - [Application::class, Application::EVENT_BEFORE_REQUEST, ['\humhub\modules\rest\Events', 'onBeforeRequest']] - ] + [Application::class, Application::EVENT_BEFORE_REQUEST, ['\humhub\modules\rest\Events', 'onBeforeRequest']], + ['humhub\modules\legal\services\ExportService', 'collectUserData', ['humhub\modules\rest\Events', 'onLegalModuleUserDataExport']], + ], ]; -?> \ No newline at end of file diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index d93dd53..c65786f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +0.10.3 (Unreleased) +-------------------------- +- Enh #: Collect user data for Legal module + 0.10.2 (September 5, 2024) -------------------------- - Enh #175: User language will be used by default diff --git a/module.json b/module.json index be97a9e..cfee703 100644 --- a/module.json +++ b/module.json @@ -5,7 +5,7 @@ "keywords": [ "api", "rest" ], - "version": "0.10.2", + "version": "0.10.3", "homepage": "https://github.com/humhub/rest", "humhub": { "minVersion": "1.16"