Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
reminec
Limaju Server Symfony
Commits
aa3500c8
Commit
aa3500c8
authored
Oct 07, 2019
by
Dominique Merle
💬
Browse files
Even the author of a poll can't delete it once it has votes.
parent
32380608
Changes
3
Hide whitespace changes
Inline
Side-by-side
features/bootstrap/PoetryFeatureContext.php
View file @
aa3500c8
...
...
@@ -29,4 +29,11 @@ class PoetryFeatureContext extends BaseFeatureContext
*/
public
function
whenActorDoesNotDecideOnThings
()
{}
/**
* @When /^(?P<actor>.+?) does not like it$/ui
* @When /^(?P<actor>.+?) n'aime pas ça$/ui
*/
public
function
whenActorDoesNotLikeIt
()
{}
}
src/Repository/LimajuPollOptionVoteRepository.php
View file @
aa3500c8
...
...
@@ -2,6 +2,7 @@
namespace
App\Repository
;
use
App\Entity\LimajuPoll
;
use
App\Entity\LimajuPollOptionVote
;
use
Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository
;
use
Doctrine\Common\Persistence\ManagerRegistry
;
...
...
@@ -19,6 +20,18 @@ class LimajuPollOptionVoteRepository extends ServiceEntityRepository
parent
::
__construct
(
$registry
,
LimajuPollOptionVote
::
class
);
}
public
function
countVotesOnPoll
(
LimajuPoll
$poll
)
{
$count
=
0
;
foreach
(
$poll
->
getOptions
()
as
$option
)
{
$count
+=
$this
->
count
([
'option'
=>
$option
->
getId
(),
]);
}
return
$count
;
}
// /**
// * @return LimajuPollOptionVote[] Returns an array of LimajuPollOptionVote objects
// */
...
...
src/Security/PollBouncer.php
View file @
aa3500c8
...
...
@@ -6,6 +6,7 @@ namespace App\Security;
use
App\Application
;
use
App\Entity\LimajuPoll
;
use
App\Repository\LimajuPollOptionVoteRepository
;
use
Symfony\Component\Security\Core\Authentication\Token\TokenInterface
;
use
Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
;
use
Symfony\Component\Security\Core\Authorization\Voter\Voter
;
...
...
@@ -26,11 +27,17 @@ class PollBouncer extends Voter
* @var AuthorizationCheckerInterface
*/
private
$authorizationChecker
;
/**
* @var Application
*/
private
$app
;
/**
* @var LimajuPollOptionVoteRepository
*/
private
$voteRepository
;
/**
* Bouncer constructor.
...
...
@@ -39,10 +46,12 @@ class PollBouncer extends Voter
*/
public
function
__construct
(
Application
$app
,
LimajuPollOptionVoteRepository
$voteRepository
,
AuthorizationCheckerInterface
$authorizationChecker
)
{
$this
->
authorizationChecker
=
$authorizationChecker
;
$this
->
app
=
$app
;
$this
->
voteRepository
=
$voteRepository
;
}
public
function
canCurrentUserEditPoll
(
LimajuPoll
$poll
,
string
$password
=
''
)
:
bool
...
...
@@ -103,6 +112,10 @@ class PollBouncer extends Voter
return
true
;
}
if
(
0
<
$this
->
voteRepository
->
countVotesOnPoll
(
$subject
))
{
return
false
;
}
if
(
$subject
->
getAuthor
()
===
$this
->
app
->
getAuthenticatedUser
())
{
return
true
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment