Skip to content

Commit

Permalink
Export core user data by "Legal" module
Browse files Browse the repository at this point in the history
  • Loading branch information
yurabakhtin committed Sep 11, 2024
1 parent b29237a commit ab92cb2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
36 changes: 36 additions & 0 deletions Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -157,4 +167,30 @@ private static function addModuleNotFoundRoutes($moduleId)
['pattern' => "{$moduleId}/<tmpParam:.*>", '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());
}
}
}
7 changes: 3 additions & 4 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']],
],
];
?>
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ab92cb2

Please sign in to comment.