aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/AnnotationBundle/Entity/Annotation.php15
-rw-r--r--src/Wallabag/ApiBundle/Controller/DeveloperController.php2
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php16
-rw-r--r--src/Wallabag/CoreBundle/Entity/SiteCredential.php13
-rw-r--r--src/Wallabag/CoreBundle/Helper/EntityTimestampsTrait.php24
-rw-r--r--src/Wallabag/UserBundle/Entity/User.php16
-rw-r--r--tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php22
7 files changed, 38 insertions, 70 deletions
diff --git a/src/Wallabag/AnnotationBundle/Entity/Annotation.php b/src/Wallabag/AnnotationBundle/Entity/Annotation.php
index 04d83001..a180d504 100644
--- a/src/Wallabag/AnnotationBundle/Entity/Annotation.php
+++ b/src/Wallabag/AnnotationBundle/Entity/Annotation.php
@@ -10,6 +10,7 @@ use JMS\Serializer\Annotation\SerializedName;
10use JMS\Serializer\Annotation\VirtualProperty; 10use JMS\Serializer\Annotation\VirtualProperty;
11use Symfony\Component\Validator\Constraints as Assert; 11use Symfony\Component\Validator\Constraints as Assert;
12use Wallabag\CoreBundle\Entity\Entry; 12use Wallabag\CoreBundle\Entity\Entry;
13use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
13use Wallabag\UserBundle\Entity\User; 14use Wallabag\UserBundle\Entity\User;
14 15
15/** 16/**
@@ -22,6 +23,8 @@ use Wallabag\UserBundle\Entity\User;
22 */ 23 */
23class Annotation 24class Annotation
24{ 25{
26 use EntityTimestampsTrait;
27
25 /** 28 /**
26 * @var int 29 * @var int
27 * 30 *
@@ -134,18 +137,6 @@ class Annotation
134 } 137 }
135 138
136 /** 139 /**
137 * @ORM\PrePersist
138 * @ORM\PreUpdate
139 */
140 public function timestamps()
141 {
142 if (null === $this->createdAt) {
143 $this->createdAt = new \DateTime();
144 }
145 $this->updatedAt = new \DateTime();
146 }
147
148 /**
149 * Get created. 140 * Get created.
150 * 141 *
151 * @return \DateTime 142 * @return \DateTime
diff --git a/src/Wallabag/ApiBundle/Controller/DeveloperController.php b/src/Wallabag/ApiBundle/Controller/DeveloperController.php
index c8a1c635..c7178017 100644
--- a/src/Wallabag/ApiBundle/Controller/DeveloperController.php
+++ b/src/Wallabag/ApiBundle/Controller/DeveloperController.php
@@ -43,7 +43,7 @@ class DeveloperController extends Controller
43 $clientForm->handleRequest($request); 43 $clientForm->handleRequest($request);
44 44
45 if ($clientForm->isSubmitted() && $clientForm->isValid()) { 45 if ($clientForm->isSubmitted() && $clientForm->isValid()) {
46 $client->setAllowedGrantTypes(['client_credentials', 'token', 'authorization_code', 'password', 'refresh_token']); 46 $client->setAllowedGrantTypes(['token', 'authorization_code', 'password', 'refresh_token']);
47 $em->persist($client); 47 $em->persist($client);
48 $em->flush(); 48 $em->flush();
49 49
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index cba72d31..61d01bdc 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -12,6 +12,7 @@ use JMS\Serializer\Annotation\VirtualProperty;
12use JMS\Serializer\Annotation\XmlRoot; 12use JMS\Serializer\Annotation\XmlRoot;
13use Symfony\Component\Validator\Constraints as Assert; 13use Symfony\Component\Validator\Constraints as Assert;
14use Wallabag\AnnotationBundle\Entity\Annotation; 14use Wallabag\AnnotationBundle\Entity\Annotation;
15use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
15use Wallabag\UserBundle\Entity\User; 16use Wallabag\UserBundle\Entity\User;
16 17
17/** 18/**
@@ -32,6 +33,8 @@ use Wallabag\UserBundle\Entity\User;
32 */ 33 */
33class Entry 34class Entry
34{ 35{
36 use EntityTimestampsTrait;
37
35 /** @Serializer\XmlAttribute */ 38 /** @Serializer\XmlAttribute */
36 /** 39 /**
37 * @var int 40 * @var int
@@ -473,19 +476,6 @@ class Entry
473 } 476 }
474 477
475 /** 478 /**
476 * @ORM\PrePersist
477 * @ORM\PreUpdate
478 */
479 public function timestamps()
480 {
481 if (null === $this->createdAt) {
482 $this->createdAt = new \DateTime();
483 }
484
485 $this->updatedAt = new \DateTime();
486 }
487
488 /**
489 * @return ArrayCollection<Annotation> 479 * @return ArrayCollection<Annotation>
490 */ 480 */
491 public function getAnnotations() 481 public function getAnnotations()
diff --git a/src/Wallabag/CoreBundle/Entity/SiteCredential.php b/src/Wallabag/CoreBundle/Entity/SiteCredential.php
index 4d6557c5..ac714359 100644
--- a/src/Wallabag/CoreBundle/Entity/SiteCredential.php
+++ b/src/Wallabag/CoreBundle/Entity/SiteCredential.php
@@ -4,6 +4,7 @@ namespace Wallabag\CoreBundle\Entity;
4 4
5use Doctrine\ORM\Mapping as ORM; 5use Doctrine\ORM\Mapping as ORM;
6use Symfony\Component\Validator\Constraints as Assert; 6use Symfony\Component\Validator\Constraints as Assert;
7use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
7use Wallabag\UserBundle\Entity\User; 8use Wallabag\UserBundle\Entity\User;
8 9
9/** 10/**
@@ -15,6 +16,8 @@ use Wallabag\UserBundle\Entity\User;
15 */ 16 */
16class SiteCredential 17class SiteCredential
17{ 18{
19 use EntityTimestampsTrait;
20
18 /** 21 /**
19 * @var int 22 * @var int
20 * 23 *
@@ -182,14 +185,4 @@ class SiteCredential
182 { 185 {
183 return $this->user; 186 return $this->user;
184 } 187 }
185
186 /**
187 * @ORM\PrePersist
188 */
189 public function timestamps()
190 {
191 if (null === $this->createdAt) {
192 $this->createdAt = new \DateTime();
193 }
194 }
195} 188}
diff --git a/src/Wallabag/CoreBundle/Helper/EntityTimestampsTrait.php b/src/Wallabag/CoreBundle/Helper/EntityTimestampsTrait.php
new file mode 100644
index 00000000..1b1ff54a
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Helper/EntityTimestampsTrait.php
@@ -0,0 +1,24 @@
1<?php
2
3namespace Wallabag\CoreBundle\Helper;
4
5use Doctrine\ORM\Mapping as ORM;
6
7/**
8 * Trait to handle created & updated date of an Entity.
9 */
10trait EntityTimestampsTrait
11{
12 /**
13 * @ORM\PrePersist
14 * @ORM\PreUpdate
15 */
16 public function timestamps()
17 {
18 if (null === $this->createdAt) {
19 $this->createdAt = new \DateTime();
20 }
21
22 $this->updatedAt = new \DateTime();
23 }
24}
diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php
index 53c327f9..48446e3c 100644
--- a/src/Wallabag/UserBundle/Entity/User.php
+++ b/src/Wallabag/UserBundle/Entity/User.php
@@ -15,6 +15,7 @@ use Symfony\Component\Security\Core\User\UserInterface;
15use Wallabag\ApiBundle\Entity\Client; 15use Wallabag\ApiBundle\Entity\Client;
16use Wallabag\CoreBundle\Entity\Config; 16use Wallabag\CoreBundle\Entity\Config;
17use Wallabag\CoreBundle\Entity\Entry; 17use Wallabag\CoreBundle\Entity\Entry;
18use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
18 19
19/** 20/**
20 * User. 21 * User.
@@ -29,6 +30,8 @@ use Wallabag\CoreBundle\Entity\Entry;
29 */ 30 */
30class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterface 31class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterface
31{ 32{
33 use EntityTimestampsTrait;
34
32 /** @Serializer\XmlAttribute */ 35 /** @Serializer\XmlAttribute */
33 /** 36 /**
34 * @var int 37 * @var int
@@ -139,19 +142,6 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
139 } 142 }
140 143
141 /** 144 /**
142 * @ORM\PrePersist
143 * @ORM\PreUpdate
144 */
145 public function timestamps()
146 {
147 if (null === $this->createdAt) {
148 $this->createdAt = new \DateTime();
149 }
150
151 $this->updatedAt = new \DateTime();
152 }
153
154 /**
155 * Set name. 145 * Set name.
156 * 146 *
157 * @param string $name 147 * @param string $name
diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php
index 2caeccf5..e9e5ee3b 100644
--- a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php
@@ -34,7 +34,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase
34 $this->assertContains('My app', $alert[0]); 34 $this->assertContains('My app', $alert[0]);
35 } 35 }
36 36
37 public function testCreateTokenFromPasswords() 37 public function testCreateToken()
38 { 38 {
39 $client = $this->getClient(); 39 $client = $this->getClient();
40 $apiClient = $this->createApiClientForUser('admin'); 40 $apiClient = $this->createApiClientForUser('admin');
@@ -56,26 +56,6 @@ class DeveloperControllerTest extends WallabagCoreTestCase
56 $this->assertArrayHasKey('refresh_token', $data); 56 $this->assertArrayHasKey('refresh_token', $data);
57 } 57 }
58 58
59 public function testCreateTokenFromClientCredentialsOnly()
60 {
61 $client = $this->getClient();
62 $apiClient = $this->createApiClientForUser('admin', ['client_credentials']);
63
64 $client->request('POST', '/oauth/v2/token', [
65 'grant_type' => 'client_credentials',
66 'client_id' => $apiClient->getPublicId(),
67 'client_secret' => $apiClient->getSecret(),
68 ]);
69
70 $this->assertSame(200, $client->getResponse()->getStatusCode());
71
72 $data = json_decode($client->getResponse()->getContent(), true);
73 $this->assertArrayHasKey('access_token', $data);
74 $this->assertArrayHasKey('expires_in', $data);
75 $this->assertArrayHasKey('token_type', $data);
76 // Client Credentials created-clients have no refresh tokens
77 }
78
79 public function testListingClient() 59 public function testListingClient()
80 { 60 {
81 $this->logInAs('admin'); 61 $this->logInAs('admin');