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
Chill-project
Chill-Report
Commits
eeff93c8
Commit
eeff93c8
authored
Apr 05, 2018
by
Julien Minet
Browse files
fix deprecations: implement abstract function for reportVoter
parent
1b4bb4f7
Pipeline
#46051
failed with stages
in 1 minute and 18 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Security/Authorization/ReportVoter.php
View file @
eeff93c8
...
...
@@ -19,12 +19,17 @@
namespace
Chill\ReportBundle\Security\Authorization
;
use
Symfony\Component\Security\Core\Authentication\Token\TokenInterface
;
use
Chill\MainBundle\Security\Authorization\AbstractChillVoter
;
use
Chill\MainBundle\Security\Authorization\AuthorizationHelper
;
use
Chill\MainBundle\Security\ProvideRoleHierarchyInterface
;
use
Chill\ReportBundle\Entity\Report
;
use
Chill\MainBundle\Entity\User
;
/**
*
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
...
...
@@ -33,38 +38,41 @@ class ReportVoter extends AbstractChillVoter implements ProvideRoleHierarchyInte
const
CREATE
=
'CHILL_REPORT_CREATE'
;
const
SEE
=
'CHILL_REPORT_SEE'
;
const
UPDATE
=
'CHILL_REPORT_UPDATE'
;
/**
*
* @var AuthorizationHelper
*/
protected
$helper
;
public
function
__construct
(
AuthorizationHelper
$helper
)
{
$this
->
helper
=
$helper
;
}
protected
function
getSupportedAttributes
()
{
return
array
(
self
::
CREATE
,
self
::
SEE
,
self
::
UPDATE
);
}
protected
function
getSupportedClasses
()
protected
function
supports
(
$attribute
,
$subject
)
{
return
array
(
'Chill\ReportBundle\Entity\Report'
);
if
(
$subject
instanceof
Report
)
{
return
\
in_array
(
$attribute
,
[
self
::
CREATE
,
self
::
UPDATE
,
self
::
SEE
]);
}
else
{
return
false
;
}
}
protected
function
isGranted
(
$attribute
,
$report
,
$user
=
null
)
protected
function
voteOnAttribute
(
$attribute
,
$subject
,
TokenInterface
$token
)
{
if
(
!
$user
instanceof
\
Chill\MainBundle\Entity\User
){
if
(
!
$token
->
getUser
()
instanceof
User
)
{
return
false
;
}
return
$this
->
helper
->
userHasAccess
(
$user
,
$report
,
$attribute
);
return
$this
->
helper
->
userHasAccess
(
$token
->
getUser
(),
$subject
,
$attribute
);
}
public
function
getRoles
()
{
return
$this
->
getSupportedAttributes
();
...
...
@@ -74,7 +82,7 @@ class ReportVoter extends AbstractChillVoter implements ProvideRoleHierarchyInte
{
return
array
();
}
public
function
getRolesWithHierarchy
()
{
return
[
'Report'
=>
$this
->
getRoles
()
];
...
...
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