Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Eliminada la ACL y reemplazada por un Security Voter propio
- Loading branch information
1 parent
6297b1a
commit 0d25fdb
Showing
4 changed files
with
53 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
security: | ||
|
||
acl: | ||
connection: default | ||
|
||
firewalls: | ||
# Firewall de la parte de administración o backend | ||
backend: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/* | ||
* (c) Javier Eguiluz <javier.eguiluz@gmail.com> | ||
* | ||
* Este archivo pertenece a la aplicación de prueba Cupon. | ||
* El código fuente de la aplicación incluye un archivo llamado LICENSE | ||
* con toda la información sobre el copyright y la licencia. | ||
*/ | ||
|
||
namespace Cupon\TiendaBundle\Security; | ||
|
||
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; | ||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | ||
|
||
class OwnerVoter implements VoterInterface | ||
{ | ||
public function supportsAttribute($attribute) | ||
{ | ||
return 'ROLE_EDITAR_OFERTA' == $attribute; | ||
} | ||
|
||
public function supportsClass($class) | ||
{ | ||
return true; | ||
} | ||
|
||
public function vote(TokenInterface $token, $object, array $attributes) | ||
{ | ||
$vote = VoterInterface::ACCESS_ABSTAIN; | ||
|
||
foreach ($attributes as $attribute) { | ||
if (false === $this->supportsAttribute($attribute)) { | ||
continue; | ||
} | ||
|
||
$user = $token->getUser(); | ||
$vote = VoterInterface::ACCESS_DENIED; | ||
|
||
// comprobar que la oferta que se edita fue publicada por esta misma tienda | ||
if ($object->getTienda()->getId() === $user->getId()) { | ||
$vote = VoterInterface::ACCESS_GRANTED; | ||
} | ||
} | ||
|
||
return $vote; | ||
} | ||
} |