Skip to content

Commit

Permalink
[Update feature] Check validity rules system
Browse files Browse the repository at this point in the history
  • Loading branch information
bastienlm committed Oct 5, 2018
1 parent 493a920 commit 6718a88
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 101 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ Download this module and add 'app' and 'skin' directory to you magento

## Usage
- Enable all feature who you want on 'System > Configuration > General > GDPR'
- Run cron phgdpr_check_rules and check GDPR validity on 'System > Configuration > General > GDPR > Status'
- You can test download data or remove data from your customer dashboard

## Password validation
Expand Down
16 changes: 16 additions & 0 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,19 @@ Init module :
- [Fix] #11 #9 #13 #15
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
==== 1.1.1 ====

- [Update] Modman update
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
==== 1.1.2 ====

- [Update] Modman update / composer update / PSR2 validity
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
==== 1.1.3 ====

- [Fix] Improve password validation UX #10
- [Update] Check validity rules system
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*
*/

class PH2M_Gdpr_Block_Adminhtml_Gdpr_Status extends Mage_Core_Block_Template
class PH2M_Gdpr_Block_Adminhtml_Gdpr_Rules_Status extends Mage_Core_Block_Template
{
/**
* Constructor. Set template.
*/
protected function _construct()
{
parent::_construct();
$this->setTemplate('ph/gdpr/system/config/status.phtml');
$this->setTemplate('ph/gdpr/system/config/rules/status.phtml');
}


Expand All @@ -38,8 +38,6 @@ public function getCssClass($config)
$config = Mage::getStoreConfig($config);
if ($config == PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::NO_VALID) {
return 'bad';
} elseif ($config == PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::WAIT_MANUAL_VALIDATION) {
return 'wait';
}
return 'good';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
*
*/

class PH2M_Gdpr_Block_Adminhtml_System_Config_Gdpr_Status extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
class PH2M_Gdpr_Block_Adminhtml_System_Config_Gdpr_Rules extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
{
/**
* @param Varien_Data_Form_Element_Abstract $element
* @return string
*/
public function render(Varien_Data_Form_Element_Abstract $element)
{
$html = Mage::getBlockSingleton('phgdpr/adminhtml_gdpr_status')->toHtml();
$status = Mage::getBlockSingleton('phgdpr/adminhtml_gdpr_rules_status')->toHtml();

return $html;
return $status;
}
}
59 changes: 2 additions & 57 deletions app/code/community/PH2M/Gdpr/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,71 +16,16 @@
*/
class PH2M_Gdpr_Model_Observer
{
protected $configModel;
const EXCEPTION_ACCOUNT_GDPR_LOCK = 20;
const DEFAULT_ATTEMPS_NUMBER = 5;
const DEFAULT_TIME_BLOCKED = 5;


/**
* Check if all config for respect GDPR is enabled
*/
public function checkRulesValidity()
{
$this->configModel = Mage::getConfig();
$this->checkNewsletterDoubleOptIn();
$this->checkPasswordFormatValidation();
$this->checkLoginLimitAttempts();
$this->checkCustomerCanRemoveData();
$this->checkCustomerCanDownloadData();
}

protected function checkCustomerCanRemoveData()
{
if (Mage::getStoreConfig('phgdpr/customer_data_remove/enable')) {
$this->configModel->saveConfig('phgdpr/valid_rules/customer_data_remove', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::WAIT_MANUAL_VALIDATION, 'default', 0);
} else {
$this->configModel->saveConfig('phgdpr/valid_rules/customer_data_remove', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::NO_VALID, 'default', 0);
}
}

protected function checkCustomerCanDownloadData()
public function checkRulesValidity(Varien_Event_Observer $observer)
{
if (Mage::getStoreConfig('phgdpr/customer_data_download/enable')) {
$this->configModel->saveConfig('phgdpr/valid_rules/customer_download_own_information', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::WAIT_MANUAL_VALIDATION, 'default', 0);
} else {
$this->configModel->saveConfig('phgdpr/valid_rules/customer_download_own_information', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::NO_VALID, 'default', 0);
}
Mage::getModel('phgdpr/rules_validity')->checkRulesValidity();
}

protected function checkNewsletterDoubleOptIn()
{
if (Mage::getStoreConfig('newsletter/subscription/confirm')) {
$this->configModel->saveConfig('phgdpr/valid_rules/newsletter_double_optin', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::WAIT_MANUAL_VALIDATION, 'default', 0);
} else {
$this->configModel->saveConfig('phgdpr/valid_rules/newsletter_double_optin', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::NO_VALID, 'default', 0);
}
}

protected function checkPasswordFormatValidation()
{
if (Mage::getStoreConfig('phgdpr/fonctionality/password_format_validation')) {
$this->configModel->saveConfig('phgdpr/valid_rules/customer_complex_password', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::WAIT_MANUAL_VALIDATION, 'default', 0);
} else {
$this->configModel->saveConfig('phgdpr/valid_rules/customer_complex_password', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::NO_VALID, 'default', 0);
}
}

protected function checkLoginLimitAttempts()
{
if (Mage::getStoreConfig('phgdpr/fonctionality/login_limit_attempts')) {
$this->configModel->saveConfig('phgdpr/valid_rules/customer_login_limit_attempts', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::WAIT_MANUAL_VALIDATION, 'default', 0);
} else {
$this->configModel->saveConfig('phgdpr/valid_rules/customer_login_limit_attempts', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::NO_VALID, 'default', 0);
}
}


/**
* If customer try to login too many time during 30 seconds,
* lock the login system during 30 seconds
Expand Down
81 changes: 81 additions & 0 deletions app/code/community/PH2M/Gdpr/Model/Rules/Validity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* PH2M_GDPR
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category GDPR
* @copyright Copyright (c) 2018 PH2M SARL
* @author PH2M SARL <contact@ph2m.com> : http://www.ph2m.com/
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

class PH2M_Gdpr_Model_Rules_Validity extends Varien_Object
{
protected $configModel;

/**
* Check if all config for respect GDPR is enabled
* @event admin_system_config_changed_section_newsletter
* @event
*/
public function checkRulesValidity()
{
$this->configModel = Mage::getConfig();
$this->checkNewsletterDoubleOptIn();
$this->checkPasswordFormatValidation();
$this->checkLoginLimitAttempts();
$this->checkCustomerCanRemoveData();
$this->checkCustomerCanDownloadData();
}

protected function checkCustomerCanRemoveData()
{
if (Mage::getStoreConfig('phgdpr/customer_data_remove/enable')) {
$this->configModel->saveConfig('phgdpr/valid_rules/customer_data_remove', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::VALID, 'default', 0);
} else {
$this->configModel->saveConfig('phgdpr/valid_rules/customer_data_remove', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::NO_VALID, 'default', 0);
}
}

protected function checkCustomerCanDownloadData()
{
if (Mage::getStoreConfig('phgdpr/customer_data_download/enable')) {
$this->configModel->saveConfig('phgdpr/valid_rules/customer_download_own_information', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::VALID, 'default', 0);
} else {
$this->configModel->saveConfig('phgdpr/valid_rules/customer_download_own_information', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::NO_VALID, 'default', 0);
}
}

protected function checkNewsletterDoubleOptIn()
{
if (Mage::getStoreConfig('newsletter/subscription/confirm')) {
$this->configModel->saveConfig('phgdpr/valid_rules/newsletter_double_optin', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::VALID, 'default', 0);
} else {
$this->configModel->saveConfig('phgdpr/valid_rules/newsletter_double_optin', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::NO_VALID, 'default', 0);
}
}

protected function checkPasswordFormatValidation()
{
if (Mage::getStoreConfig('phgdpr/fonctionality/password_format_validation')) {
$this->configModel->saveConfig('phgdpr/valid_rules/customer_complex_password', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::VALID, 'default', 0);
} else {
$this->configModel->saveConfig('phgdpr/valid_rules/customer_complex_password', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::NO_VALID, 'default', 0);
}
}

protected function checkLoginLimitAttempts()
{
if (Mage::getStoreConfig('phgdpr/fonctionality/login_limit_attempts')) {
$this->configModel->saveConfig('phgdpr/valid_rules/customer_login_limit_attempts', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::VALID, 'default', 0);
} else {
$this->configModel->saveConfig('phgdpr/valid_rules/customer_login_limit_attempts', PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity::NO_VALID, 'default', 0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@
*/

/**
* Used in creating options for Yes|No config value selection
*
* Class PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity
*/
class PH2M_Gdpr_Model_System_Config_Source_Rulesvalidity
{
const NO_VALID = 0;
const VALID = 1;
const WAIT_MANUAL_VALIDATION = 2;
const NO_VALID = 0;
const VALID = 1;

/**
* Options getter
Expand All @@ -43,8 +41,7 @@ public function toOptionArray()
{
return [
['value' => self::NO_VALID, 'label' => Mage::helper('adminhtml')->__('No valid')],
['value' => self::VALID, 'label' => Mage::helper('adminhtml')->__('Valid')],
['value' => self::WAIT_MANUAL_VALIDATION, 'label' => Mage::helper('adminhtml')->__('Wait manual validation')],
['value' => self::VALID, 'label' => Mage::helper('adminhtml')->__('Valid')]
];
}

Expand All @@ -57,8 +54,7 @@ public function toArray()
{
return [
self::NO_VALID => Mage::helper('adminhtml')->__('No valid'),
self::VALID => Mage::helper('adminhtml')->__('Valid'),
self::WAIT_MANUAL_VALIDATION => Mage::helper('adminhtml')->__('Wait manual validation'),
self::VALID => Mage::helper('adminhtml')->__('Valid')
];
}
}
29 changes: 22 additions & 7 deletions app/code/community/PH2M/Gdpr/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@
</global>
<crontab>
<jobs>
<phgdpr_check_rules>
<run>
<model>phgdpr/observer::checkRulesValidity</model>
</run>
</phgdpr_check_rules>
<phgdpr_queue_runner>
<run>
<model>phgdpr/observer::runQueueRunner</model>
Expand Down Expand Up @@ -160,18 +155,38 @@
</PH2M_Gdpr>
</modules>
</translate>
<events>
<admin_system_config_changed_section_newsletter>
<observers>
<bind_locale>
<class>phgdpr/observer</class>
<method>checkRulesValidity</method>
</bind_locale>
</observers>
</admin_system_config_changed_section_newsletter>
<admin_system_config_changed_section_phgdpr>
<observers>
<bind_locale>
<class>phgdpr/observer</class>
<method>checkRulesValidity</method>
</bind_locale>
</observers>
</admin_system_config_changed_section_phgdpr>
</events>
</adminhtml>
<default>
<phgdpr>
<customer_data_remove>
<confirm_email_template>phgdpr_customer_data_remove_confirm_email_template</confirm_email_template>
<email_sender_identity>general</email_sender_identity>
<lock_account_message><![CDATA[This account will be removed soon, during this process you can log to this account]]></lock_account_message>
<lock_account_message>
<![CDATA[This account will be removed soon, during this process you can log to this account]]></lock_account_message>
</customer_data_remove>
<customer_data_download>
<email_template>phgdpr_customer_data_download_email_template</email_template>
<email_sender_identity>general</email_sender_identity>
<queue_processing_message><![CDATA[We received your request, and we send you your data soon by email.]]></queue_processing_message>
<queue_processing_message>
<![CDATA[We received your request, and we send you your data soon by email.]]></queue_processing_message>
</customer_data_download>
</phgdpr>
</default>
Expand Down
21 changes: 6 additions & 15 deletions app/code/community/PH2M/Gdpr/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<show_in_store>1</show_in_store>
<groups>
<status translate="label">
<label>Status</label>
<label>GDPR rules validity</label>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
Expand All @@ -37,7 +37,7 @@
<status translate="label comment">
<label>Status</label>
<frontend_type>text</frontend_type>
<frontend_model>phgdpr/adminhtml_system_config_gdpr_status</frontend_model>
<frontend_model>phgdpr/adminhtml_system_config_gdpr_rules</frontend_model>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
Expand All @@ -54,7 +54,7 @@
<expanded>1</expanded>
<fields>
<password_format_validation translate="label comment">
<label>Enable password GDPR format validation</label>
<label>Enable password CNIL format validation</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>10</sort_order>
Expand Down Expand Up @@ -101,9 +101,9 @@
<valid_rules>
<label>Valid rules</label>
<sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<show_in_default>0</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<expanded>0</expanded>
<fields>
<customer_complex_password translate="label comment">
Expand All @@ -115,15 +115,6 @@
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</customer_complex_password>
<customer_password_reset translate="label comment">
<label>Customer password reset</label>
<frontend_type>select</frontend_type>
<source_model>phgdpr/system_config_source_rulesvalidity</source_model>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</customer_password_reset>
<customer_login_limit_attempts translate="label comment">
<label>Customer multi login attempts limit</label>
<frontend_type>select</frontend_type>
Expand Down
Loading

0 comments on commit 6718a88

Please sign in to comment.