Skip to content

Commit 2c4018d

Browse files
authored
Merge pull request #224 from symfony-cmf/bug/non-object-to-voter
[Voters] Account for subject to not be an object
2 parents f45a637 + c9ff106 commit 2c4018d

File tree

6 files changed

+26
-14
lines changed

6 files changed

+26
-14
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ cache:
1616

1717
env:
1818
matrix: SYMFONY_VERSION=2.8.*
19-
global: SYMFONY_DEPRECATIONS_HELPER=7
19+
global: SYMFONY_DEPRECATIONS_HELPER=weak
2020

2121
matrix:
2222
include:

PublishWorkflow/Voter/PublishTimePeriodVoter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ public function supportsClass($class)
6666
/**
6767
* {@inheritdoc}
6868
*
69-
* @param PublishTimePeriodReadInterface $object
69+
* @param PublishTimePeriodReadInterface $subject
7070
*/
71-
public function vote(TokenInterface $token, $object, array $attributes)
71+
public function vote(TokenInterface $token, $subject, array $attributes)
7272
{
73-
if (!$this->supportsClass(get_class($object))) {
73+
if (!is_object($subject) || !$this->supportsClass(get_class($subject))) {
7474
return self::ACCESS_ABSTAIN;
7575
}
7676

77-
$startDate = $object->getPublishStartDate();
78-
$endDate = $object->getPublishEndDate();
77+
$startDate = $subject->getPublishStartDate();
78+
$endDate = $subject->getPublishEndDate();
7979

8080
$decision = self::ACCESS_GRANTED;
8181
foreach ($attributes as $attribute) {

PublishWorkflow/Voter/PublishableVoter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ public function supportsClass($class)
4444
/**
4545
* {@inheritdoc}
4646
*
47-
* @param PublishableReadInterface $object
47+
* @param PublishableReadInterface $subject
4848
*/
49-
public function vote(TokenInterface $token, $object, array $attributes)
49+
public function vote(TokenInterface $token, $subject, array $attributes)
5050
{
51-
if (!$this->supportsClass(get_class($object))) {
51+
if (!is_object($subject) || !$this->supportsClass(get_class($subject))) {
5252
return self::ACCESS_ABSTAIN;
5353
}
5454

@@ -61,7 +61,7 @@ public function vote(TokenInterface $token, $object, array $attributes)
6161
$decision = self::ACCESS_ABSTAIN;
6262
continue;
6363
}
64-
if (!$object->isPublishable()) {
64+
if (!$subject->isPublishable()) {
6565
return self::ACCESS_DENIED;
6666
}
6767
}

Security/Authorization/Voter/PublishedVoter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ public function supportsClass($class)
5757
/**
5858
* {@inheritdoc}
5959
*
60-
* @param object $object
60+
* @param object $subject
6161
*/
62-
public function vote(TokenInterface $token, $object, array $attributes)
62+
public function vote(TokenInterface $token, $subject, array $attributes)
6363
{
64-
if (!$this->supportsClass(get_class($object))) {
64+
if (!is_object($subject) || !$this->supportsClass(get_class($subject))) {
6565
return self::ACCESS_ABSTAIN;
6666
}
6767
foreach ($attributes as $attribute) {
@@ -70,7 +70,7 @@ public function vote(TokenInterface $token, $object, array $attributes)
7070
}
7171
}
7272

73-
if ($this->publishWorkflowChecker->isGranted($attributes, $object)) {
73+
if ($this->publishWorkflowChecker->isGranted($attributes, $subject)) {
7474
return self::ACCESS_GRANTED;
7575
}
7676

Tests/Unit/PublishWorkflow/Voter/PublishTimePeriodVoterTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,10 @@ public function testUnsupportedClass()
132132
);
133133
$this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $result);
134134
}
135+
136+
public function testNonClassSubject()
137+
{
138+
$result = $this->voter->vote($this->token, array(1, 2, 3), array(PublishWorkflowChecker::VIEW_ATTRIBUTE));
139+
$this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $result);
140+
}
135141
}

Tests/Unit/PublishWorkflow/Voter/PublishableVoterTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,10 @@ public function testUnsupportedClass()
100100
);
101101
$this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $result);
102102
}
103+
104+
public function testNonClassSubject()
105+
{
106+
$result = $this->voter->vote($this->token, array(1, 2, 3), array(PublishWorkflowChecker::VIEW_ATTRIBUTE));
107+
$this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $result);
108+
}
103109
}

0 commit comments

Comments
 (0)