1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oro\Bundle\ActivityBundle\Entity\Manager; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
6
|
|
|
use Doctrine\ORM\EntityNotFoundException; |
7
|
|
|
|
8
|
|
|
use Oro\Bundle\ActivityBundle\Manager\ActivityManager; |
9
|
|
|
use Oro\Bundle\ActivityBundle\Model\ActivityInterface; |
10
|
|
|
use Oro\Bundle\SecurityBundle\Exception\ForbiddenException; |
11
|
|
|
use Oro\Bundle\SecurityBundle\SecurityFacade; |
12
|
|
|
use Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager; |
13
|
|
|
use Oro\Bundle\SoapBundle\Handler\DeleteHandler; |
14
|
|
|
use Oro\Bundle\SoapBundle\Model\RelationIdentifier; |
15
|
|
|
|
16
|
|
|
class ActivityEntityDeleteHandler extends DeleteHandler |
17
|
|
|
{ |
18
|
|
|
/** @var SecurityFacade */ |
19
|
|
|
protected $securityFacade; |
20
|
|
|
|
21
|
|
|
/** @var ActivityManager */ |
22
|
|
|
protected $activityManager; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param SecurityFacade $securityFacade |
26
|
|
|
*/ |
27
|
|
|
public function setSecurityFacade(SecurityFacade $securityFacade) |
28
|
|
|
{ |
29
|
|
|
$this->securityFacade = $securityFacade; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param ActivityManager $activityManager |
34
|
|
|
*/ |
35
|
|
|
public function setActivityManager(ActivityManager $activityManager) |
36
|
|
|
{ |
37
|
|
|
$this->activityManager = $activityManager; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Handle delete entity object. |
42
|
|
|
* |
43
|
|
|
* @param RelationIdentifier $id |
44
|
|
|
* @param ApiEntityManager $manager |
45
|
|
|
* |
46
|
|
|
* @throws EntityNotFoundException if an entity with the given id does not exist |
47
|
|
|
* @throws ForbiddenException if a delete operation is forbidden |
48
|
|
|
*/ |
49
|
|
|
public function handleDelete($id, ApiEntityManager $manager) |
50
|
|
|
{ |
51
|
|
|
$em = $manager->getObjectManager(); |
52
|
|
|
|
53
|
|
|
/** @var ActivityInterface $entity */ |
54
|
|
|
$entity = $em->find($id->getOwnerEntityClass(), $id->getOwnerEntityId()); |
55
|
|
|
if (!$entity) { |
56
|
|
|
throw new EntityNotFoundException(); |
57
|
|
|
} |
58
|
|
|
$this->checkPermissions($entity, $em); |
59
|
|
|
|
60
|
|
|
$targetEntity = $em->find($id->getTargetEntityClass(), $id->getTargetEntityId()); |
61
|
|
|
if (!$targetEntity) { |
62
|
|
|
throw new EntityNotFoundException(); |
63
|
|
|
} |
64
|
|
|
$this->checkPermissionsForTargetEntity($targetEntity, $em); |
65
|
|
|
|
66
|
|
|
$this->activityManager->removeActivityTarget($entity, $targetEntity); |
67
|
|
|
|
68
|
|
|
$em->flush(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
|
|
protected function checkPermissions($entity, ObjectManager $em) |
75
|
|
|
{ |
76
|
|
|
if (!$this->securityFacade->isGranted('EDIT', $entity)) { |
77
|
|
|
throw new ForbiddenException('has no edit permissions for activity entity'); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
|
|
protected function checkPermissionsForTargetEntity($entity, ObjectManager $em) |
|
|
|
|
85
|
|
|
{ |
86
|
|
|
if (!$this->securityFacade->isGranted('VIEW', $entity)) { |
87
|
|
|
throw new ForbiddenException('has no view permissions for related entity'); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.