Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions gdpr.module
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@ function _get_module_list_by_type($type) {
function _get_modules() {
$cache = \Drupal::cache()->get('modules.list');

if (!$cache) {
return [];
}

if ($cache->data) {
return $cache->data;
}
Expand Down
29 changes: 29 additions & 0 deletions modules/gdpr_dump/src/Plugin/Gdpr/Sanitizer/DateSanitizer.php
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
Expand Up @@ -3,14 +3,15 @@
namespace Drupal\gdpr_dump\Plugin\Gdpr\Sanitizer;

use Drupal\Component\Utility\Random;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\gdpr_dump\Sanitizer\GdprSanitizerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Class EmailSanitizer.
*
* @GdprSanitizer(
* id = "gpdr_email_sanitizer",
* id = "gdpr_email_sanitizer",
* label = @Translation("Email sanitizer"),
* description=@Translation("Provides sanitation functionality intended to be used for emails.")
* )
Expand Down Expand Up @@ -57,7 +58,7 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritdoc}
*/
public function sanitize($input) {
public function sanitize($input, FieldItemListInterface $field) {
if (empty($input)) {
return $input;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace Drupal\gdpr_dump\Plugin\Gdpr\Sanitizer;

use Drupal\Component\Utility\Random;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\gdpr_dump\Sanitizer\GdprSanitizerBase;

/**
* Class LongTextSanitizer.
*
* @GdprSanitizer(
* id = "gpdr_long_text_sanitizer",
* id = "gdpr_long_text_sanitizer",
* label = @Translation("Long text sanitizer"),
* description=@Translation("Provides sanitation functionality intended to be used for longer text.")
* )
Expand All @@ -32,7 +33,7 @@ class LongTextSanitizer extends GdprSanitizerBase {
*
* @throws \RuntimeException
*/
public function sanitize($input) {
public function sanitize($input, FieldItemListInterface $field) {
if (empty($input)) {
return $input;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace Drupal\gdpr_dump\Plugin\Gdpr\Sanitizer;

use Drupal\Component\Utility\Random;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\gdpr_dump\Sanitizer\GdprSanitizerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Class PasswordSanitizer.
*
* @GdprSanitizer(
* id = "gpdr_password_sanitizer",
* id = "gdpr_password_sanitizer",
* label = @Translation("Password sanitizer"),
* description=@Translation("Provides sanitation functionality intended to be used for passwords.")
* )
Expand Down Expand Up @@ -65,7 +66,7 @@ public static function create(ContainerInterface $container, array $configuratio
* @return int|string
* The sanitized input.
*/
public function sanitize($input) {
public function sanitize($input, FieldItemListInterface $field) {
if (NULL === $this->random) {
$this->random = new Random();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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");
}

$value = '';

if (!empty($input)) {
// Generate a prefixed random string.
$rand = new Random();
$value = "anon_" . $rand->string(4);
// If the value is too long, tirm it.
if (isset($max_length) && strlen($input) > $max_length) {
$value = substr(0, $max_length);
}
}
return $value;
}

}
5 changes: 3 additions & 2 deletions modules/gdpr_dump/src/Plugin/Gdpr/Sanitizer/TextSanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
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 = "gpdr_text_sanitizer",
* id = "gdpr_text_sanitizer",
* label = @Translation("Text sanitizer"),
* description=@Translation("Provides sanitation functionality intended to be used for titles or short text.")
* )
Expand All @@ -30,7 +31,7 @@ class TextSanitizer extends GdprSanitizerBase {
*
* @throws \RuntimeException
*/
public function sanitize($input) {
public function sanitize($input, FieldItemListInterface $field) {
if (empty($input)) {
return $input;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace Drupal\gdpr_dump\Plugin\Gdpr\Sanitizer;

use Drupal\Component\Utility\Random;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\gdpr_dump\Sanitizer\GdprSanitizerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Class UsernameSanitizer.
*
* @GdprSanitizer(
* id = "gpdr_username_sanitizer",
* id = "gdpr_username_sanitizer",
* label = @Translation("Username sanitizer"),
* description=@Translation("Provides sanitation functionality intended to be used for usernames.")
* )
Expand Down Expand Up @@ -54,7 +55,7 @@ public static function create(ContainerInterface $container, array $configuratio
*
* @throws \RuntimeException
*/
public function sanitize($input) {
public function sanitize($input, FieldItemListInterface $field) {
if (empty($input)) {
return $input;
}
Expand Down
8 changes: 8 additions & 0 deletions modules/gdpr_dump/src/Sanitizer/GdprSanitizerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,12 @@ public function get($name) {
return $this->sanitizers[$name];
}


/**
* Gets all sanitizers currently registered.
*/
public function getDefinitions() {
return $this->pluginManager->getDefinitions();
}

}
4 changes: 3 additions & 1 deletion modules/gdpr_dump/src/Sanitizer/GdprSanitizerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Drupal\gdpr_dump\Sanitizer;

use Drupal\Core\Field\FieldItemListInterface;

/**
* Interface GdprSanitizerInterface.
*
Expand All @@ -18,6 +20,6 @@ interface GdprSanitizerInterface {
* @return int|string
* The sanitized input.
*/
public function sanitize($input);
public function sanitize($input, FieldItemListInterface $field);

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public function __construct(

$this->setCacheBackend($cacheBackend, 'gdpr_sanitizer_plugins');
$this->alterInfo('gdpr_sanitizer_info');


}

}
2 changes: 1 addition & 1 deletion modules/gdpr_dump/src/Service/GdprSqlDump.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ protected function sanitizeData() {
* Also add a way to make exceptions
* e.g option for 'don't alter uid 1 name', etc.
*/
$row[$column] = $this->pluginFactory->get($pluginId)->sanitize($row[$column]);
$row[$column] = $this->pluginFactory->get($pluginId)->sanitize($row[$column], NULL);
}
$insertQuery->values($row);
}
Expand Down
49 changes: 37 additions & 12 deletions modules/gdpr_fields/gdpr_fields.module
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ use Drupal\Core\Form\FormStateInterface;
* @todo Check user edit permission for GDPR fields.
*/
function gdpr_fields_form_field_config_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {

/* @var \Drupal\gdpr_dump\Sanitizer\GdprSanitizerFactory $sanitizer_factory */
$sanitizer_factory = \Drupal::service('gdpr_dump.sanitizer_factory');
$sanitizer_definitions = $sanitizer_factory->getDefinitions();
/* @var \Drupal\Core\Field\FieldConfigInterface $field */
$field = $form_state->getFormObject()->getEntity();
// @todo Check that target entity is a content entity.
Expand All @@ -39,13 +43,13 @@ function gdpr_fields_form_field_config_edit_form_alter(&$form, FormStateInterfac
'no' => 'Not',
],
'#default_value' => $field->getThirdPartySetting('gdpr_fields', 'gdpr_fields_rta', 'no'),
'#states' => array(
'visible' => array(
':input[name="gdpr_fields_enabled"]' => array(
'#states' => [
'visible' => [
':input[name="gdpr_fields_enabled"]' => [
'checked' => TRUE,
),
),
),
],
],
],
];

$form['field']['gdpr_fields']['gdpr_fields_rtf'] = [
Expand All @@ -58,14 +62,32 @@ function gdpr_fields_form_field_config_edit_form_alter(&$form, FormStateInterfac
'no' => 'Not',
],
'#default_value' => $field->getThirdPartySetting('gdpr_fields', 'gdpr_fields_rtf', 'no'),
'#states' => array(
'visible' => array(
':input[name="gdpr_fields_enabled"]' => array(
'#states' => [
'visible' => [
':input[name="gdpr_fields_enabled"]' => [
'checked' => TRUE,
),
),
),
],
],
],
];

$sanitizer_options = ['' => ''] + array_map(function ($s) {
return $s['label'];
}, $sanitizer_definitions);

$form['field']['gdpr_fields']['gdpr_fields_sanitizer'] = [
'#type' => 'select',
'#title' => t('Sanitizer to use'),
'#options' => $sanitizer_options,
'#default_value' => $field->getThirdPartySetting('gdpr_fields', 'gdpr_fields_sanitizer', ''),
'#states' => [
'visible' => [
':input[name="gdpr_fields_enabled"]' => ['checked' => TRUE],
':input[name="gdpr_fields_rtf"]' => ['value' => 'anonymise'],
],
],
];

$form['actions']['submit']['#submit'][] = 'gdpr_fields_form_field_config_edit_form_submit';
}

Expand All @@ -87,12 +109,15 @@ function gdpr_fields_form_field_config_edit_form_submit(array $form, FormStateIn
$field->setThirdPartySetting('gdpr_fields', 'gdpr_fields_enabled', TRUE);
$field->setThirdPartySetting('gdpr_fields', 'gdpr_fields_rta', $form_fields['gdpr_fields_rta']);
$field->setThirdPartySetting('gdpr_fields', 'gdpr_fields_rtf', $form_fields['gdpr_fields_rtf']);
$field->setThirdPartySetting('gdpr_fields', 'gdpr_fields_sanitizer', $form_fields['gdpr_fields_sanitizer']);
$field->save();
}
else {
$field->unsetThirdPartySetting('gdpr_fields', 'gdpr_fields_enabled');
$field->unsetThirdPartySetting('gdpr_fields', 'gdpr_fields_rta');
$field->unsetThirdPartySetting('gdpr_fields', 'gdpr_fields_rtf');
$field->unsetThirdPartySetting('gdpr_fields', 'gdpr_fields_sanitizer');

$field->save();
}

Expand Down
15 changes: 14 additions & 1 deletion modules/gdpr_fields/src/GDPRCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,19 @@ 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.
// @todo Remove this once we have solved how to deal with ignored/excluded relationships
if ($related_entity_type == 'gdpr_task') {
continue;
}

if ($type == 'typed_data_entity_relationship') {

@yanniboi yanniboi Mar 14, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, can you stick a @todo in here to remove the gdpr_task specific continue once we have solved the concept of 'ignore/excluded' relationships and entity types.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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);
Expand Down Expand Up @@ -308,6 +314,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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ langcode: en
status: true
dependencies:
config:
- field.field.gdpr_task.gdpr_remove.removal_log
- gdpr_tasks.gdpr_task_type.gdpr_remove
third_party_settings: { }
id: gdpr_task.gdpr_remove.default
Expand Down
Loading