-
Notifications
You must be signed in to change notification settings - Fork 1
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
Commit for code review - contains the latest code from d.o. #1
Open
graber-1
wants to merge
5
commits into
master
Choose a base branch
from
7.x-1.x
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cf6dd63
Updated to the last commit from the d.o. repo.
graber-1 a092022
Update to latest.
graber-1 9013dc2
Update to d.o. latest.
graber-1 1bea52f
Updated to d.o. latest.
graber-1 66a8aa8
Issue #2975131 by torgosPizza: Exclude roles in _commerce_gdpr_update…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
TABLE OF CONTENTS | ||
----------------- | ||
|
||
* Introduction | ||
* Requirements | ||
* Installation | ||
* Configuration | ||
|
||
|
||
INTRODUCTION | ||
------------ | ||
|
||
This module helps Drupal Commere sites comply with the EU GDPR directive by | ||
providing means to anonymize user and order data. | ||
Anonymized data can still be used for statistical purposes but will not allow | ||
to identify a person. | ||
The module adds UI for users to anonimize their data and means for the site | ||
administrators to setup automatic anonymization after a defined amount of time. | ||
|
||
|
||
REQUIREMENTS | ||
------------ | ||
|
||
* Order module (commerce_order, included in the Drupal Commerce package | ||
- https://www.drupal.org/project/commerce), | ||
* Chaos tool suite (ctools, also required by Drupal Commerce | ||
- https://www.drupal.org/project/ctools). | ||
|
||
|
||
INSTALLATION | ||
------------ | ||
|
||
* Install as you would normally install a contributed Drupal module. See: | ||
https://drupal.org/documentation/install/modules-themes/modules-7 | ||
for further information. | ||
|
||
|
||
CONFIGURATION | ||
------------- | ||
|
||
1. settings.php | ||
|
||
By default, the module uses md5 algorithm and the $drupal_hash_salt value | ||
for hashing user data. It is strongly advised to change at least the salt | ||
for improved security by including the following code in settings.php: | ||
|
||
<code> | ||
$conf['commerce_gdpr_salt'] = 'some_salt'; | ||
$conf['commerce_gdpr_algo'] = 'some_algo'; | ||
</code> | ||
|
||
For enhanced security, you may set this variable to a value using the | ||
contents of a file outside your docroot that is never saved together | ||
with any backups of your Drupal files and database. | ||
|
||
Example: | ||
<code> | ||
$conf['commerce_gdpr_salt'] = file_get_contents('/home/example/anonimyzation_salt.txt'); | ||
</code> | ||
|
||
The salt needs to be at least 22 characters long and can be generated once using | ||
<code>hash('some_algorithm', mt_rand());</code> | ||
or just entered manually. | ||
|
||
For a list of supported hashing algorithms see | ||
http://php.net/manual/en/function.hash-hmac-algos.php. | ||
|
||
NOTE: Those config values must be entered only once when the module is | ||
installed and should not be changed after data has already been anonimized, | ||
otherwise comparing data from before and after the change will be impossible. | ||
|
||
|
||
2. Admin UI | ||
|
||
To setup the module, go to /admin/commerce/config/commerce-gdpr. | ||
|
||
If automatic anonymization is required, set Order data retention period to | ||
a positive integer value. Also check roles that shouldn't be automatically | ||
anonymized. | ||
|
||
By default, only entity properties are anonimized and automatic anonimization | ||
is switched off. To select entity felds that should also be anonimized and | ||
time after automatic anonymization should take place, go to the module | ||
configuration form (). | ||
|
||
3. Custom entity properties | ||
|
||
See commerce_gdpr.api.php. |
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,155 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains admin forms for the module. | ||
*/ | ||
|
||
/** | ||
* Configuration form builder. | ||
*/ | ||
function commerce_gdpr_admin_form($form, &$form_state) { | ||
|
||
// Issue a warining if a site-specific hashing salt is not set. | ||
if (!variable_get('commerce_gdpr_salt', FALSE) && empty($form_state['input'])) { | ||
drupal_set_message(t('To ensure increased safety of anonymized data, please set a platform-specific hashing salt. More information can be found on the module !help.', array( | ||
'!help' => l(t('help page'), 'admin/help/commerce_gdpr', array( | ||
'attributes' => array('target' => '_blank'), | ||
)), | ||
)), 'warning'); | ||
} | ||
|
||
$form['data_retention'] = array( | ||
'#type' => 'textfield', | ||
'#title' => t('Order data retention period'), | ||
'#default_value' => variable_get('commerce_gdpr_data_retention', 0), | ||
'#description' => t('Enter number of days after which inactive data will be anonymized, 0 - no automatic anonymization.'), | ||
); | ||
|
||
$roles = user_roles(TRUE); | ||
if (!empty($roles)) { | ||
$form['excluded_roles'] = array( | ||
'#type' => 'checkboxes', | ||
'#options' => user_roles(TRUE), | ||
'#title' => t('Excluded roles'), | ||
'#default_value' => variable_get('commerce_gdpr_excluded_roles', array()), | ||
'#description' => t('Select which roles should not be anonymized automatically (If data retention period > 0).'), | ||
); | ||
} | ||
|
||
$form['direct_processing'] = array( | ||
'#type' => 'checkbox', | ||
'#title' => t('Process items immediately'), | ||
'#description' => t('Process items immediately on the user form and during the "People" page bulk operation rather then enqueing the operations. NOTE: may cause performance issues in case of users with many orders.'), | ||
'#default_value' => variable_get('commerce_gdpr_direct_processing', 0), | ||
); | ||
|
||
$form['user_button_text'] = array( | ||
'#type' => 'textfield', | ||
'#title' => t('User account anonymization button text'), | ||
'#default_value' => variable_get('commerce_gdpr_user_button_text', 'I want to be forgotten'), | ||
'#required' => TRUE, | ||
); | ||
|
||
$form['anonymized_fields'] = array( | ||
'#type' => 'fieldset', | ||
'#title' => t('Fields subject to anonymization'), | ||
'#tree' => TRUE, | ||
); | ||
|
||
$entity_info = entity_get_info(); | ||
$selected_fields = variable_get('commerce_gdpr_anonymized_fields', array()); | ||
|
||
foreach (array_keys(_commerce_gdpr_get_entity_property_info()) as $type) { | ||
$entity_info = entity_get_info($type); | ||
$form['anonymized_fields'][$type] = array( | ||
'#type' => 'fieldset', | ||
'#title' => $entity_info['label'], | ||
); | ||
foreach ($entity_info['bundles'] as $bundle => $bundle_info) { | ||
if (count($entity_info['bundles']) > 1) { | ||
$form['anonymized_fields'][$type][$bundle] = array( | ||
'#type' => 'fieldset', | ||
'#title' => $bundle_info['label'], | ||
); | ||
} | ||
else { | ||
$form['anonymized_fields'][$type]['#title'] = $bundle_info['label']; | ||
} | ||
|
||
$field_instances = field_info_instances($type, $bundle); | ||
if (empty($field_instances)) { | ||
$form['anonymized_fields'][$type][$bundle]['info'] = array( | ||
'#markup' => t('No field instances available.'), | ||
); | ||
} | ||
else { | ||
foreach ($field_instances as $field_name => $instance_info) { | ||
|
||
// Excluse customer profile type fields, those will be anonymized | ||
// along with the order. Also exclude line items. | ||
// TODO: Actually all entity reference field types should be | ||
// handled differently, but it's not needed at the moment. | ||
$excluded_fields = array( | ||
'commerce_line_item_reference', | ||
'commerce_customer_profile_reference', | ||
); | ||
$info = field_info_field($field_name); | ||
if (in_array($info['type'], $excluded_fields)) { | ||
continue; | ||
} | ||
|
||
$form['anonymized_fields'][$type][$bundle][$field_name] = array( | ||
'#type' => 'checkbox', | ||
'#title' => $instance_info['label'], | ||
'#default_value' => !empty($selected_fields[$type][$bundle][$field_name]), | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
||
$form['submit'] = array( | ||
'#type' => 'submit', | ||
'#value' => t('Save settings'), | ||
); | ||
|
||
return $form; | ||
} | ||
|
||
/** | ||
* Admin form validate handler. | ||
*/ | ||
function commerce_gdpr_admin_form_validate($form, &$form_state) { | ||
if (!ctype_digit($form_state['values']['data_retention'])) { | ||
form_set_error('data_retention', t('Enter a valid data retention value in days.')); | ||
} | ||
} | ||
|
||
/** | ||
* Admin form submit handler. | ||
*/ | ||
function commerce_gdpr_admin_form_submit($form, &$form_state) { | ||
variable_set('commerce_gdpr_data_retention', intval($form_state['values']['data_retention'])); | ||
variable_set('commerce_gdpr_excluded_roles', array_filter($form_state['values']['excluded_roles'])); | ||
variable_set('commerce_gdpr_direct_processing', $form_state['values']['direct_processing']); | ||
variable_set('commerce_gdpr_user_button_text', $form_state['values']['user_button_text']); | ||
|
||
$selected_fields = array(); | ||
foreach ($form_state['values']['anonymized_fields'] as $type => $type_data) { | ||
foreach ($type_data as $bundle => $bundle_data) { | ||
foreach ($bundle_data as $field_name => $value) { | ||
if ($value) { | ||
$selected_fields[$type][$bundle][$field_name] = $field_name; | ||
} | ||
} | ||
} | ||
} | ||
variable_set('commerce_gdpr_anonymized_fields', $selected_fields); | ||
|
||
if (variable_get('commerce_gdpr_excluded_roles', array()) !== $form['excluded_roles']['#default_value']) { | ||
_commerce_gdpr_update_last_access(); | ||
} | ||
|
||
drupal_set_message(t('Settings saved.')); | ||
} |
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,44 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Commerce GDPR API documentation. | ||
* | ||
* This file contains no working PHP code; it exists to provide additional | ||
* documentation for doxygen as well as to document hooks in the standard | ||
* Drupal manner. | ||
*/ | ||
|
||
/** | ||
* Allows altering information about anonymizable entity properties. | ||
* | ||
* NOTE: because of inability to save a customer profile that is bound | ||
* to an order, it is not allowed to add properties for | ||
* commerce_customer_profile entity type here. | ||
* | ||
* @param array $entity_property_info | ||
* Array containing information about anonymizable entity properties. | ||
* | ||
* @see _commerce_gdpr_get_entity_property_info | ||
*/ | ||
function hook_commerce_gdpr_entity_property_info_alter(array &$entity_property_info) { | ||
$entity_property_info['user']['mail']['type'] = 'clear'; | ||
} | ||
|
||
/** | ||
* Allows to act on an entity just before the anonymization takes place. | ||
* | ||
* @param string $type | ||
* Entity type. | ||
* @param object $entity | ||
* Drupal entity. | ||
* @param array $properties_data | ||
* Array of entity property anonymization data. | ||
* @param array $field_data | ||
* Array of field anonymization data. | ||
*/ | ||
function hook_commerce_gdpr_entity_anonymization($type, $entity, array $properties_data, array $field_data) { | ||
if ($type === 'node') { | ||
db_delete('some_custom_table')->condition('nid', $entity->nid)->execute(); | ||
} | ||
} |
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,12 @@ | ||
name = Commerce GDPR | ||
description = Allows user and order data anonymization for complience with the GDPR EU directive. | ||
core = 7.x | ||
package = Commerce (contrib) | ||
configure = admin/commerce/config/commerce-gdpr | ||
dependencies[] = commerce:commerce | ||
dependencies[] = commerce:commerce_order | ||
dependencies[] = ctools:ctools | ||
files[] = commerce_gdpr.test | ||
|
||
test_dependencies[] = views:views | ||
test_dependencies[] = addressfield:addressfield |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
lack of t()
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.
It's a default variable value, I thought it should be constant :)