Skip to content

Commit

Permalink
Merge branch '1.3'
Browse files Browse the repository at this point in the history
Conflicts:
	.travis.yml
	src/PublishWorkflow/Voter/PublishableVoter.php
  • Loading branch information
wouterj committed Jan 29, 2017
2 parents 389e3ca + 2c4018d commit 3a71cbb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/PublishWorkflow/Voter/PublishTimePeriodVoter.php
Expand Up @@ -70,16 +70,16 @@ public function supportsClass($class)
/**
* {@inheritdoc}
*
* @param PublishTimePeriodReadInterface $object
* @param PublishTimePeriodReadInterface $subject
*/
public function vote(TokenInterface $token, $object, array $attributes)
public function vote(TokenInterface $token, $subject, array $attributes)
{
if (!$this->supportsClass(get_class($object))) {
if (!is_object($subject) || !$this->supportsClass(get_class($subject))) {
return self::ACCESS_ABSTAIN;
}

$startDate = $object->getPublishStartDate();
$endDate = $object->getPublishEndDate();
$startDate = $subject->getPublishStartDate();
$endDate = $subject->getPublishEndDate();

$decision = self::ACCESS_GRANTED;
foreach ($attributes as $attribute) {
Expand Down
8 changes: 4 additions & 4 deletions src/PublishWorkflow/Voter/PublishableVoter.php
Expand Up @@ -48,11 +48,11 @@ public function supportsClass($class)
/**
* {@inheritdoc}
*
* @param PublishableReadInterface $object
* @param PublishableReadInterface $subject
*/
public function vote(TokenInterface $token, $object, array $attributes)
public function vote(TokenInterface $token, $subject, array $attributes)
{
if (!$this->supportsClass(get_class($object))) {
if (!is_object($subject) || !$this->supportsClass(get_class($subject))) {
return self::ACCESS_ABSTAIN;
}

Expand All @@ -66,7 +66,7 @@ public function vote(TokenInterface $token, $object, array $attributes)
continue;
}

if (!$object->isPublishable()) {
if (!$subject->isPublishable()) {
return self::ACCESS_DENIED;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Security/Authorization/Voter/PublishedVoter.php
Expand Up @@ -57,11 +57,11 @@ public function supportsClass($class)
/**
* {@inheritdoc}
*
* @param object $object
* @param object $subject
*/
public function vote(TokenInterface $token, $object, array $attributes)
public function vote(TokenInterface $token, $subject, array $attributes)
{
if (!$this->supportsClass(get_class($object))) {
if (!is_object($subject) || !$this->supportsClass(get_class($subject))) {
return self::ACCESS_ABSTAIN;
}
foreach ($attributes as $attribute) {
Expand All @@ -70,7 +70,7 @@ public function vote(TokenInterface $token, $object, array $attributes)
}
}

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

Expand Down
Expand Up @@ -133,4 +133,10 @@ public function testUnsupportedClass()
);
$this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $result);
}

public function testNonClassSubject()
{
$result = $this->voter->vote($this->token, array(1, 2, 3), array(PublishWorkflowChecker::VIEW_ATTRIBUTE));
$this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $result);
}
}
6 changes: 6 additions & 0 deletions tests/Unit/PublishWorkflow/Voter/PublishableVoterTest.php
Expand Up @@ -101,4 +101,10 @@ public function testUnsupportedClass()
);
$this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $result);
}

public function testNonClassSubject()
{
$result = $this->voter->vote($this->token, array(1, 2, 3), array(PublishWorkflowChecker::VIEW_ATTRIBUTE));
$this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $result);
}
}

0 comments on commit 3a71cbb

Please sign in to comment.