aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/CoreBundle/Controller/DeveloperController.php33
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/client_parameters.html.twig3
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/howto_app.html.twig2
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/index.html.twig41
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/client_parameters.html.twig3
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/howto_app.html.twig2
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/index.html.twig41
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/DeveloperControllerTest.php53
8 files changed, 162 insertions, 16 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/DeveloperController.php b/src/Wallabag/CoreBundle/Controller/DeveloperController.php
index 30cc8beb..e7720355 100644
--- a/src/Wallabag/CoreBundle/Controller/DeveloperController.php
+++ b/src/Wallabag/CoreBundle/Controller/DeveloperController.php
@@ -17,13 +17,17 @@ class DeveloperController extends Controller
17 */ 17 */
18 public function indexAction() 18 public function indexAction()
19 { 19 {
20 return $this->render('WallabagCoreBundle:Developer:index.html.twig'); 20 $clients = $this->getDoctrine()->getRepository('WallabagApiBundle:Client')->findAll();
21
22 return $this->render('WallabagCoreBundle:Developer:index.html.twig', array(
23 'clients' => $clients,
24 ));
21 } 25 }
22 26
23 /** 27 /**
24 * @param Request $request 28 * @param Request $request
25 * 29 *
26 * @Route("/developer/client/create", name="create_client") 30 * @Route("/developer/client/create", name="developer_create_client")
27 * 31 *
28 * @return \Symfony\Component\HttpFoundation\Response 32 * @return \Symfony\Component\HttpFoundation\Response
29 */ 33 */
@@ -56,7 +60,30 @@ class DeveloperController extends Controller
56 } 60 }
57 61
58 /** 62 /**
59 * @Route("/developer/howto/first-app", name="howto-firstapp") 63 * Remove a client.
64 *
65 * @param Request $request
66 *
67 * @Route("/developer/client/delete/{id}", requirements={"id" = "\d+"}, name="developer_delete_client")
68 *
69 * @return \Symfony\Component\HttpFoundation\RedirectResponse
70 */
71 public function deleteClientAction(Request $request, Client $client)
72 {
73 $em = $this->getDoctrine()->getManager();
74 $em->remove($client);
75 $em->flush();
76
77 $this->get('session')->getFlashBag()->add(
78 'notice',
79 'Client deleted'
80 );
81
82 return $this->redirect($this->generateUrl('developer'));
83 }
84
85 /**
86 * @Route("/developer/howto/first-app", name="developer_howto_firstapp")
60 * 87 *
61 * @return \Symfony\Component\HttpFoundation\Response 88 * @return \Symfony\Component\HttpFoundation\Response
62 */ 89 */
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/client_parameters.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/client_parameters.html.twig
index a2a28d50..c2f7e95c 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/client_parameters.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/client_parameters.html.twig
@@ -8,14 +8,13 @@
8 <div class="card-panel settings"> 8 <div class="card-panel settings">
9 <div class="row"> 9 <div class="row">
10 <p>{% trans %}Here are your client parameters.{% endtrans %}</p> 10 <p>{% trans %}Here are your client parameters.{% endtrans %}</p>
11 <p><strong>{% trans %}Make sure to copy these parameters now. You won’t be able to see them again!{% endtrans %}</strong></p>
12 <ul> 11 <ul>
13 <li>{% trans %}Client ID:{% endtrans %} <strong><pre>{{ client_id }}</pre></strong></li> 12 <li>{% trans %}Client ID:{% endtrans %} <strong><pre>{{ client_id }}</pre></strong></li>
14 <li>{% trans %}Client secret:{% endtrans %} <strong><pre>{{ client_secret }}</pre></strong></li> 13 <li>{% trans %}Client secret:{% endtrans %} <strong><pre>{{ client_secret }}</pre></strong></li>
15 </ul> 14 </ul>
16 15
17 <a href="{{ path('developer') }}" class="waves-effect waves-light grey btn">{% trans %}Back{% endtrans %}</a> 16 <a href="{{ path('developer') }}" class="waves-effect waves-light grey btn">{% trans %}Back{% endtrans %}</a>
18 <a href="{{ path('howto-firstapp') }}" class="btn waves-effect waves-light">{% trans %}Read the howto "Create my first application"{% endtrans %}</a> 17 <a href="{{ path('developer_howto_firstapp') }}" class="btn waves-effect waves-light">{% trans %}Read the howto "Create my first application"{% endtrans %}</a>
19 </div> 18 </div>
20 </div> 19 </div>
21 </div> 20 </div>
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/howto_app.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/howto_app.html.twig
index 88788776..1aece1d9 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/howto_app.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/howto_app.html.twig
@@ -15,7 +15,7 @@
15 <div class="row"> 15 <div class="row">
16 <p>The following commands make use of the <a href="https://github.com/jkbrzt/httpie">HTTPie library</a>. Make sure it is installed on your system before using it.</p> 16 <p>The following commands make use of the <a href="https://github.com/jkbrzt/httpie">HTTPie library</a>. Make sure it is installed on your system before using it.</p>
17 <p>You need a token to communicate between your 3rd application and wallabag API.</p> 17 <p>You need a token to communicate between your 3rd application and wallabag API.</p>
18 <p>To create this token, you need <a href="{{ path('create_client') }}">to create a new client</a>.</p> 18 <p>To create this token, you need <a href="{{ path('developer_create_client') }}">to create a new client</a>.</p>
19 <p>Now, create your token (replace client_id, client_secret, username and password with the good values):</p> 19 <p>Now, create your token (replace client_id, client_secret, username and password with the good values):</p>
20 <p> 20 <p>
21 <pre><code class="language-bash">http POST http://v2.wallabag.org/oauth/v2/token \ 21 <pre><code class="language-bash">http POST http://v2.wallabag.org/oauth/v2/token \
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/index.html.twig
index 87dd4a5f..604bfec9 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/index.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/index.html.twig
@@ -13,15 +13,52 @@
13 <h4>{% trans %}Documentation{% endtrans %}</h4> 13 <h4>{% trans %}Documentation{% endtrans %}</h4>
14 14
15 <ul> 15 <ul>
16 <li><a href="{{ path('howto-firstapp') }}">{% trans %}How to create my first application{% endtrans %}</a></li> 16 <li><a href="{{ path('developer_howto_firstapp') }}">{% trans %}How to create my first application{% endtrans %}</a></li>
17 <li><a href="{{ path('nelmio_api_doc_index') }}">{% trans %}View full API documentation{% endtrans %}</a></li> 17 <li><a href="{{ path('nelmio_api_doc_index') }}">{% trans %}View full API documentation{% endtrans %}</a></li>
18 </ul> 18 </ul>
19 19
20 <h4>{% trans %}Clients{% endtrans %}</h4> 20 <h4>{% trans %}Clients{% endtrans %}</h4>
21 <ul> 21 <ul>
22 <li><a href="{{ path('create_client') }}">{% trans %}Create a new client{% endtrans %}</a></li> 22 <li><a href="{{ path('developer_create_client') }}">{% trans %}Create a new client{% endtrans %}</a></li>
23 </ul> 23 </ul>
24 24
25 <h4>{% trans %}Existing clients{% endtrans %}</h4>
26 {% if clients %}
27 <ul class="collapsible" data-collapsible="expandable">
28 {% for client in clients %}
29 <li>
30 <div class="collapsible-header">#{{ client.id }}</div>
31 <div class="collapsible-body">
32 <table class="striped">
33 <tr>
34 <td>{% trans %}Client ID:{% endtrans %}</td>
35 <td><strong><code>{{ client.id }}_{{ client.randomId }}</code></strong></td>
36 </tr>
37 <tr>
38 <td>{% trans %}Client secret:{% endtrans %}</td>
39 <td><strong><code>{{ client.secret }}</code></strong></td>
40 </tr>
41 <tr>
42 <td>{% trans %}Redirect URIs:{% endtrans %}</td>
43 <td><strong><code>{{ client.redirectUris|json_encode() }}</code></strong></td>
44 </tr>
45 <tr>
46 <td>{% trans %}Grant type allowed:{% endtrans %}</td>
47 <td><strong><code>{{ client.allowedGrantTypes|json_encode() }}</code></strong></td>
48 </tr>
49 </table>
50 <p>
51 {% trans %}You have the ability to remove this client. This action is IRREVERSIBLE !{% endtrans %}<br/>
52 {% trans %}If you remove it, every app configured with that client won't be able to auth on your wallabag.{% endtrans %}<br/>
53 <a class="waves-effect waves-light red btn" href="{{ path('developer_delete_client', {'id': client.id}) }}">{% trans %}Remove this client{% endtrans %}</a>
54 </p>
55 </div>
56 </li>
57 {% endfor %}
58 </ul>
59 {% else %}
60 {% trans %}No client yet.{% endtrans %}
61 {% endif %}
25 </div> 62 </div>
26 63
27 </div> 64 </div>
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/client_parameters.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/client_parameters.html.twig
index a2a28d50..c2f7e95c 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/client_parameters.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/client_parameters.html.twig
@@ -8,14 +8,13 @@
8 <div class="card-panel settings"> 8 <div class="card-panel settings">
9 <div class="row"> 9 <div class="row">
10 <p>{% trans %}Here are your client parameters.{% endtrans %}</p> 10 <p>{% trans %}Here are your client parameters.{% endtrans %}</p>
11 <p><strong>{% trans %}Make sure to copy these parameters now. You won’t be able to see them again!{% endtrans %}</strong></p>
12 <ul> 11 <ul>
13 <li>{% trans %}Client ID:{% endtrans %} <strong><pre>{{ client_id }}</pre></strong></li> 12 <li>{% trans %}Client ID:{% endtrans %} <strong><pre>{{ client_id }}</pre></strong></li>
14 <li>{% trans %}Client secret:{% endtrans %} <strong><pre>{{ client_secret }}</pre></strong></li> 13 <li>{% trans %}Client secret:{% endtrans %} <strong><pre>{{ client_secret }}</pre></strong></li>
15 </ul> 14 </ul>
16 15
17 <a href="{{ path('developer') }}" class="waves-effect waves-light grey btn">{% trans %}Back{% endtrans %}</a> 16 <a href="{{ path('developer') }}" class="waves-effect waves-light grey btn">{% trans %}Back{% endtrans %}</a>
18 <a href="{{ path('howto-firstapp') }}" class="btn waves-effect waves-light">{% trans %}Read the howto "Create my first application"{% endtrans %}</a> 17 <a href="{{ path('developer_howto_firstapp') }}" class="btn waves-effect waves-light">{% trans %}Read the howto "Create my first application"{% endtrans %}</a>
19 </div> 18 </div>
20 </div> 19 </div>
21 </div> 20 </div>
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/howto_app.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/howto_app.html.twig
index 88788776..1aece1d9 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/howto_app.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/howto_app.html.twig
@@ -15,7 +15,7 @@
15 <div class="row"> 15 <div class="row">
16 <p>The following commands make use of the <a href="https://github.com/jkbrzt/httpie">HTTPie library</a>. Make sure it is installed on your system before using it.</p> 16 <p>The following commands make use of the <a href="https://github.com/jkbrzt/httpie">HTTPie library</a>. Make sure it is installed on your system before using it.</p>
17 <p>You need a token to communicate between your 3rd application and wallabag API.</p> 17 <p>You need a token to communicate between your 3rd application and wallabag API.</p>
18 <p>To create this token, you need <a href="{{ path('create_client') }}">to create a new client</a>.</p> 18 <p>To create this token, you need <a href="{{ path('developer_create_client') }}">to create a new client</a>.</p>
19 <p>Now, create your token (replace client_id, client_secret, username and password with the good values):</p> 19 <p>Now, create your token (replace client_id, client_secret, username and password with the good values):</p>
20 <p> 20 <p>
21 <pre><code class="language-bash">http POST http://v2.wallabag.org/oauth/v2/token \ 21 <pre><code class="language-bash">http POST http://v2.wallabag.org/oauth/v2/token \
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/index.html.twig
index 87dd4a5f..604bfec9 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/index.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/index.html.twig
@@ -13,15 +13,52 @@
13 <h4>{% trans %}Documentation{% endtrans %}</h4> 13 <h4>{% trans %}Documentation{% endtrans %}</h4>
14 14
15 <ul> 15 <ul>
16 <li><a href="{{ path('howto-firstapp') }}">{% trans %}How to create my first application{% endtrans %}</a></li> 16 <li><a href="{{ path('developer_howto_firstapp') }}">{% trans %}How to create my first application{% endtrans %}</a></li>
17 <li><a href="{{ path('nelmio_api_doc_index') }}">{% trans %}View full API documentation{% endtrans %}</a></li> 17 <li><a href="{{ path('nelmio_api_doc_index') }}">{% trans %}View full API documentation{% endtrans %}</a></li>
18 </ul> 18 </ul>
19 19
20 <h4>{% trans %}Clients{% endtrans %}</h4> 20 <h4>{% trans %}Clients{% endtrans %}</h4>
21 <ul> 21 <ul>
22 <li><a href="{{ path('create_client') }}">{% trans %}Create a new client{% endtrans %}</a></li> 22 <li><a href="{{ path('developer_create_client') }}">{% trans %}Create a new client{% endtrans %}</a></li>
23 </ul> 23 </ul>
24 24
25 <h4>{% trans %}Existing clients{% endtrans %}</h4>
26 {% if clients %}
27 <ul class="collapsible" data-collapsible="expandable">
28 {% for client in clients %}
29 <li>
30 <div class="collapsible-header">#{{ client.id }}</div>
31 <div class="collapsible-body">
32 <table class="striped">
33 <tr>
34 <td>{% trans %}Client ID:{% endtrans %}</td>
35 <td><strong><code>{{ client.id }}_{{ client.randomId }}</code></strong></td>
36 </tr>
37 <tr>
38 <td>{% trans %}Client secret:{% endtrans %}</td>
39 <td><strong><code>{{ client.secret }}</code></strong></td>
40 </tr>
41 <tr>
42 <td>{% trans %}Redirect URIs:{% endtrans %}</td>
43 <td><strong><code>{{ client.redirectUris|json_encode() }}</code></strong></td>
44 </tr>
45 <tr>
46 <td>{% trans %}Grant type allowed:{% endtrans %}</td>
47 <td><strong><code>{{ client.allowedGrantTypes|json_encode() }}</code></strong></td>
48 </tr>
49 </table>
50 <p>
51 {% trans %}You have the ability to remove this client. This action is IRREVERSIBLE !{% endtrans %}<br/>
52 {% trans %}If you remove it, every app configured with that client won't be able to auth on your wallabag.{% endtrans %}<br/>
53 <a class="waves-effect waves-light red btn" href="{{ path('developer_delete_client', {'id': client.id}) }}">{% trans %}Remove this client{% endtrans %}</a>
54 </p>
55 </div>
56 </li>
57 {% endfor %}
58 </ul>
59 {% else %}
60 {% trans %}No client yet.{% endtrans %}
61 {% endif %}
25 </div> 62 </div>
26 63
27 </div> 64 </div>
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/DeveloperControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/DeveloperControllerTest.php
index 204796ca..fc220b85 100644
--- a/src/Wallabag/CoreBundle/Tests/Controller/DeveloperControllerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Controller/DeveloperControllerTest.php
@@ -6,19 +6,66 @@ use Wallabag\CoreBundle\Tests\WallabagCoreTestCase;
6 6
7class DeveloperControllerTest extends WallabagCoreTestCase 7class DeveloperControllerTest extends WallabagCoreTestCase
8{ 8{
9 public function testNewClient() 9 public function testCreateClient()
10 { 10 {
11 $this->logInAs('admin'); 11 $this->logInAs('admin');
12 $client = $this->getClient(); 12 $client = $this->getClient();
13 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
14 $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
13 15
14 $crawler = $client->request('GET', '/developer/client/create'); 16 $crawler = $client->request('GET', '/developer/client/create');
15 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 17 $this->assertEquals(200, $client->getResponse()->getStatusCode());
16 18
17 $form = $crawler->filter('button[type=submit]')->form(); 19 $form = $crawler->filter('button[type=submit]')->form();
18 20
19 $crawler = $client->submit($form); 21 $client->submit($form);
20 22
21 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 23 $this->assertEquals(200, $client->getResponse()->getStatusCode());
22 $this->assertContains('Make sure to copy these parameters now.', $client->getResponse()->getContent()); 24
25 $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
26 $this->assertGreaterThan(count($nbClients), count($newNbClients));
27 }
28
29 public function testListingClient()
30 {
31 $this->logInAs('admin');
32 $client = $this->getClient();
33 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
34 $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
35
36 $crawler = $client->request('GET', '/developer');
37 $this->assertEquals(200, $client->getResponse()->getStatusCode());
38 $this->assertEquals(count($nbClients), $crawler->filter('ul[class=collapsible] li')->count());
39 }
40
41 public function testDeveloperHowto()
42 {
43 $this->logInAs('admin');
44 $client = $this->getClient();
45
46 $crawler = $client->request('GET', '/developer/howto/first-app');
47 $this->assertEquals(200, $client->getResponse()->getStatusCode());
48 }
49
50 public function testRemoveClient()
51 {
52 $this->logInAs('admin');
53 $client = $this->getClient();
54 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
55 $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
56
57 $crawler = $client->request('GET', '/developer');
58
59 $link = $crawler
60 ->filter('div[class=collapsible-body] p a')
61 ->eq(0)
62 ->link()
63 ;
64
65 $client->click($link);
66 $this->assertEquals(302, $client->getResponse()->getStatusCode());
67
68 $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
69 $this->assertGreaterThan(count($newNbClients), count($nbClients));
23 } 70 }
24} 71}