| @@ 27-52 (lines=26) @@ | ||
| 24 | * @author Mathias Gelhausen <[email protected]> |
|
| 25 | * @todo write test |
|
| 26 | */ |
|
| 27 | class MayChangeCv implements AssertionInterface |
|
| 28 | { |
|
| 29 | /** |
|
| 30 | * Returns true if and only if the assertion conditions are met |
|
| 31 | * |
|
| 32 | * This method is passed the ACL, Role, Resource, and privilege to which the authorization query applies. If the |
|
| 33 | * $role, $resource, or $privilege parameters are null, it means that the query applies to all Roles, Resources, or |
|
| 34 | * privileges, respectively. |
|
| 35 | * |
|
| 36 | * @param Acl $acl |
|
| 37 | * @param RoleInterface $role |
|
| 38 | * @param ResourceInterface $resource |
|
| 39 | * @param string $privilege |
|
| 40 | * |
|
| 41 | * @return bool |
|
| 42 | */ |
|
| 43 | public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null) |
|
| 44 | { |
|
| 45 | return $role instanceOf UserInterface |
|
| 46 | && $resource instanceOf CvInterface |
|
| 47 | && 'edit' == $privilege |
|
| 48 | && $resource->getPermissions()->isGranted($role, PermissionsInterface::PERMISSION_CHANGE); |
|
| 49 | } |
|
| 50 | ||
| 51 | ||
| 52 | } |
|
| @@ 29-56 (lines=28) @@ | ||
| 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 | ||
| 56 | } |
|
| @@ 27-36 (lines=10) @@ | ||
| 24 | * @author Mathias Gelhausen <[email protected]> |
|
| 25 | * @todo write test |
|
| 26 | */ |
|
| 27 | class WriteAssertion implements AssertionInterface |
|
| 28 | { |
|
| 29 | public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null) |
|
| 30 | { |
|
| 31 | return 'edit' == $privilege |
|
| 32 | && $role instanceOf UserInterface |
|
| 33 | && $resource instanceOf OrganizationInterface |
|
| 34 | && $resource->getPermissions()->isGranted($role, PermissionsInterface::PERMISSION_CHANGE); |
|
| 35 | } |
|
| 36 | } |
|