-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support gdpr export, anonymize and deletion
- Loading branch information
Showing
4 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace FoF\BanIPs\Data; | ||
|
||
use Blomstra\Gdpr\Data\Type; | ||
use FoF\BanIPs\BannedIP; | ||
use Illuminate\Support\Arr; | ||
|
||
class BannedIPData extends Type | ||
{ | ||
public function export(): ?array | ||
{ | ||
$exportData = []; | ||
|
||
BannedIP::query() | ||
->where('user_id', $this->user->id) | ||
->each(function (BannedIP $bannedIp) use (&$exportData) { | ||
$exportData[] = ["bannedIP/{$bannedIp->id}.json" => $this->sanitize($bannedIp)]; | ||
}); | ||
|
||
return $exportData; | ||
} | ||
|
||
public function sanitize(BannedIP $bannedIP): array | ||
{ | ||
return Arr::except($bannedIP, ['id', 'creator_id', 'user_id']); | ||
} | ||
|
||
public function anonymize(): void | ||
{ | ||
BannedIP::query() | ||
->where('user_id', $this->user->id) | ||
->update(['user_id' => null]); | ||
} | ||
|
||
public static function deleteDescription(): string | ||
{ | ||
return self::anonymizeDescription(); | ||
} | ||
|
||
public function delete(): void | ||
{ | ||
$this->anonymize(); | ||
} | ||
} |