Skip to content

Commit

Permalink
Merge branch 'master' into magento2.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed Jul 2, 2018
2 parents 5750df5 + 58c0141 commit 6129a38
Show file tree
Hide file tree
Showing 32 changed files with 1,027 additions and 437 deletions.
36 changes: 11 additions & 25 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ class Config
const CONFIG_PATH_ERASURE_STRATEGY = 'gdpr/erasure/strategy';
const CONFIG_PATH_ERASURE_TIME_LAPSE = 'gdpr/erasure/time_lapse';
const CONFIG_PATH_ERASURE_INFORMATION_BLOCK = 'gdpr/erasure/block_id';
const CONFIG_PATH_ERASURE_REMOVE_CUSTOMER = 'gdpr/erasure/remove_customer';
const CONFIG_PATH_ERASURE_STRATEGY_COMPONENTS = 'gdpr/erasure/components';
const CONFIG_PATH_ANONYMIZE_INFORMATION_BLOCK = 'gdpr/anonymize/block_id';
const CONFIG_PATH_ANONYMIZE_CUSTOMER_ATTRIBUTES = 'gdpr/anonymize/customer_attributes';
const CONFIG_PATH_ANONYMIZE_CUSTOMER_ADDRESS_ATTRIBUTES = 'gdpr/anonymize/customer_address_attributes';
const CONFIG_PATH_EXPORT_ENABLED = 'gdpr/export/enabled';
const CONFIG_PATH_EXPORT_INFORMATION_BLOCK = 'gdpr/export/block_id';
const CONFIG_PATH_EXPORT_RENDERER = 'gdpr/export/renderer';
Expand Down Expand Up @@ -102,6 +101,16 @@ public function getDefaultStrategy(): string
return $this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_STRATEGY, ScopeInterface::SCOPE_STORE);
}

/**
* Check if the customer can be removed if he has no orders
*
* @return bool
*/
public function isCustomerRemovedNoOrders(): bool
{
return $this->scopeConfig->isSetFlag(self::CONFIG_PATH_ERASURE_REMOVE_CUSTOMER, ScopeInterface::SCOPE_STORE);
}

/**
* Retrieve the components configured for the deletion strategy
*
Expand Down Expand Up @@ -142,29 +151,6 @@ public function getAnonymizeInformationBlockId(): string
return $this->getValueString(self::CONFIG_PATH_ANONYMIZE_INFORMATION_BLOCK, ScopeInterface::SCOPE_STORE);
}

/**
* Retrieve the anonymous customer attributes codes
*
* @return array
*/
public function getAnonymizeCustomerAttributes(): array
{
return $this->getValueArray(self::CONFIG_PATH_ANONYMIZE_CUSTOMER_ATTRIBUTES, ScopeInterface::SCOPE_STORE);
}

/**
* Retrieve the anonymous customer address attributes codes
*
* @return array
*/
public function getAnonymizeCustomerAddressAttributes(): array
{
return $this->getValueArray(
self::CONFIG_PATH_ANONYMIZE_CUSTOMER_ADDRESS_ATTRIBUTES,
ScopeInterface::SCOPE_STORE
);
}

/**
* Check if the export is enabled
*
Expand Down
51 changes: 0 additions & 51 deletions Model/Config/Source/CustomerAddressAttributes.php

This file was deleted.

51 changes: 0 additions & 51 deletions Model/Config/Source/CustomerAttributes.php

This file was deleted.

71 changes: 71 additions & 0 deletions Model/Config/Source/VirtualCustomerAttributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* Copyright © 2018 OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);

namespace Opengento\Gdpr\Model\Config\Source;

use Magento\Customer\Api\MetadataInterface;
use Magento\Framework\Data\OptionSourceInterface;
use Magento\Framework\Exception\LocalizedException;

/**
* Class VirtualCustomerAttributes
*/
class VirtualCustomerAttributes implements OptionSourceInterface
{
/**
* @var \Magento\Customer\Api\MetadataInterface
*/
private $metadata;

/**
* @var array
*/
private $options;

/**
* @param \Magento\Customer\Api\MetadataInterface $metadata
* @param array $options
*/
public function __construct(
MetadataInterface $metadata,
array $options = []
) {
$this->metadata = $metadata;
$this->options = $this->loadOptions($options);
}

/**
* {@inheritdoc}
*/
public function toOptionArray()
{
return $this->options;
}

/**
* Load an prepare customer address attributes options
*
* @param array $defaultOptions
* @return array
*/
public function loadOptions(array $defaultOptions = []): array
{
$options = [];

try {
$attributes = $this->metadata->getAllAttributesMetadata();
} catch (LocalizedException $e) {
$attributes = [];
}

foreach ($attributes as $attribute) {
$options[] = ['value' => $attribute->getAttributeCode(), 'label' => $attribute->getFrontendLabel()];
}

return \array_merge($options, $defaultOptions);
}
}
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,12 @@ The settings are divided as following:
* Cron Scheduler
* Right to Erasure Information CMS Block
* Anonymization Information CMS Block
* Customer Attributes to anonymize
* Customer Address Attributes to anonymize
* Remove Customer if no Orders
* Apply Deletion Strategy to specific components
* Export Settings
* Enable the feature
* Export Personal Data Information CMS Block
* Export Renderer option
* Customer Attributes to export
* Customer Address Attributes to export
* Cookie Settings
* Enable the cookie disclosure
* Cookie Policy Information CMS Block
Expand Down Expand Up @@ -183,7 +180,7 @@ Please provide your Magento 2 version and the module version. Explain how to rep
- **Opengento Community** - *Lead* - [They're awesome!](https://github.com/opengento)
- **Contributors** - *Contributor* - [Many thanks!](https://github.com/opengento/magento2-gdpr/graphs/contributors)

## Licence
## License

This project is licensed under the MIT License - see the [LICENSE](./LICENSE) details.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
use Magento\Framework\Phrase;

/**
* Class AbstractAnonymize
* Class AnonymizeTool
*/
abstract class AbstractAnonymize implements ProcessorInterface
class AnonymizeTool
{
/**
* @var \Magento\Framework\Math\Random
*/
protected $mathRandom;
private $mathRandom;

/**
* AbstractAnonymize constructor.
* @param \Magento\Framework\Math\Random $mathRandom
*/
public function __construct(
Expand All @@ -35,20 +34,41 @@ public function __construct(
*
* @return string
*/
protected function anonymousValue(): string
public function anonymousValue(): string
{
return (new Phrase('Anonymous'))->render();
}

/**
* Retrieve an anonymous email
*
* @return string
*/
public function anonymousEmail(): string
{
return (new Phrase('[email protected]'))->render();
}

/**
* Retrieve anonymous phone number
*
* @return string
*/
public function anonymousPhone(): string
{
return (new Phrase('9999999999'))->render();
}

/**
* Retrieve a random value
*
* @param int $length
* @param null|string $chars
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function randomValue(int $length = 10): string
public function randomValue(int $length = 10, string $chars = ''): string
{
return $this->mathRandom->getRandomString($length);
return $this->mathRandom->getRandomString($length, $chars ?: null);
}
}
Loading

0 comments on commit 6129a38

Please sign in to comment.