Skip to content

Commit

Permalink
closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Nov 1, 2017
1 parent 410b3c2 commit 0104d47
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ LUYA MODULE MAILCHIMP CHANGELOG

All notable changes to this project will be documented in this file. This project make usage of the [Yii Versioning Strategy](https://github.com/yiisoft/yii2/blob/master/docs/internals/versions.md).

1.0.2 (in progress)
1.0.2 (1. November 2017)
-------------------

- [#8](https://github.com/luyadev/luya-module-mailchimp/issues/8) Provide an option to disable the robots filtering.

1.0.1 (17. October 2017)
-------------------

Expand Down
13 changes: 6 additions & 7 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ class Module extends \luya\base\Module
* [[\luya\components\Mail::addresses()]] method of the mailer function.
*/
public $recipients;

/**
* @var int Number in seconds, if the process time is faster then `$spamDetectionDelay`, the mail will threated as spam
* and throws an exception. As humans requires at least more then 2 seconds to fillup a form we use this as base value.
*/
public $spamDetectionDelay = 2;

/**
* @var string MailChimp API key. You'll find more info how to make or retrieve an API key here: http://kb.mailchimp.com/accounts/management/about-api-keys
*/
Expand Down Expand Up @@ -134,4 +127,10 @@ class Module extends \luya\base\Module
* ```
*/
public $groups = [];

/**
* @var boolean Whether robots filtering is enabled or not, if provided this is the time of seconds a visitor must enter data on the
* page, if the time is lower then given time, an exception is thrown. If value is false, the robots filter behavior is disabled.
*/
public $robotsFilterDelay = 2.5;
}
15 changes: 11 additions & 4 deletions src/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,24 @@

/**
* Default Controller.
*
*
* @author Basil Suter <[email protected]>
* @since 1.0.0
*/
class DefaultController extends Controller
{
public function behaviors()
{
return [
'robotsFilter' => RobotsFilter::class,
];
$behaviors = parent::behaviors();

if ($this->module->robotsFilterDelay !== false) {
$behaviors['robotsFilter'] = [
'class' => RobotsFilter::class,
'delay' => $this->module->robotsFilterDelay,
];
}

return $behaviors;
}

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/MailchimpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,18 @@ public function testRobotsSpamDelay()
$this->expectException('yii\base\InvalidCallException');
(new DefaultController('default', $module))->runAction('index');
}

public function testRobotsSpamDelayDisabled()
{
$module = $this->app->getModule('mailchimp');
$module->robotsFilterDelay = false;
$module->listId = '123';
$module->mailchimpApi = '123';
$module->attributes = ['foo' => 'bar'];

$ctrl = (new DefaultController('default', $module));
$behaviors = $ctrl->behaviors();

$this->assertEmpty($behaviors);
}
}

0 comments on commit 0104d47

Please sign in to comment.