Skip to content

Commit

Permalink
Add remaining exporters
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrLevin committed Nov 29, 2024
1 parent ddc0688 commit 8eaf18e
Show file tree
Hide file tree
Showing 15 changed files with 293 additions and 40 deletions.
17 changes: 17 additions & 0 deletions app/Services/PersonalDataSelection/Exporters/AppsExporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Services\PersonalDataSelection\Exporters;

use App\Services\PersonalDataSelection\Exporters\Base\AbstractExporter;
use App\Services\PersonalDataSelection\Exporters\Base\RelationExportable;

class AppsExporter extends AbstractExporter
{
use RelationExportable;

protected string $fileName = 'apps.json';
protected string $relation = 'oAuthClients';
// todo: columns
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace App\Services\PersonalDataSelection\Exporters\Base;

trait RelationExportable
{
protected function exportData(): string|array {

$relation = $this->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);
}
}
17 changes: 17 additions & 0 deletions app/Services/PersonalDataSelection/Exporters/HomeExporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Services\PersonalDataSelection\Exporters;

use App\Services\PersonalDataSelection\Exporters\Base\AbstractExporter;
use App\Services\PersonalDataSelection\Exporters\Base\RelationExportable;

class HomeExporter extends AbstractExporter
{
use RelationExportable;

protected string $fileName = 'home.json';
protected string $relation = 'home';
// todo: columns
}
17 changes: 17 additions & 0 deletions app/Services/PersonalDataSelection/Exporters/IcsTokenExporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Services\PersonalDataSelection\Exporters;

use App\Services\PersonalDataSelection\Exporters\Base\AbstractExporter;
use App\Services\PersonalDataSelection\Exporters\Base\RelationExportable;

class IcsTokenExporter extends AbstractExporter
{
use RelationExportable;

protected string $fileName = 'ics_tokens.json';
protected string $relation = 'icsTokens';
// todo: columns
}
17 changes: 17 additions & 0 deletions app/Services/PersonalDataSelection/Exporters/LikesExporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Services\PersonalDataSelection\Exporters;

use App\Services\PersonalDataSelection\Exporters\Base\AbstractExporter;
use App\Services\PersonalDataSelection\Exporters\Base\RelationExportable;

class LikesExporter extends AbstractExporter
{
use RelationExportable;

protected string $fileName = 'likes.json';
protected string $relation = 'likes';
// todo: columns
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Services\PersonalDataSelection\Exporters;

use App\Services\PersonalDataSelection\Exporters\Base\AbstractExporter;
use App\Services\PersonalDataSelection\Exporters\Base\RelationExportable;

class NotificationsExporter extends AbstractExporter
{
use RelationExportable;

protected string $fileName = 'notifications.json';
protected string $relation = 'notifications';
// todo: columns
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Services\PersonalDataSelection\Exporters;

use App\Services\PersonalDataSelection\Exporters\Base\AbstractExporter;
use App\Services\PersonalDataSelection\Exporters\Base\RelationExportable;

class PermissionExporter extends AbstractExporter
{
use RelationExportable;

protected string $fileName = 'permissions.json';
protected string $relation = 'permissions';
// todo: columns
}
17 changes: 17 additions & 0 deletions app/Services/PersonalDataSelection/Exporters/RoleExporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Services\PersonalDataSelection\Exporters;

use App\Services\PersonalDataSelection\Exporters\Base\AbstractExporter;
use App\Services\PersonalDataSelection\Exporters\Base\RelationExportable;

class RoleExporter extends AbstractExporter
{
use RelationExportable;

protected string $fileName = 'roles.json';
protected string $relation = 'roles';
// todo: columns
}
17 changes: 17 additions & 0 deletions app/Services/PersonalDataSelection/Exporters/SessionExporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Services\PersonalDataSelection\Exporters;

use App\Services\PersonalDataSelection\Exporters\Base\AbstractExporter;
use App\Services\PersonalDataSelection\Exporters\Base\RelationExportable;

class SessionExporter extends AbstractExporter
{
use RelationExportable;

protected string $fileName = 'sessions.json';
protected string $relation = 'sessions';
// todo: columns
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App\Services\PersonalDataSelection\Exporters;

use App\Services\PersonalDataSelection\Exporters\Base\AbstractExporter;
use App\Services\PersonalDataSelection\Exporters\Base\RelationExportable;

class SocialProfileExporter extends AbstractExporter
{
use RelationExportable;

protected string $fileName = 'social_profiles.json';
protected string $relation = 'socialProfile';
protected string $with = 'mastodonserver';
// todo: columns
}
11 changes: 5 additions & 6 deletions app/Services/PersonalDataSelection/Exporters/StatusExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
namespace App\Services\PersonalDataSelection\Exporters;

use App\Services\PersonalDataSelection\Exporters\Base\AbstractExporter;
use App\Services\PersonalDataSelection\Exporters\Base\ModelExportable;
use App\Services\PersonalDataSelection\Exporters\Base\RelationExportable;

class StatusExporter extends AbstractExporter
{
use ModelExportable;
use RelationExportable;

protected string $fileName = 'statuses.json';

protected function exportData(): array|string {
return $this->user->statuses()->with('tags')->get()->toArray(); // todo: columns definieren
}
protected string $relation = 'statuses';
protected string $with = 'tags';
// todo: columns
}
17 changes: 17 additions & 0 deletions app/Services/PersonalDataSelection/Exporters/TokenExporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Services\PersonalDataSelection\Exporters;

use App\Services\PersonalDataSelection\Exporters\Base\AbstractExporter;
use App\Services\PersonalDataSelection\Exporters\Base\RelationExportable;

class TokenExporter extends AbstractExporter
{
use RelationExportable;

protected string $fileName = 'tokens.json';
protected string $relation = 'tokens';
// todo: columns
}
27 changes: 27 additions & 0 deletions app/Services/PersonalDataSelection/Exporters/UserDataExporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace App\Services\PersonalDataSelection\Exporters;

use App\Services\PersonalDataSelection\Exporters\Base\AbstractExporter;

class UserDataExporter extends AbstractExporter
{
protected string $fileName = 'user.json';
protected array $columns = [
'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'
];

protected function exportData(): array|string {
return $this->user->only($this->columns);
}

protected function onExportValidation(): bool {
return true;
}
}
27 changes: 27 additions & 0 deletions app/Services/PersonalDataSelection/Exporters/WebhookExporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace App\Services\PersonalDataSelection\Exporters;

use App\Services\PersonalDataSelection\Exporters\Base\AbstractExporter;

class WebhookExporter extends AbstractExporter
{
protected string $fileName = 'webhooks.json';

protected function exportData(): array|string {
$webhooks = $this->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;
}
}
61 changes: 27 additions & 34 deletions app/Services/PersonalDataSelection/UserGdprDataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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,
]);
}
}

0 comments on commit 8eaf18e

Please sign in to comment.