{"action":"created","comment":{"url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments/32103396","id":32103396,"diff_hunk":"@@ -0,0 +1,221 @@\n+<?php\n+\n+namespace Pim\\Bundle\\EnrichBundle\\Controller;\n+\n+use Oro\\Bundle\\SecurityBundle\\Annotation\\AclAncestor;\n+use Pim\\Bundle\\CatalogBundle\\Manager\\ProductManager;\n+use Pim\\Bundle\\CommentBundle\\Builder\\CommentBuilder;\n+use Pim\\Bundle\\CommentBundle\\Manager\\CommentManager;\n+use Symfony\\Component\\Form\\FormFactoryInterface;\n+use Symfony\\Component\\HttpFoundation\\JsonResponse;\n+use Symfony\\Component\\HttpFoundation\\Request;\n+use Symfony\\Component\\Security\\Core\\SecurityContextInterface;\n+use Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface;\n+use Symfony\\Component\\Validator\\ValidatorInterface;\n+\n+/**\n+ * Controller for product comments\n+ *\n+ * @author    Filips Alpe <filips@akeneo.com>\n+ * @copyright 2015 Akeneo SAS (http://www.akeneo.com)\n+ * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)\n+ */\n+class ProductCommentRestController\n+{\n+    /** @var SecurityContextInterface */\n+    protected $securityContext;\n+\n+    /** @var FormFactoryInterface */\n+    protected $formFactory;\n+\n+    /** @var ProductManager */\n+    protected $productManager;\n+\n+    /** @var CommentManager */\n+    protected $commentManager;\n+\n+    /** @var CommentBuilder */\n+    protected $commentBuilder;\n+\n+    /** @var NormalizerInterface */\n+    protected $normalizer;\n+\n+    /** @var ValidatorInterface */\n+    protected $validator;\n+\n+    /**\n+     * Constructor\n+     *\n+     * @param SecurityContextInterface $securityContext\n+     * @param FormFactoryInterface     $formFactory\n+     * @param ProductManager           $productManager\n+     * @param CommentManager           $commentManager\n+     * @param CommentBuilder           $commentBuilder\n+     * @param NormalizerInterface      $normalizer\n+     * @param ValidatorInterface       $validator\n+     */\n+    public function __construct(\n+        SecurityContextInterface $securityContext,\n+        FormFactoryInterface $formFactory,\n+        ProductManager $productManager,\n+        CommentManager $commentManager,\n+        CommentBuilder $commentBuilder,\n+        NormalizerInterface $normalizer,\n+        ValidatorInterface $validator\n+    ) {\n+        $this->securityContext = $securityContext;\n+        $this->formFactory     = $formFactory;\n+        $this->productManager  = $productManager;\n+        $this->commentManager  = $commentManager;\n+        $this->commentBuilder  = $commentBuilder;\n+        $this->normalizer      = $normalizer;\n+        $this->validator       = $validator;\n+    }\n+\n+    /**\n+     * List comments made on a product\n+     *\n+     * @param Request    $request\n+     * @param int|string $id\n+     *\n+     * @AclAncestor(\"pim_enrich_product_comment\")\n+     *\n+     * @return \\Symfony\\Component\\HttpFoundation\\Response\n+     */\n+    public function getAction(Request $request, $id)\n+    {\n+        $product = $this->findProductOr404($id);\n+        $comments = $this->commentManager->getComments($product);\n+        $class = $this->productManager->getProductName();\n+\n+        return new JsonResponse($this->normalizer->normalize($comments, 'json'));\n+    }\n+\n+    /**\n+     * Create a comment on a product\n+     *\n+     * @param Request $request\n+     * @param string  $id\n+     *\n+     * @return JsonResponse\n+     */\n+    public function postAction(Request $request, $id)\n+    {\n+        $product = $this->findProductOr404($id);\n+\n+        $data = json_decode($request->getContent(), true);\n+\n+        $comment = $this->commentBuilder->buildComment($product, $this->getUser());\n+\n+        $form = $this->formFactory->create('pim_comment_comment', $comment, ['csrf_protection' => false]);\n+\n+        $form->submit($data, false);\n+\n+        if ($form->isValid()) {\n+            $this->commentManager->save($comment);\n+\n+            return new JsonResponse($this->normalizer->normalize($comment, 'json'));\n+        }\n+\n+        $violations = $this->validator->validate($comment);\n+\n+        $errors = [];\n+        foreach ($violations as $violation) {\n+            $errors[$violation->getPropertyPath()] = [\n+                'message'       => $violation->getMessage(),\n+                'invalid_value' => $violation->getInvalidValue()\n+            ];\n+        }\n+\n+        return new JsonResponse($errors, 400);\n+    }\n+\n+    /**\n+     * Reply to a product comment\n+     *\n+     * @param Request $request\n+     * @param string  $id\n+     * @param string  $commentId\n+     *\n+     * @return JsonResponse\n+     */\n+    public function postReplyAction(Request $request, $id, $commentId)\n+    {\n+        $product = $this->findProductOr404($id);\n+\n+        $data = json_decode($request->getContent(), true);\n+        $data['parent'] = $commentId;\n+\n+        $reply = $this->commentBuilder->buildComment($product, $this->getUser());\n+        $form = $this->formFactory->create(\n+            'pim_comment_comment',\n+            $reply,\n+            ['is_reply' => true, 'csrf_protection' => false]\n+        );\n+        $form->submit($data, false);\n+\n+        if ($form->isValid()) {\n+            $now = new \\DateTime();\n+            $reply->setCreatedAt($now);\n+            $reply->setRepliedAt($now);\n+            $comment = $reply->getParent();\n+            $comment->setRepliedAt($now);\n+\n+            $this->commentManager->save($reply);\n+\n+            return new JsonResponse($this->normalizer->normalize($reply, 'json'));\n+        }\n+\n+        $violations = $this->validator->validate($reply);\n+\n+        $errors = [];\n+        foreach ($violations as $violation) {\n+            $errors[$violation->getPropertyPath()] = [\n+                'message'       => $violation->getMessage(),\n+                'invalid_value' => $violation->getInvalidValue()\n+            ];\n+        }\n+\n+        return new JsonResponse($errors, 400);\n+    }\n+\n+    /**\n+     * Find a product by its id or return a 404 response\n+     *\n+     * @param int $id the product id\n+     *\n+     * @throws \\Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException\n+     *\n+     * @return \\Pim\\Bundle\\CatalogBundle\\Model\\ProductInterface\n+     */\n+    protected function findProductOr404($id)\n+    {\n+        $product = $this->productManager->find($id);\n+\n+        if (!$product) {\n+            throw $this->createNotFoundException(","path":"src/Pim/Bundle/EnrichBundle/Controller/ProductCommentRestController.php","position":196,"original_position":196,"commit_id":"5d5ed9f82032b1ef7eb6b6fc57e54896fe074984","original_commit_id":"5d5ed9f82032b1ef7eb6b6fc57e54896fe074984","user":{"login":"grena","id":301169,"avatar_url":"https://avatars.githubusercontent.com/u/301169?v=3","gravatar_id":"","url":"https://api.github.com/users/grena","html_url":"https://github.com/grena","followers_url":"https://api.github.com/users/grena/followers","following_url":"https://api.github.com/users/grena/following{/other_user}","gists_url":"https://api.github.com/users/grena/gists{/gist_id}","starred_url":"https://api.github.com/users/grena/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grena/subscriptions","organizations_url":"https://api.github.com/users/grena/orgs","repos_url":"https://api.github.com/users/grena/repos","events_url":"https://api.github.com/users/grena/events{/privacy}","received_events_url":"https://api.github.com/users/grena/received_events","type":"User","site_admin":false},"body":"It seems that this method doesn't exist","created_at":"2015-06-10T10:02:16Z","updated_at":"2015-06-10T10:02:16Z","html_url":"https://github.com/akeneo/pim-community-dev/pull/2693#discussion_r32103396","pull_request_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/2693","_links":{"self":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments/32103396"},"html":{"href":"https://github.com/akeneo/pim-community-dev/pull/2693#discussion_r32103396"},"pull_request":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/2693"}}},"pull_request":{"url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/2693","id":35940602,"html_url":"https://github.com/akeneo/pim-community-dev/pull/2693","diff_url":"https://github.com/akeneo/pim-community-dev/pull/2693.diff","patch_url":"https://github.com/akeneo/pim-community-dev/pull/2693.patch","issue_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/2693","number":2693,"state":"open","locked":false,"title":"Product edit form revamp","user":{"login":"sumbobyboys","id":1117272,"avatar_url":"https://avatars.githubusercontent.com/u/1117272?v=3","gravatar_id":"","url":"https://api.github.com/users/sumbobyboys","html_url":"https://github.com/sumbobyboys","followers_url":"https://api.github.com/users/sumbobyboys/followers","following_url":"https://api.github.com/users/sumbobyboys/following{/other_user}","gists_url":"https://api.github.com/users/sumbobyboys/gists{/gist_id}","starred_url":"https://api.github.com/users/sumbobyboys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sumbobyboys/subscriptions","organizations_url":"https://api.github.com/users/sumbobyboys/orgs","repos_url":"https://api.github.com/users/sumbobyboys/repos","events_url":"https://api.github.com/users/sumbobyboys/events{/privacy}","received_events_url":"https://api.github.com/users/sumbobyboys/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-05-21T14:41:22Z","updated_at":"2015-06-10T10:02:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4b547cf49e3b643406cfeb7a97c207fc258ff5e0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/2693/commits","review_comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/2693/comments","review_comment_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments{/number}","comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/2693/comments","statuses_url":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/5d5ed9f82032b1ef7eb6b6fc57e54896fe074984","head":{"label":"akeneo:feature/product_edit_form","ref":"feature/product_edit_form","sha":"5d5ed9f82032b1ef7eb6b6fc57e54896fe074984","user":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.githubusercontent.com/u/2510186?v=3","gravatar_id":"","url":"https://api.github.com/users/akeneo","html_url":"https://github.com/akeneo","followers_url":"https://api.github.com/users/akeneo/followers","following_url":"https://api.github.com/users/akeneo/following{/other_user}","gists_url":"https://api.github.com/users/akeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/akeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akeneo/subscriptions","organizations_url":"https://api.github.com/users/akeneo/orgs","repos_url":"https://api.github.com/users/akeneo/repos","events_url":"https://api.github.com/users/akeneo/events{/privacy}","received_events_url":"https://api.github.com/users/akeneo/received_events","type":"Organization","site_admin":false},"repo":{"id":5367323,"name":"pim-community-dev","full_name":"akeneo/pim-community-dev","owner":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.githubusercontent.com/u/2510186?v=3","gravatar_id":"","url":"https://api.github.com/users/akeneo","html_url":"https://github.com/akeneo","followers_url":"https://api.github.com/users/akeneo/followers","following_url":"https://api.github.com/users/akeneo/following{/other_user}","gists_url":"https://api.github.com/users/akeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/akeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akeneo/subscriptions","organizations_url":"https://api.github.com/users/akeneo/orgs","repos_url":"https://api.github.com/users/akeneo/repos","events_url":"https://api.github.com/users/akeneo/events{/privacy}","received_events_url":"https://api.github.com/users/akeneo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/akeneo/pim-community-dev","description":"Akeneo PIM development repository","fork":false,"url":"https://api.github.com/repos/akeneo/pim-community-dev","forks_url":"https://api.github.com/repos/akeneo/pim-community-dev/forks","keys_url":"https://api.github.com/repos/akeneo/pim-community-dev/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akeneo/pim-community-dev/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akeneo/pim-community-dev/teams","hooks_url":"https://api.github.com/repos/akeneo/pim-community-dev/hooks","issue_events_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/events{/number}","events_url":"https://api.github.com/repos/akeneo/pim-community-dev/events","assignees_url":"https://api.github.com/repos/akeneo/pim-community-dev/assignees{/user}","branches_url":"https://api.github.com/repos/akeneo/pim-community-dev/branches{/branch}","tags_url":"https://api.github.com/repos/akeneo/pim-community-dev/tags","blobs_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/refs{/sha}","trees_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/{sha}","languages_url":"https://api.github.com/repos/akeneo/pim-community-dev/languages","stargazers_url":"https://api.github.com/repos/akeneo/pim-community-dev/stargazers","contributors_url":"https://api.github.com/repos/akeneo/pim-community-dev/contributors","subscribers_url":"https://api.github.com/repos/akeneo/pim-community-dev/subscribers","subscription_url":"https://api.github.com/repos/akeneo/pim-community-dev/subscription","commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/commits{/sha}","git_commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/commits{/sha}","comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/comments{/number}","issue_comment_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/comments{/number}","contents_url":"https://api.github.com/repos/akeneo/pim-community-dev/contents/{+path}","compare_url":"https://api.github.com/repos/akeneo/pim-community-dev/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akeneo/pim-community-dev/merges","archive_url":"https://api.github.com/repos/akeneo/pim-community-dev/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akeneo/pim-community-dev/downloads","issues_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues{/number}","pulls_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls{/number}","milestones_url":"https://api.github.com/repos/akeneo/pim-community-dev/milestones{/number}","notifications_url":"https://api.github.com/repos/akeneo/pim-community-dev/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akeneo/pim-community-dev/labels{/name}","releases_url":"https://api.github.com/repos/akeneo/pim-community-dev/releases{/id}","created_at":"2012-08-10T09:27:26Z","updated_at":"2015-06-06T08:22:05Z","pushed_at":"2015-06-10T09:41:18Z","git_url":"git://github.com/akeneo/pim-community-dev.git","ssh_url":"git@github.com:akeneo/pim-community-dev.git","clone_url":"https://github.com/akeneo/pim-community-dev.git","svn_url":"https://github.com/akeneo/pim-community-dev","homepage":"http://akeneo.com","size":157600,"stargazers_count":229,"watchers_count":229,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":114,"mirror_url":null,"open_issues_count":54,"forks":114,"open_issues":54,"watchers":229,"default_branch":"master"}},"base":{"label":"akeneo:master","ref":"master","sha":"2597e54539c51bd7e19212c00da7d0852e3616d8","user":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.githubusercontent.com/u/2510186?v=3","gravatar_id":"","url":"https://api.github.com/users/akeneo","html_url":"https://github.com/akeneo","followers_url":"https://api.github.com/users/akeneo/followers","following_url":"https://api.github.com/users/akeneo/following{/other_user}","gists_url":"https://api.github.com/users/akeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/akeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akeneo/subscriptions","organizations_url":"https://api.github.com/users/akeneo/orgs","repos_url":"https://api.github.com/users/akeneo/repos","events_url":"https://api.github.com/users/akeneo/events{/privacy}","received_events_url":"https://api.github.com/users/akeneo/received_events","type":"Organization","site_admin":false},"repo":{"id":5367323,"name":"pim-community-dev","full_name":"akeneo/pim-community-dev","owner":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.githubusercontent.com/u/2510186?v=3","gravatar_id":"","url":"https://api.github.com/users/akeneo","html_url":"https://github.com/akeneo","followers_url":"https://api.github.com/users/akeneo/followers","following_url":"https://api.github.com/users/akeneo/following{/other_user}","gists_url":"https://api.github.com/users/akeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/akeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akeneo/subscriptions","organizations_url":"https://api.github.com/users/akeneo/orgs","repos_url":"https://api.github.com/users/akeneo/repos","events_url":"https://api.github.com/users/akeneo/events{/privacy}","received_events_url":"https://api.github.com/users/akeneo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/akeneo/pim-community-dev","description":"Akeneo PIM development repository","fork":false,"url":"https://api.github.com/repos/akeneo/pim-community-dev","forks_url":"https://api.github.com/repos/akeneo/pim-community-dev/forks","keys_url":"https://api.github.com/repos/akeneo/pim-community-dev/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akeneo/pim-community-dev/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akeneo/pim-community-dev/teams","hooks_url":"https://api.github.com/repos/akeneo/pim-community-dev/hooks","issue_events_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/events{/number}","events_url":"https://api.github.com/repos/akeneo/pim-community-dev/events","assignees_url":"https://api.github.com/repos/akeneo/pim-community-dev/assignees{/user}","branches_url":"https://api.github.com/repos/akeneo/pim-community-dev/branches{/branch}","tags_url":"https://api.github.com/repos/akeneo/pim-community-dev/tags","blobs_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/refs{/sha}","trees_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/{sha}","languages_url":"https://api.github.com/repos/akeneo/pim-community-dev/languages","stargazers_url":"https://api.github.com/repos/akeneo/pim-community-dev/stargazers","contributors_url":"https://api.github.com/repos/akeneo/pim-community-dev/contributors","subscribers_url":"https://api.github.com/repos/akeneo/pim-community-dev/subscribers","subscription_url":"https://api.github.com/repos/akeneo/pim-community-dev/subscription","commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/commits{/sha}","git_commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/commits{/sha}","comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/comments{/number}","issue_comment_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/comments{/number}","contents_url":"https://api.github.com/repos/akeneo/pim-community-dev/contents/{+path}","compare_url":"https://api.github.com/repos/akeneo/pim-community-dev/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akeneo/pim-community-dev/merges","archive_url":"https://api.github.com/repos/akeneo/pim-community-dev/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akeneo/pim-community-dev/downloads","issues_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues{/number}","pulls_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls{/number}","milestones_url":"https://api.github.com/repos/akeneo/pim-community-dev/milestones{/number}","notifications_url":"https://api.github.com/repos/akeneo/pim-community-dev/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akeneo/pim-community-dev/labels{/name}","releases_url":"https://api.github.com/repos/akeneo/pim-community-dev/releases{/id}","created_at":"2012-08-10T09:27:26Z","updated_at":"2015-06-06T08:22:05Z","pushed_at":"2015-06-10T09:41:18Z","git_url":"git://github.com/akeneo/pim-community-dev.git","ssh_url":"git@github.com:akeneo/pim-community-dev.git","clone_url":"https://github.com/akeneo/pim-community-dev.git","svn_url":"https://github.com/akeneo/pim-community-dev","homepage":"http://akeneo.com","size":157600,"stargazers_count":229,"watchers_count":229,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":114,"mirror_url":null,"open_issues_count":54,"forks":114,"open_issues":54,"watchers":229,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/2693"},"html":{"href":"https://github.com/akeneo/pim-community-dev/pull/2693"},"issue":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/issues/2693"},"comments":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/issues/2693/comments"},"review_comments":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/2693/comments"},"review_comment":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/2693/commits"},"statuses":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/5d5ed9f82032b1ef7eb6b6fc57e54896fe074984"}}}}