diff options
author | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2016-10-29 13:20:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-29 13:20:55 +0200 |
commit | 5feef9f7a4e6852415feb388190b7ca141f116d1 (patch) | |
tree | 773b12c221b089ba508040e855d78f27edb589b0 /src/Wallabag/ApiBundle | |
parent | 8e58be9fb62615cdd8f4b55ad0981f57641bf0ab (diff) | |
parent | f08ec5f88a78bfe2edf2c2148094f3f099e8389c (diff) | |
download | wallabag-5feef9f7a4e6852415feb388190b7ca141f116d1.tar.gz wallabag-5feef9f7a4e6852415feb388190b7ca141f116d1.tar.zst wallabag-5feef9f7a4e6852415feb388190b7ca141f116d1.zip |
Merge pull request #2499 from wallabag/add-relation-client-user
Added relation between API Client and User
Diffstat (limited to 'src/Wallabag/ApiBundle')
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/DeveloperController.php | 8 | ||||
-rw-r--r-- | src/Wallabag/ApiBundle/Entity/Client.php | 17 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/DeveloperController.php b/src/Wallabag/ApiBundle/Controller/DeveloperController.php index 5a36a260..550c0608 100644 --- a/src/Wallabag/ApiBundle/Controller/DeveloperController.php +++ b/src/Wallabag/ApiBundle/Controller/DeveloperController.php | |||
@@ -19,7 +19,7 @@ class DeveloperController extends Controller | |||
19 | */ | 19 | */ |
20 | public function indexAction() | 20 | public function indexAction() |
21 | { | 21 | { |
22 | $clients = $this->getDoctrine()->getRepository('WallabagApiBundle:Client')->findAll(); | 22 | $clients = $this->getDoctrine()->getRepository('WallabagApiBundle:Client')->findByUser($this->getUser()->getId()); |
23 | 23 | ||
24 | return $this->render('@WallabagCore/themes/common/Developer/index.html.twig', [ | 24 | return $this->render('@WallabagCore/themes/common/Developer/index.html.twig', [ |
25 | 'clients' => $clients, | 25 | 'clients' => $clients, |
@@ -38,7 +38,7 @@ class DeveloperController extends Controller | |||
38 | public function createClientAction(Request $request) | 38 | public function createClientAction(Request $request) |
39 | { | 39 | { |
40 | $em = $this->getDoctrine()->getManager(); | 40 | $em = $this->getDoctrine()->getManager(); |
41 | $client = new Client(); | 41 | $client = new Client($this->getUser()); |
42 | $clientForm = $this->createForm(ClientType::class, $client); | 42 | $clientForm = $this->createForm(ClientType::class, $client); |
43 | $clientForm->handleRequest($request); | 43 | $clientForm->handleRequest($request); |
44 | 44 | ||
@@ -75,6 +75,10 @@ class DeveloperController extends Controller | |||
75 | */ | 75 | */ |
76 | public function deleteClientAction(Client $client) | 76 | public function deleteClientAction(Client $client) |
77 | { | 77 | { |
78 | if (null === $this->getUser() || $client->getUser()->getId() != $this->getUser()->getId()) { | ||
79 | throw $this->createAccessDeniedException('You can not access this client.'); | ||
80 | } | ||
81 | |||
78 | $em = $this->getDoctrine()->getManager(); | 82 | $em = $this->getDoctrine()->getManager(); |
79 | $em->remove($client); | 83 | $em->remove($client); |
80 | $em->flush(); | 84 | $em->flush(); |
diff --git a/src/Wallabag/ApiBundle/Entity/Client.php b/src/Wallabag/ApiBundle/Entity/Client.php index f7898ac8..427a4c7f 100644 --- a/src/Wallabag/ApiBundle/Entity/Client.php +++ b/src/Wallabag/ApiBundle/Entity/Client.php | |||
@@ -4,6 +4,7 @@ namespace Wallabag\ApiBundle\Entity; | |||
4 | 4 | ||
5 | use Doctrine\ORM\Mapping as ORM; | 5 | use Doctrine\ORM\Mapping as ORM; |
6 | use FOS\OAuthServerBundle\Entity\Client as BaseClient; | 6 | use FOS\OAuthServerBundle\Entity\Client as BaseClient; |
7 | use Wallabag\UserBundle\Entity\User; | ||
7 | 8 | ||
8 | /** | 9 | /** |
9 | * @ORM\Table("oauth2_clients") | 10 | * @ORM\Table("oauth2_clients") |
@@ -35,9 +36,15 @@ class Client extends BaseClient | |||
35 | */ | 36 | */ |
36 | protected $accessTokens; | 37 | protected $accessTokens; |
37 | 38 | ||
38 | public function __construct() | 39 | /** |
40 | * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="clients") | ||
41 | */ | ||
42 | private $user; | ||
43 | |||
44 | public function __construct(User $user) | ||
39 | { | 45 | { |
40 | parent::__construct(); | 46 | parent::__construct(); |
47 | $this->user = $user; | ||
41 | } | 48 | } |
42 | 49 | ||
43 | /** | 50 | /** |
@@ -63,4 +70,12 @@ class Client extends BaseClient | |||
63 | 70 | ||
64 | return $this; | 71 | return $this; |
65 | } | 72 | } |
73 | |||
74 | /** | ||
75 | * @return User | ||
76 | */ | ||
77 | public function getUser() | ||
78 | { | ||
79 | return $this->user; | ||
80 | } | ||
66 | } | 81 | } |