From 8eaf18ebe6814d195880ede5e67bbb1616f0b22c Mon Sep 17 00:00:00 2001 From: Levin Date: Sat, 30 Nov 2024 00:26:25 +0100 Subject: [PATCH] Add remaining exporters --- .../Exporters/AppsExporter.php | 17 ++++++ .../Exporters/Base/RelationExportable.php | 36 +++++++++++ .../Exporters/HomeExporter.php | 17 ++++++ .../Exporters/IcsTokenExporter.php | 17 ++++++ .../Exporters/LikesExporter.php | 17 ++++++ .../Exporters/NotificationsExporter.php | 17 ++++++ .../Exporters/PermissionExporter.php | 17 ++++++ .../Exporters/RoleExporter.php | 17 ++++++ .../Exporters/SessionExporter.php | 17 ++++++ .../Exporters/SocialProfileExporter.php | 18 ++++++ .../Exporters/StatusExporter.php | 11 ++-- .../Exporters/TokenExporter.php | 17 ++++++ .../Exporters/UserDataExporter.php | 27 ++++++++ .../Exporters/WebhookExporter.php | 27 ++++++++ .../UserGdprDataService.php | 61 ++++++++----------- 15 files changed, 293 insertions(+), 40 deletions(-) create mode 100644 app/Services/PersonalDataSelection/Exporters/AppsExporter.php create mode 100644 app/Services/PersonalDataSelection/Exporters/Base/RelationExportable.php create mode 100644 app/Services/PersonalDataSelection/Exporters/HomeExporter.php create mode 100644 app/Services/PersonalDataSelection/Exporters/IcsTokenExporter.php create mode 100644 app/Services/PersonalDataSelection/Exporters/LikesExporter.php create mode 100644 app/Services/PersonalDataSelection/Exporters/NotificationsExporter.php create mode 100644 app/Services/PersonalDataSelection/Exporters/PermissionExporter.php create mode 100644 app/Services/PersonalDataSelection/Exporters/RoleExporter.php create mode 100644 app/Services/PersonalDataSelection/Exporters/SessionExporter.php create mode 100644 app/Services/PersonalDataSelection/Exporters/SocialProfileExporter.php create mode 100644 app/Services/PersonalDataSelection/Exporters/TokenExporter.php create mode 100644 app/Services/PersonalDataSelection/Exporters/UserDataExporter.php create mode 100644 app/Services/PersonalDataSelection/Exporters/WebhookExporter.php diff --git a/app/Services/PersonalDataSelection/Exporters/AppsExporter.php b/app/Services/PersonalDataSelection/Exporters/AppsExporter.php new file mode 100644 index 000000000..b1072e604 --- /dev/null +++ b/app/Services/PersonalDataSelection/Exporters/AppsExporter.php @@ -0,0 +1,17 @@ +user->{$this->relation}(); + + if (!empty($this->whereColumn)) { + $condition = $this->whereCondition ?? 'id'; + + $relation->where( + $this->whereColumn, + $this->user->{$condition} + ); + } + + if (!empty($this->with)) { + $relation->with($this->with); + } + + if (!empty($this->columns)) { + return $relation->only($this->columns); + } + + return $relation->get()->toJson(); + } + + protected function onExportValidation(): bool { + return !empty($this->relation); + } +} diff --git a/app/Services/PersonalDataSelection/Exporters/HomeExporter.php b/app/Services/PersonalDataSelection/Exporters/HomeExporter.php new file mode 100644 index 000000000..725f08e25 --- /dev/null +++ b/app/Services/PersonalDataSelection/Exporters/HomeExporter.php @@ -0,0 +1,17 @@ +user->statuses()->with('tags')->get()->toArray(); // todo: columns definieren - } + protected string $relation = 'statuses'; + protected string $with = 'tags'; + // todo: columns } diff --git a/app/Services/PersonalDataSelection/Exporters/TokenExporter.php b/app/Services/PersonalDataSelection/Exporters/TokenExporter.php new file mode 100644 index 000000000..52d54ff43 --- /dev/null +++ b/app/Services/PersonalDataSelection/Exporters/TokenExporter.php @@ -0,0 +1,17 @@ +user->only($this->columns); + } + + protected function onExportValidation(): bool { + return true; + } +} diff --git a/app/Services/PersonalDataSelection/Exporters/WebhookExporter.php b/app/Services/PersonalDataSelection/Exporters/WebhookExporter.php new file mode 100644 index 000000000..ee77b32e8 --- /dev/null +++ b/app/Services/PersonalDataSelection/Exporters/WebhookExporter.php @@ -0,0 +1,27 @@ +user->webhooks()->with('events')->get(); + $webhooks = $webhooks->map(function($webhook) { + return $webhook->only([ + 'oauth_client_id', 'created_at', 'updated_at' + ]); + }); + + return $webhooks->toJson(); + } + + protected function onExportValidation(): bool { + return true; + } +} diff --git a/app/Services/PersonalDataSelection/UserGdprDataService.php b/app/Services/PersonalDataSelection/UserGdprDataService.php index 64468d600..1d84fabb2 100644 --- a/app/Services/PersonalDataSelection/UserGdprDataService.php +++ b/app/Services/PersonalDataSelection/UserGdprDataService.php @@ -2,9 +2,9 @@ namespace App\Services\PersonalDataSelection; -use App\Http\Controllers\Backend\User\TokenController; use App\Models\User; use App\Services\PersonalDataSelection\Exporters\ActivityLogExporter; +use App\Services\PersonalDataSelection\Exporters\AppsExporter; use App\Services\PersonalDataSelection\Exporters\Base\Exporter; use App\Services\PersonalDataSelection\Exporters\BlocksExporter; use App\Services\PersonalDataSelection\Exporters\EventExporter; @@ -14,12 +14,24 @@ use App\Services\PersonalDataSelection\Exporters\FollowsExporter; use App\Services\PersonalDataSelection\Exporters\FollowsRequestsExporter; use App\Services\PersonalDataSelection\Exporters\HafasTripsExporter; +use App\Services\PersonalDataSelection\Exporters\HomeExporter; +use App\Services\PersonalDataSelection\Exporters\IcsTokenExporter; +use App\Services\PersonalDataSelection\Exporters\LikesExporter; use App\Services\PersonalDataSelection\Exporters\MentionExporter; use App\Services\PersonalDataSelection\Exporters\MutesExporter; +use App\Services\PersonalDataSelection\Exporters\NotificationsExporter; use App\Services\PersonalDataSelection\Exporters\PasswordResetsExporter; +use App\Services\PersonalDataSelection\Exporters\PermissionExporter; use App\Services\PersonalDataSelection\Exporters\ReportsExporter; +use App\Services\PersonalDataSelection\Exporters\RoleExporter; +use App\Services\PersonalDataSelection\Exporters\SessionExporter; +use App\Services\PersonalDataSelection\Exporters\SocialProfileExporter; +use App\Services\PersonalDataSelection\Exporters\StatusExporter; +use App\Services\PersonalDataSelection\Exporters\TokenExporter; use App\Services\PersonalDataSelection\Exporters\TrustedUsersExporter; +use App\Services\PersonalDataSelection\Exporters\UserDataExporter; use App\Services\PersonalDataSelection\Exporters\WebhookCreationRequestExporter; +use App\Services\PersonalDataSelection\Exporters\WebhookExporter; use Spatie\PersonalDataExport\PersonalDataSelection; class UserGdprDataService @@ -29,44 +41,13 @@ public function __invoke(PersonalDataSelection $personalDataSelection, User $dat } private function addUserPersonalData(PersonalDataSelection $personalDataSelection, User $userModel): void { - $userData = $userModel->only([ - 'name', 'username', 'home_id', 'private_profile', 'default_status_visibility', - 'default_status_sensitivity', 'prevent_index', 'privacy_hide_days', 'language', - 'timezone', 'friend_checkin', 'likes_enabled', 'points_enabled', 'mapprovider', - 'email', 'email_verified_at', 'privacy_ack_at', - 'last_login', 'created_at', 'updated_at' - ]); - - $webhooks = $userModel->webhooks()->with('events')->get(); - $webhooks = $webhooks->map(function($webhook) { - return $webhook->only([ - 'oauth_client_id', 'created_at', 'updated_at' - ]); - }); - - if ($userModel->avatar && file_exists(public_path('/uploads/avatars/' . $userModel->avatar))) { - $personalDataSelection - ->addFile(public_path('/uploads/avatars/' . $userModel->avatar)); + $personalDataSelection->addFile(public_path('/uploads/avatars/' . $userModel->avatar)); } - $personalDataSelection - ->add('user.json', $userData) - ->add('notifications.json', $userModel->notifications()->get()->toJson()) //TODO: columns definieren - ->add('likes.json', $userModel->likes()->get()->toJson()) //TODO: columns definieren - ->add('social_profile.json', $userModel->socialProfile()->with('mastodonserver')->get()) //TODO: columns definieren - ->add('webhooks.json', $webhooks) - ->add('tokens.json', TokenController::index($userModel)->toJson()) //TODO: columns definieren - ->add('ics_tokens.json', $userModel->icsTokens()->get()->toJson()) //TODO: columns definieren - ->add('apps.json', $userModel->oAuthClients()->get()->toJson()) //TODO: columns definieren - ->add('sessions.json', $userModel->sessions()->get()->toJson()) //TODO: columns definieren - ->add('home.json', $userModel->home()->get()->toJson()) //TODO: columns definieren - ->add('roles.json', $userModel->roles()->get()->toJson()) //TODO: columns definieren - ->add('permissions.json', $userModel->permissions()->get()->toJson()) //TODO: columns definieren - ; $exporter = new Exporter($personalDataSelection, $userModel); $exporter->export([ - //StatusExporter::class, + StatusExporter::class, FollowRequestsExporter::class, FollowsRequestsExporter::class, FollowsExporter::class, @@ -82,6 +63,18 @@ private function addUserPersonalData(PersonalDataSelection $personalDataSelectio EventSuggestionsExporter::class, WebhookCreationRequestExporter::class, MentionExporter::class, + SocialProfileExporter::class, + TokenExporter::class, + IcsTokenExporter::class, + AppsExporter::class, + SessionExporter::class, + NotificationsExporter::class, + LikesExporter::class, + HomeExporter::class, + RoleExporter::class, + PermissionExporter::class, + UserDataExporter::class, + WebhookExporter::class, ]); } }