コード例 #1
0
 /**
  * @param  MediaFolder $mediaFolder
  * @param  Request     $request
  * @return Response
  *
  * @Rest\ParamConverter(name="mediaFolder", class="BackBee\NestedNode\MediaFolder")
  * @Rest\Security("is_fully_authenticated() & has_role('ROLE_API_USER') & is_granted('EDIT', mediaFolder)")
  */
 public function patchAction(MediaFolder $mediaFolder, Request $request)
 {
     $operations = $request->request->all();
     try {
         (new OperationSyntaxValidator())->validate($operations);
     } catch (InvalidOperationSyntaxException $e) {
         throw new BadRequestHttpException('operation invalid syntax: ' . $e->getMessage());
     }
     $this->patchSiblingAndParentOperation($mediaFolder, $operations);
     $entityPatcher = new EntityPatcher(new RightManager($this->getSerializer()->getMetadataFactory()));
     try {
         $entityPatcher->patch($mediaFolder, $operations);
     } catch (UnauthorizedPatchOperationException $e) {
         throw new BadRequestHttpException('Invalid patch operation: ' . $e->getMessage());
     }
     $this->getEntityManager()->flush();
     return $this->createJsonResponse(null, 204);
 }
コード例 #2
0
ファイル: PageController.php プロジェクト: Bensid/BackBee
 /**
  * Patch page.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  *
  * @Rest\RequestParam(name="0", description="Patch operations", requirements={
  *   @Assert\NotBlank(message="Request must contain at least one operation")
  * })
  *
  * @Rest\ParamConverter(name="page", class="BackBee\NestedNode\Page")
  * @Rest\Security(expression="is_granted('EDIT', page)")
  */
 public function patchAction(Page $page, Request $request)
 {
     $operations = $request->request->all();
     try {
         (new OperationSyntaxValidator())->validate($operations);
     } catch (InvalidOperationSyntaxException $e) {
         throw new BadRequestHttpException('operation invalid syntax: ' . $e->getMessage());
     }
     $entity_patcher = new EntityPatcher(new RightManager($this->getSerializer()->getMetadataFactory()));
     $entity_patcher->getRightManager()->addAuthorizationMapping($page, array('publishing' => array('replace'), 'archiving' => array('replace')));
     $this->patchStateOperation($page, $operations);
     $this->patchSiblingAndParentOperation($page, $operations);
     try {
         $entity_patcher->patch($page, $operations);
     } catch (UnauthorizedPatchOperationException $e) {
         throw new BadRequestHttpException('Invalid patch operation: ' . $e->getMessage());
     }
     if (true === $page->isOnline(true)) {
         $this->granted('PUBLISH', $page);
     }
     $this->getEntityManager()->flush();
     return $this->createJsonResponse(null, 204);
 }
コード例 #3
0
 /**
  * Patch the bundle.
  *
  * @Rest\RequestParam(name="0", description="Patch operations", requirements={
  *   @Assert\NotBlank(message="Request must contain at least one operation")
  * })
  *
  * @param string $id the id of the bundle we are looking for
  */
 public function patchAction($id, Request $request)
 {
     $bundle = $this->getBundleById($id);
     $this->granted('EDIT', $bundle);
     $operations = $request->request->all();
     try {
         (new OperationSyntaxValidator())->validate($operations);
     } catch (InvalidOperationSyntaxException $e) {
         throw new BadRequestHttpException('operation invalid syntax: ' . $e->getMessage());
     }
     $entity_patcher = new EntityPatcher(new RightManager($this->getSerializer()->getMetadataFactory()));
     $entity_patcher->getRightManager()->addAuthorizationMapping($bundle, array('category' => array('replace'), 'config_per_site' => array('replace'), 'enable' => array('replace')));
     try {
         $entity_patcher->patch($bundle, $operations);
     } catch (UnauthorizedPatchOperationException $e) {
         throw new BadRequestHttpException('Invalid patch operation: ' . $e->getMessage());
     }
     $this->getApplication()->getContainer()->get('config.persistor')->persist($bundle->getConfig(), null !== $bundle->getConfig()->getProperty('config_per_site') ? $bundle->getConfig()->getProperty('config_per_site') : false);
     return $this->createJsonResponse(null, 204);
 }