-
-
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 (#32)
* feat: support gdpr export, anonymize and deletion * Apply fixes from StyleCI * php versions * fix: phpstan errors --------- Co-authored-by: StyleCI Bot <[email protected]>
- Loading branch information
1 parent
a4ce369
commit 71a46ad
Showing
5 changed files
with
73 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
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,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/ban-ips. | ||
* | ||
* Copyright (c) FriendsOfFlarum. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
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/ip-{$bannedIp->id}.json" => $this->encodeForExport($this->sanitize($bannedIp))]; | ||
}); | ||
|
||
return $exportData; | ||
} | ||
|
||
public function sanitize(BannedIP $bannedIP): array | ||
{ | ||
return Arr::except($bannedIP->toArray(), ['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(); | ||
} | ||
} |