1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* YAWIK |
4
|
|
|
* |
5
|
|
|
* @filesource |
6
|
|
|
* @license MIT |
7
|
|
|
* @copyright 2013 - 2016 Cross Solution <http://cross-solution.de> |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** */ |
11
|
|
|
namespace Cv\Acl\Assertion; |
12
|
|
|
|
13
|
|
|
use Cv\Entity\Cv; |
14
|
|
|
use Auth\Entity\UserInterface; |
15
|
|
|
use Core\Entity\PermissionsInterface; |
16
|
|
|
use Cv\Entity\CvInterface; |
17
|
|
|
use Cv\Entity\Status; |
18
|
|
|
use Laminas\Permissions\Acl\Acl; |
19
|
|
|
use Laminas\Permissions\Acl\Assertion\AssertionInterface; |
20
|
|
|
use Laminas\Permissions\Acl\Resource\ResourceInterface; |
21
|
|
|
use Laminas\Permissions\Acl\Role\RoleInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* ${CARET} |
25
|
|
|
* |
26
|
|
|
* @author Mathias Gelhausen <[email protected]> |
27
|
|
|
* @todo write test |
28
|
|
|
*/ |
29
|
|
|
class MayViewCv implements AssertionInterface |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Returns true if and only if the assertion conditions are met |
33
|
|
|
* |
34
|
|
|
* This method is passed the ACL, Role, Resource, and privilege to which the authorization query applies. If the |
35
|
|
|
* $role, $resource, or $privilege parameters are null, it means that the query applies to all Roles, Resources, or |
36
|
|
|
* privileges, respectively. |
37
|
|
|
* |
38
|
|
|
* @param Acl $acl |
39
|
|
|
* @param RoleInterface $role |
40
|
|
|
* @param ResourceInterface $resource |
41
|
|
|
* @param string $privilege |
42
|
|
|
* |
43
|
|
|
* @return bool |
44
|
|
|
*/ |
45
|
|
|
public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null) |
46
|
|
|
{ |
47
|
|
|
/* @var ResourceInterface|Cv $resource */ |
48
|
|
|
return $role instanceof UserInterface |
49
|
|
|
&& $resource instanceof CvInterface |
50
|
|
|
&& 'view' == $privilege |
51
|
|
|
&& ($resource->getPermissions()->isGranted($role, PermissionsInterface::PERMISSION_VIEW) |
52
|
|
|
|| Status::PUBLIC_TO_ALL == (string) $resource->getStatus()); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|