Skip to content

Commit 118c970

Browse files
committed
add check for paginator theme before setting it in gateway
1 parent 63108f8 commit 118c970

3 files changed

Lines changed: 44 additions & 12 deletions

File tree

Component/FloodControl.php

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
namespace CCDNMessage\MessageBundle\Component;
1515

16+
use Symfony\Component\Security\Core\SecurityContextInterface;
17+
use Symfony\Component\HttpFoundation\Session\Session;
18+
1619
/**
1720
*
1821
* @category CCDNMessage
@@ -29,10 +32,24 @@ class FloodControl
2932
/**
3033
*
3134
* @access protected
32-
* @var $session
35+
* @var \Symfony\Component\Security\Core\SecurityContextInterface $securityContext
36+
*/
37+
protected $securityContext;
38+
39+
/**
40+
*
41+
* @access protected
42+
* @var \Symfony\Component\HttpFoundation\Session\Session $session
3343
*/
3444
protected $session;
3545

46+
/**
47+
*
48+
* @access protected
49+
* @var string $kernelEnv
50+
*/
51+
protected $kernelEnv;
52+
3653
/**
3754
*
3855
* @access protected
@@ -50,19 +67,24 @@ class FloodControl
5067
/**
5168
*
5269
* @access public
53-
* @param $session
70+
* @param \Symfony\Component\Security\Core\SecurityContextInterface $securityContext
71+
* @param \Symfony\Component\HttpFoundation\Session\Session $session
72+
* @param string $kernelEnv
73+
* @param int $sendLimit
74+
* @param int $blockForMinutes
5475
*/
55-
public function __construct($session, $sendLimit, $blockForMinutes)
76+
public function __construct(SecurityContextInterface $securityContext, Session $session, $kernelEnv, $sendLimit, $blockForMinutes)
5677
{
78+
$this->securityContext = $securityContext;
5779
$this->session = $session;
58-
59-
$this->sendLimit = $sendLimit;
60-
61-
$this->blockForMinutes = $blockForMinutes;
80+
$this->kernelEnv = $kernelEnv;
6281

6382
if ( ! $this->session->has('flood_control_message_send_count')) {
6483
$this->session->set('flood_control_message_send_count', array());
6584
}
85+
86+
$this->sendLimit = $sendLimit;
87+
$this->blockForMinutes = $blockForMinutes;
6688
}
6789

6890
/**
@@ -71,11 +93,13 @@ public function __construct($session, $sendLimit, $blockForMinutes)
7193
*/
7294
public function incrementCounter()
7395
{
74-
$sendCount = $this->session->get('flood_control_message_send_count');
96+
if (! $this->securityContext->isGranted('ROLE_MODERATOR') || $this->kernelEnv != 'prod') {
97+
$sendCount = $this->session->get('flood_control_message_send_count');
7598

76-
$sendCount[] = new \DateTime('now');
99+
$sendCount[] = new \DateTime('now');
77100

78-
$this->session->set('flood_control_message_send_count', $sendCount);
101+
$this->session->set('flood_control_message_send_count', $sendCount);
102+
}
79103
}
80104

81105
/**
@@ -85,14 +109,17 @@ public function incrementCounter()
85109
*/
86110
public function isFlooded()
87111
{
88-
$timeLimit = new \DateTime('-' . $this->blockForMinutes . ' minutes');
112+
if ($this->sendLimit < 1 || ! $this->securityContext->isGranted('ROLE_MODERATOR') || $this->kernelEnv != 'prod') {
113+
return false;
114+
}
89115

90116
if ($this->session->has('flood_control_message_send_count')) {
91117
$attempts = $this->session->get('flood_control_message_send_count');
92118

93119
// Iterate over attempts and only reveal attempts that fall within the $timeLimit.
94120
$freshenedAttempts = array();
95121

122+
$timeLimit = new \DateTime('-' . $this->blockForMinutes . ' minutes');
96123
$limit = $timeLimit->getTimestamp();
97124

98125
foreach ($attempts as $attempt) {

Model/Component/Gateway/BaseGateway.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ public function all(QueryBuilder $qb, $parameters = array())
194194
public function paginateQuery(QueryBuilder $qb, $itemsPerPage, $page)
195195
{
196196
$pager = $this->paginator->paginate($qb, $page, $itemsPerPage);
197-
$pager->setTemplate($this->pagerTheme);
197+
198+
if ($this->pagerTheme) {
199+
$pager->setTemplate($this->pagerTheme);
200+
}
198201

199202
return $pager;
200203
}

Resources/config/services/components.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ services:
4949
ccdn_message_message.component.flood_control:
5050
class: %ccdn_message_message.component.flood_control.class%
5151
arguments:
52+
- @security.context
5253
- @session
54+
- %kernel.environment%
5355
- %ccdn_message_message.message.flood_control.send_limit%
5456
- %ccdn_message_message.message.flood_control.block_for_minutes%
5557

0 commit comments

Comments
 (0)