Skip to content

Commit

Permalink
Add all model exporters
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrLevin committed Nov 29, 2024
1 parent ad9e7e0 commit ddc0688
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@

trait ModelExportable
{
protected function exportData(): string {
$condition = $this->whereCondition ?? 'id';

return $this->model::where(
$this->whereColumn,
$this->user->{$condition}
)->get()->toJson();
}

protected function onExportValidation(): bool {
return true;
// todo check for model + columns
return !empty($this->model) && !empty($this->whereColumn);
}
}
18 changes: 18 additions & 0 deletions app/Services/PersonalDataSelection/Exporters/EventExporter.php
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\Models\Event;
use App\Services\PersonalDataSelection\Exporters\Base\AbstractExporter;
use App\Services\PersonalDataSelection\Exporters\Base\ModelExportable;

class EventExporter extends AbstractExporter
{
use ModelExportable;

protected string $fileName = 'events.json';
protected string $model = Event::class;
protected string $whereColumn = 'approved_by';
}
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\Models\EventSuggestion;
use App\Services\PersonalDataSelection\Exporters\Base\AbstractExporter;
use App\Services\PersonalDataSelection\Exporters\Base\ModelExportable;

class EventSuggestionsExporter extends AbstractExporter
{
use ModelExportable;

protected string $fileName = 'event_suggestions.json';
protected string $model = EventSuggestion::class;
protected string $whereColumn = 'user_id';
}
18 changes: 18 additions & 0 deletions app/Services/PersonalDataSelection/Exporters/MentionExporter.php
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\Models\Mention;
use App\Services\PersonalDataSelection\Exporters\Base\AbstractExporter;
use App\Services\PersonalDataSelection\Exporters\Base\ModelExportable;

class MentionExporter extends AbstractExporter
{
use ModelExportable;

protected string $fileName = 'mentions.json';
protected string $model = Mention::class;
protected string $whereColumn = 'mentioned_id';
}
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\Models\WebhookCreationRequest;
use App\Services\PersonalDataSelection\Exporters\Base\AbstractExporter;
use App\Services\PersonalDataSelection\Exporters\Base\ModelExportable;

class WebhookCreationRequestExporter extends AbstractExporter
{
use ModelExportable;

protected string $fileName = 'webhook_creation_requests.json';
protected string $model = WebhookCreationRequest::class;
protected string $whereColumn = 'user_id';
}
24 changes: 10 additions & 14 deletions app/Services/PersonalDataSelection/UserGdprDataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@
namespace App\Services\PersonalDataSelection;

use App\Http\Controllers\Backend\User\TokenController;
use App\Models\Event;
use App\Models\EventSuggestion;
use App\Models\Mention;
use App\Models\User;
use App\Models\WebhookCreationRequest;
use App\Services\PersonalDataSelection\Exporters\ActivityLogExporter;
use App\Services\PersonalDataSelection\Exporters\Base\Exporter;
use App\Services\PersonalDataSelection\Exporters\BlocksExporter;
use App\Services\PersonalDataSelection\Exporters\EventExporter;
use App\Services\PersonalDataSelection\Exporters\EventSuggestionsExporter;
use App\Services\PersonalDataSelection\Exporters\FollowingsExporter;
use App\Services\PersonalDataSelection\Exporters\FollowRequestsExporter;
use App\Services\PersonalDataSelection\Exporters\FollowsExporter;
use App\Services\PersonalDataSelection\Exporters\FollowsRequestsExporter;
use App\Services\PersonalDataSelection\Exporters\HafasTripsExporter;
use App\Services\PersonalDataSelection\Exporters\MentionExporter;
use App\Services\PersonalDataSelection\Exporters\MutesExporter;
use App\Services\PersonalDataSelection\Exporters\PasswordResetsExporter;
use App\Services\PersonalDataSelection\Exporters\ReportsExporter;
use App\Services\PersonalDataSelection\Exporters\StatusExporter;
use App\Services\PersonalDataSelection\Exporters\TrustedUsersExporter;
use App\Services\PersonalDataSelection\Exporters\WebhookCreationRequestExporter;
use Spatie\PersonalDataExport\PersonalDataSelection;

class UserGdprDataService
Expand Down Expand Up @@ -56,25 +55,18 @@ private function addUserPersonalData(PersonalDataSelection $personalDataSelectio
->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('event_suggestions.json', EventSuggestion::where('user_id', $userModel->id)->get()->toJson()) //TODO: columns definieren
->add('events.json', Event::where('approved_by', $userModel->id)->get()->toJson()) //TODO: columns definieren
->add('webhooks.json', $webhooks)
->add(
'webhook_creation_requests.json',
WebhookCreationRequest::where('user_id', $userModel->id)->get()->toJson() //TODO: columns definieren
)
->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('mentions.json', Mention::where('mentioned_id', $userModel->id)->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 @@ -86,6 +78,10 @@ private function addUserPersonalData(PersonalDataSelection $personalDataSelectio
TrustedUsersExporter::class,
ActivityLogExporter::class,
PasswordResetsExporter::class,
EventExporter::class,
EventSuggestionsExporter::class,
WebhookCreationRequestExporter::class,
MentionExporter::class,
]);
}
}

0 comments on commit ddc0688

Please sign in to comment.