-
-
Notifications
You must be signed in to change notification settings - Fork 11
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, erasure (#69)
* feat: support gdpr export, erasure * Apply fixes from StyleCI * chore: set php versions * newline --------- Co-authored-by: StyleCI Bot <[email protected]>
- Loading branch information
1 parent
12db387
commit a4b36e0
Showing
5 changed files
with
85 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,66 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/follow-tags. | ||
* | ||
* Copyright (c) FriendsOfFlarum. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FoF\FollowTags\Data; | ||
|
||
use Blomstra\Gdpr\Data\Type; | ||
use Flarum\Tags\Tag; | ||
use Flarum\Tags\TagState; | ||
use Illuminate\Support\Arr; | ||
|
||
class TagSubscription extends Type | ||
{ | ||
public function export(): ?array | ||
{ | ||
$exportData = []; | ||
|
||
Tag::query() | ||
->each(function (Tag $tag) use (&$exportData) { | ||
$state = $tag->stateFor($this->user); | ||
$sanitized = $this->sanitize($state); | ||
|
||
// if the sanitized data has more than simply the `tag_id` key, we'll export it | ||
if (count($sanitized) > 1) { | ||
$exportData[] = ["FollowTagSubscription/tag-{$tag->id}.json" => $this->encodeForExport($sanitized)]; | ||
} | ||
}); | ||
|
||
return $exportData; | ||
} | ||
|
||
public function sanitize(TagState $state): array | ||
{ | ||
return Arr::except($state->toArray(), ['user_id', 'marked_as_read_at', 'is_hidden']); | ||
} | ||
|
||
public function anonymize(): void | ||
{ | ||
Tag::query() | ||
->each(function (Tag $tag) { | ||
$state = $tag->stateFor($this->user); | ||
|
||
if ($state->exists) { | ||
$state->subscription = null; | ||
$state->save(); | ||
} | ||
}); | ||
} | ||
|
||
public static function deleteDescription(): string | ||
{ | ||
return self::anonymizeDescription(); | ||
} | ||
|
||
public function delete(): void | ||
{ | ||
$this->anonymize(); | ||
} | ||
} |