-
Notifications
You must be signed in to change notification settings - Fork 2
Add ability to remove/anonymise user data #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/gdpr-tasks
Are you sure you want to change the base?
Changes from 13 commits
c74d730
e4a9e70
7d5f84c
70f6297
ad47726
82bd0cb
722e8fb
2638016
906259e
aa30efa
8a77cad
dba2706
4a27249
42609c3
a4117aa
a515bb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?php | ||
|
|
||
| namespace Drupal\gdpr_dump\Plugin\Gdpr\Sanitizer; | ||
|
|
||
| use Drupal\Component\Utility\Random; | ||
| use Drupal\Core\Field\FieldItemListInterface; | ||
| use Drupal\gdpr_dump\Sanitizer\GdprSanitizerBase; | ||
|
|
||
| /** | ||
| * Class TextSanitizer. | ||
| * | ||
| * @GdprSanitizer( | ||
| * id = "gdpr_date_sanitizer", | ||
| * label = @Translation("Date sanitizer"), | ||
| * description=@Translation("Provides sanitation functionality intended to be used for datetime fields.") | ||
| * ) | ||
| * | ||
| * @package Drupal\gdpr_dump\Plugin\Gdpr\Sanitizer | ||
| */ | ||
| class DateSanitizer extends GdprSanitizerBase { | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function sanitize($input, FieldItemListInterface $field) { | ||
| return '1000-01-01'; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <?php | ||
|
|
||
| namespace Drupal\gdpr_dump\Plugin\Gdpr\Sanitizer; | ||
|
|
||
| use Drupal\Component\Utility\Random; | ||
| use Drupal\Core\Field\FieldItemListInterface; | ||
| use Drupal\gdpr_dump\Sanitizer\GdprSanitizerBase; | ||
|
|
||
| /** | ||
| * Class TextSanitizer. | ||
| * | ||
| * @GdprSanitizer( | ||
| * id = "gdpr_random_text_sanitizer", | ||
| * label = @Translation("Random Text sanitizer"), | ||
| * description=@Translation("Provides sanitation functionality intended to be | ||
| * used for text fields.") | ||
| * ) | ||
| * | ||
| * @package Drupal\gdpr_dump\Plugin\Gdpr\Sanitizer | ||
| */ | ||
| class RandomTextSanitizer extends GdprSanitizerBase { | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function sanitize($input, FieldItemListInterface $field) { | ||
| if ($field != NULL) { | ||
| $max_length = $field->getDataDefinition()->getSetting("max_length"); | ||
| } | ||
| else { | ||
| $max_length = NULL; | ||
| } | ||
|
|
||
| $value = ''; | ||
|
|
||
| if (!empty($input)) { | ||
| // Generate a prefixed random string. | ||
| $value = "anon_" . $this->generateRandomString(4); | ||
| // If the value is too long, tirm it. | ||
| if (isset($max_length) && strlen($input) > $max_length) { | ||
| $value = substr(0, $max_length); | ||
| } | ||
| } | ||
| return $value; | ||
| } | ||
|
|
||
| /** | ||
| * Generates a random string of the specified length. | ||
| */ | ||
| private function generateRandomString($length) { | ||
| $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
| $charactersLength = strlen($characters); | ||
| $randomString = ''; | ||
| for ($i = 0; $i < $length; $i++) { | ||
| $randomString .= $characters[rand(0, $charactersLength - 1)]; | ||
| } | ||
| return $randomString; | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this you can use
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,13 +140,18 @@ public function getValueEntities(array &$entity_list, $entity_type, EntityInterf | |
|
|
||
|
|
||
| foreach ($definitions as $definition_id => $definition) { | ||
| list($type, $definition_entity, ,) = explode(':', $definition_id); | ||
| list($type, $definition_entity, $related_entity_type,) = explode(':', $definition_id); | ||
|
|
||
| // Ignore entity revisions for now. | ||
| if ($definition_entity == 'entity_revision') { | ||
| continue; | ||
| } | ||
|
|
||
| // Ignore links back to gdpr_task. | ||
| if ($related_entity_type == 'gdpr_task') { | ||
| continue; | ||
| } | ||
|
|
||
| if ($type == 'typed_data_entity_relationship') { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, can you stick a
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| /* @var \Drupal\ctools\Plugin\Relationship\TypedDataEntityRelationship $plugin */ | ||
| $plugin = $this->relationshipManager->createInstance($definition_id); | ||
|
|
@@ -308,6 +313,13 @@ public function fieldValues($entity_type = 'user', EntityInterface $entity, $ext | |
|
|
||
| if ($rtf_value && $rtf_value !== 'no') { | ||
| $fields[$key]['gdpr_rtf'] = $rtf_value; | ||
| // For 'maybes', provide a link to edit the entity. | ||
| if ($rtf_value == 'maybe') { | ||
| $fields[$key]['link'] = $entity->toLink('Edit', 'edit-form'); | ||
| } | ||
| else { | ||
| $fields[$key]['link'] = ''; | ||
| } | ||
| } | ||
| else { | ||
| unset($fields[$key]); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You dont need to explicitly set
$max_lengthto NULL as you are checking forissetlater anyway. Just remove the else.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - that's my C# background coming through!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.