|
28 | 28 | use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityUpdatedEvent; |
29 | 29 | use EasyCorp\Bundle\EasyAdminBundle\Exception\EntityRemoveException; |
30 | 30 | use EasyCorp\Bundle\EasyAdminBundle\Exception\ForbiddenActionException; |
| 31 | +use EasyCorp\Bundle\EasyAdminBundle\Exception\InsufficientEntityPermissionException; |
31 | 32 | use EasyCorp\Bundle\EasyAdminBundle\Factory\ActionFactory; |
32 | 33 | use EasyCorp\Bundle\EasyAdminBundle\Factory\EntityFactory; |
33 | 34 | use EasyCorp\Bundle\EasyAdminBundle\Factory\FilterFactory; |
@@ -115,7 +116,7 @@ public function index(AdminContext $context) |
115 | 116 | $queryBuilder = $this->createIndexQueryBuilder($context->getSearch(), $context->getEntity(), $fields, $filters); |
116 | 117 | $paginator = $this->get(PaginatorFactory::class)->create($queryBuilder); |
117 | 118 |
|
118 | | - $entities = EntityCollection::new($context->getEntity(), $paginator->getResults()); |
| 119 | + $entities = $this->get(EntityFactory::class)->createCollection($context->getEntity(), $paginator->getResults()); |
119 | 120 | $this->get(EntityFactory::class)->processFieldsForAll($entities, $fields); |
120 | 121 | $globalActions = $this->get(EntityFactory::class)->processActionsForAll($entities, $context->getCrud()->getActionsConfig()); |
121 | 122 |
|
@@ -150,6 +151,10 @@ public function detail(AdminContext $context) |
150 | 151 | throw new ForbiddenActionException($context); |
151 | 152 | } |
152 | 153 |
|
| 154 | + if (!$context->getEntity()->isAccessible()) { |
| 155 | + throw new InsufficientEntityPermissionException($context); |
| 156 | + } |
| 157 | + |
153 | 158 | $this->get(EntityFactory::class)->processFields($context->getEntity(), FieldCollection::new($this->configureFields(Crud::PAGE_DETAIL))); |
154 | 159 | $this->get(EntityFactory::class)->processActions($context->getEntity(), $context->getCrud()->getActionsConfig()); |
155 | 160 |
|
@@ -180,6 +185,10 @@ public function edit(AdminContext $context) |
180 | 185 | throw new ForbiddenActionException($context); |
181 | 186 | } |
182 | 187 |
|
| 188 | + if (!$context->getEntity()->isAccessible()) { |
| 189 | + throw new InsufficientEntityPermissionException($context); |
| 190 | + } |
| 191 | + |
183 | 192 | $this->get(EntityFactory::class)->processFields($context->getEntity(), FieldCollection::new($this->configureFields(Crud::PAGE_EDIT))); |
184 | 193 | $this->get(EntityFactory::class)->processActions($context->getEntity(), $context->getCrud()->getActionsConfig()); |
185 | 194 | $entityInstance = $context->getEntity()->getInstance(); |
@@ -259,6 +268,10 @@ public function new(AdminContext $context) |
259 | 268 | throw new ForbiddenActionException($context); |
260 | 269 | } |
261 | 270 |
|
| 271 | + if (!$context->getEntity()->isAccessible()) { |
| 272 | + throw new InsufficientEntityPermissionException($context); |
| 273 | + } |
| 274 | + |
262 | 275 | $context->getEntity()->setInstance($this->createEntity($context->getEntity()->getFqcn())); |
263 | 276 | $this->get(EntityFactory::class)->processFields($context->getEntity(), FieldCollection::new($this->configureFields(Crud::PAGE_NEW))); |
264 | 277 | $this->get(EntityFactory::class)->processActions($context->getEntity(), $context->getCrud()->getActionsConfig()); |
@@ -333,6 +346,10 @@ public function delete(AdminContext $context) |
333 | 346 | throw new ForbiddenActionException($context); |
334 | 347 | } |
335 | 348 |
|
| 349 | + if (!$context->getEntity()->isAccessible()) { |
| 350 | + throw new InsufficientEntityPermissionException($context); |
| 351 | + } |
| 352 | + |
336 | 353 | $csrfToken = $context->getRequest()->request->get('token'); |
337 | 354 | if (!$this->isCsrfTokenValid('ea-delete', $csrfToken)) { |
338 | 355 | return $this->redirectToRoute($context->getDashboardRouteName()); |
|
0 commit comments