]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Add listing clients
authorJeremy Benoist <jeremy.benoist@gmail.com>
Sat, 5 Mar 2016 20:44:39 +0000 (21:44 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Sat, 5 Mar 2016 20:44:39 +0000 (21:44 +0100)
Rename route to be more consistive (ie: prefixed with developer_)

src/Wallabag/CoreBundle/Controller/DeveloperController.php
src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/client_parameters.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/howto_app.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/index.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/client_parameters.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/howto_app.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/index.html.twig
src/Wallabag/CoreBundle/Tests/Controller/DeveloperControllerTest.php

index 30cc8bebd8e0c3dea8243327f4e79b11e218fdfa..e7720355661ad10bcf365e69bfe78c5ef337bcb8 100644 (file)
@@ -17,13 +17,17 @@ class DeveloperController extends Controller
      */
     public function indexAction()
     {
-        return $this->render('WallabagCoreBundle:Developer:index.html.twig');
+        $clients = $this->getDoctrine()->getRepository('WallabagApiBundle:Client')->findAll();
+
+        return $this->render('WallabagCoreBundle:Developer:index.html.twig', array(
+            'clients' => $clients,
+        ));
     }
 
     /**
      * @param Request $request
      *
-     * @Route("/developer/client/create", name="create_client")
+     * @Route("/developer/client/create", name="developer_create_client")
      *
      * @return \Symfony\Component\HttpFoundation\Response
      */
@@ -56,7 +60,30 @@ class DeveloperController extends Controller
     }
 
     /**
-     * @Route("/developer/howto/first-app", name="howto-firstapp")
+     * Remove a client.
+     *
+     * @param Request $request
+     *
+     * @Route("/developer/client/delete/{id}", requirements={"id" = "\d+"}, name="developer_delete_client")
+     *
+     * @return \Symfony\Component\HttpFoundation\RedirectResponse
+     */
+    public function deleteClientAction(Request $request, Client $client)
+    {
+        $em = $this->getDoctrine()->getManager();
+        $em->remove($client);
+        $em->flush();
+
+        $this->get('session')->getFlashBag()->add(
+            'notice',
+            'Client deleted'
+        );
+
+        return $this->redirect($this->generateUrl('developer'));
+    }
+
+    /**
+     * @Route("/developer/howto/first-app", name="developer_howto_firstapp")
      *
      * @return \Symfony\Component\HttpFoundation\Response
      */
index a2a28d508bc5f4b01e696d6114f49196936d5484..c2f7e95c49f0a32094481e9a7150fc15134aa58c 100644 (file)
@@ -8,14 +8,13 @@
         <div class="card-panel settings">
             <div class="row">
                 <p>{% trans %}Here are your client parameters.{% endtrans %}</p>
-                <p><strong>{% trans %}Make sure to copy these parameters now. You won’t be able to see them again!{% endtrans %}</strong></p>
                 <ul>
                     <li>{% trans %}Client ID:{% endtrans %} <strong><pre>{{ client_id }}</pre></strong></li>
                     <li>{% trans %}Client secret:{% endtrans %} <strong><pre>{{ client_secret }}</pre></strong></li>
                 </ul>
 
                 <a href="{{ path('developer') }}" class="waves-effect waves-light grey btn">{% trans %}Back{% endtrans %}</a>
-                <a href="{{ path('howto-firstapp') }}" class="btn waves-effect waves-light">{% trans %}Read the howto "Create my first application"{% endtrans %}</a>
+                <a href="{{ path('developer_howto_firstapp') }}" class="btn waves-effect waves-light">{% trans %}Read the howto "Create my first application"{% endtrans %}</a>
             </div>
         </div>
     </div>
index 88788776797d9a034e114d952169e53367d943de..1aece1d91609e3f6abc74dcf072f894250668b65 100644 (file)
@@ -15,7 +15,7 @@
             <div class="row">
                 <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>
                 <p>You need a token to communicate between your 3rd application and wallabag API.</p>
-                <p>To create this token, you need <a href="{{ path('create_client') }}">to create a new client</a>.</p>
+                <p>To create this token, you need <a href="{{ path('developer_create_client') }}">to create a new client</a>.</p>
                 <p>Now, create your token (replace client_id, client_secret, username and password with the good values):</p>
                 <p>
                     <pre><code class="language-bash">http POST http://v2.wallabag.org/oauth/v2/token \
index 87dd4a5fe6f27202c852444ba371b0c152d6d85d..604bfec9c6017fbc0bac88012178314ae25ffd5c 100644 (file)
                 <h4>{% trans %}Documentation{% endtrans %}</h4>
 
                 <ul>
-                    <li><a href="{{ path('howto-firstapp') }}">{% trans %}How to create my first application{% endtrans %}</a></li>
+                    <li><a href="{{ path('developer_howto_firstapp') }}">{% trans %}How to create my first application{% endtrans %}</a></li>
                     <li><a href="{{ path('nelmio_api_doc_index') }}">{% trans %}View full API documentation{% endtrans %}</a></li>
                 </ul>
 
                 <h4>{% trans %}Clients{% endtrans %}</h4>
                 <ul>
-                    <li><a href="{{ path('create_client') }}">{% trans %}Create a new client{% endtrans %}</a></li>
+                    <li><a href="{{ path('developer_create_client') }}">{% trans %}Create a new client{% endtrans %}</a></li>
                 </ul>
 
+                <h4>{% trans %}Existing clients{% endtrans %}</h4>
+                {% if clients %}
+                    <ul class="collapsible" data-collapsible="expandable">
+                        {% for client in clients %}
+                            <li>
+                                <div class="collapsible-header">#{{ client.id }}</div>
+                                <div class="collapsible-body">
+                                    <table class="striped">
+                                        <tr>
+                                            <td>{% trans %}Client ID:{% endtrans %}</td>
+                                            <td><strong><code>{{ client.id }}_{{ client.randomId }}</code></strong></td>
+                                        </tr>
+                                        <tr>
+                                            <td>{% trans %}Client secret:{% endtrans %}</td>
+                                            <td><strong><code>{{ client.secret }}</code></strong></td>
+                                        </tr>
+                                        <tr>
+                                            <td>{% trans %}Redirect URIs:{% endtrans %}</td>
+                                            <td><strong><code>{{ client.redirectUris|json_encode() }}</code></strong></td>
+                                        </tr>
+                                        <tr>
+                                            <td>{% trans %}Grant type allowed:{% endtrans %}</td>
+                                            <td><strong><code>{{ client.allowedGrantTypes|json_encode() }}</code></strong></td>
+                                        </tr>
+                                    </table>
+                                    <p>
+                                        {% trans %}You have the ability to remove this client. This action is IRREVERSIBLE !{% endtrans %}<br/>
+                                        {% trans %}If you remove it, every app configured with that client won't be able to auth on your wallabag.{% endtrans %}<br/>
+                                        <a class="waves-effect waves-light red btn" href="{{ path('developer_delete_client', {'id': client.id}) }}">{% trans %}Remove this client{% endtrans %}</a>
+                                    </p>
+                                </div>
+                            </li>
+                        {% endfor %}
+                    </ul>
+                {% else %}
+                    {% trans %}No client yet.{% endtrans %}
+                {% endif %}
             </div>
 
         </div>
index a2a28d508bc5f4b01e696d6114f49196936d5484..c2f7e95c49f0a32094481e9a7150fc15134aa58c 100644 (file)
@@ -8,14 +8,13 @@
         <div class="card-panel settings">
             <div class="row">
                 <p>{% trans %}Here are your client parameters.{% endtrans %}</p>
-                <p><strong>{% trans %}Make sure to copy these parameters now. You won’t be able to see them again!{% endtrans %}</strong></p>
                 <ul>
                     <li>{% trans %}Client ID:{% endtrans %} <strong><pre>{{ client_id }}</pre></strong></li>
                     <li>{% trans %}Client secret:{% endtrans %} <strong><pre>{{ client_secret }}</pre></strong></li>
                 </ul>
 
                 <a href="{{ path('developer') }}" class="waves-effect waves-light grey btn">{% trans %}Back{% endtrans %}</a>
-                <a href="{{ path('howto-firstapp') }}" class="btn waves-effect waves-light">{% trans %}Read the howto "Create my first application"{% endtrans %}</a>
+                <a href="{{ path('developer_howto_firstapp') }}" class="btn waves-effect waves-light">{% trans %}Read the howto "Create my first application"{% endtrans %}</a>
             </div>
         </div>
     </div>
index 88788776797d9a034e114d952169e53367d943de..1aece1d91609e3f6abc74dcf072f894250668b65 100644 (file)
@@ -15,7 +15,7 @@
             <div class="row">
                 <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>
                 <p>You need a token to communicate between your 3rd application and wallabag API.</p>
-                <p>To create this token, you need <a href="{{ path('create_client') }}">to create a new client</a>.</p>
+                <p>To create this token, you need <a href="{{ path('developer_create_client') }}">to create a new client</a>.</p>
                 <p>Now, create your token (replace client_id, client_secret, username and password with the good values):</p>
                 <p>
                     <pre><code class="language-bash">http POST http://v2.wallabag.org/oauth/v2/token \
index 87dd4a5fe6f27202c852444ba371b0c152d6d85d..604bfec9c6017fbc0bac88012178314ae25ffd5c 100644 (file)
                 <h4>{% trans %}Documentation{% endtrans %}</h4>
 
                 <ul>
-                    <li><a href="{{ path('howto-firstapp') }}">{% trans %}How to create my first application{% endtrans %}</a></li>
+                    <li><a href="{{ path('developer_howto_firstapp') }}">{% trans %}How to create my first application{% endtrans %}</a></li>
                     <li><a href="{{ path('nelmio_api_doc_index') }}">{% trans %}View full API documentation{% endtrans %}</a></li>
                 </ul>
 
                 <h4>{% trans %}Clients{% endtrans %}</h4>
                 <ul>
-                    <li><a href="{{ path('create_client') }}">{% trans %}Create a new client{% endtrans %}</a></li>
+                    <li><a href="{{ path('developer_create_client') }}">{% trans %}Create a new client{% endtrans %}</a></li>
                 </ul>
 
+                <h4>{% trans %}Existing clients{% endtrans %}</h4>
+                {% if clients %}
+                    <ul class="collapsible" data-collapsible="expandable">
+                        {% for client in clients %}
+                            <li>
+                                <div class="collapsible-header">#{{ client.id }}</div>
+                                <div class="collapsible-body">
+                                    <table class="striped">
+                                        <tr>
+                                            <td>{% trans %}Client ID:{% endtrans %}</td>
+                                            <td><strong><code>{{ client.id }}_{{ client.randomId }}</code></strong></td>
+                                        </tr>
+                                        <tr>
+                                            <td>{% trans %}Client secret:{% endtrans %}</td>
+                                            <td><strong><code>{{ client.secret }}</code></strong></td>
+                                        </tr>
+                                        <tr>
+                                            <td>{% trans %}Redirect URIs:{% endtrans %}</td>
+                                            <td><strong><code>{{ client.redirectUris|json_encode() }}</code></strong></td>
+                                        </tr>
+                                        <tr>
+                                            <td>{% trans %}Grant type allowed:{% endtrans %}</td>
+                                            <td><strong><code>{{ client.allowedGrantTypes|json_encode() }}</code></strong></td>
+                                        </tr>
+                                    </table>
+                                    <p>
+                                        {% trans %}You have the ability to remove this client. This action is IRREVERSIBLE !{% endtrans %}<br/>
+                                        {% trans %}If you remove it, every app configured with that client won't be able to auth on your wallabag.{% endtrans %}<br/>
+                                        <a class="waves-effect waves-light red btn" href="{{ path('developer_delete_client', {'id': client.id}) }}">{% trans %}Remove this client{% endtrans %}</a>
+                                    </p>
+                                </div>
+                            </li>
+                        {% endfor %}
+                    </ul>
+                {% else %}
+                    {% trans %}No client yet.{% endtrans %}
+                {% endif %}
             </div>
 
         </div>
index 204796ca0dc741c8c4d3197bf4c87a9b4b4848a0..fc220b850d25d487ca5bd332a8b44645e41249c6 100644 (file)
@@ -6,19 +6,66 @@ use Wallabag\CoreBundle\Tests\WallabagCoreTestCase;
 
 class DeveloperControllerTest extends WallabagCoreTestCase
 {
-    public function testNewClient()
+    public function testCreateClient()
     {
         $this->logInAs('admin');
         $client = $this->getClient();
+        $em = $client->getContainer()->get('doctrine.orm.entity_manager');
+        $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
 
         $crawler = $client->request('GET', '/developer/client/create');
         $this->assertEquals(200, $client->getResponse()->getStatusCode());
 
         $form = $crawler->filter('button[type=submit]')->form();
 
-        $crawler = $client->submit($form);
+        $client->submit($form);
 
         $this->assertEquals(200, $client->getResponse()->getStatusCode());
-        $this->assertContains('Make sure to copy these parameters now.', $client->getResponse()->getContent());
+
+        $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
+        $this->assertGreaterThan(count($nbClients), count($newNbClients));
+    }
+
+    public function testListingClient()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+        $em = $client->getContainer()->get('doctrine.orm.entity_manager');
+        $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
+
+        $crawler = $client->request('GET', '/developer');
+        $this->assertEquals(200, $client->getResponse()->getStatusCode());
+        $this->assertEquals(count($nbClients), $crawler->filter('ul[class=collapsible] li')->count());
+    }
+
+    public function testDeveloperHowto()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $crawler = $client->request('GET', '/developer/howto/first-app');
+        $this->assertEquals(200, $client->getResponse()->getStatusCode());
+    }
+
+    public function testRemoveClient()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+        $em = $client->getContainer()->get('doctrine.orm.entity_manager');
+        $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
+
+        $crawler = $client->request('GET', '/developer');
+
+        $link = $crawler
+            ->filter('div[class=collapsible-body] p a')
+            ->eq(0)
+            ->link()
+        ;
+
+        $client->click($link);
+        $this->assertEquals(302, $client->getResponse()->getStatusCode());
+
+        $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
+        $this->assertGreaterThan(count($newNbClients), count($nbClients));
     }
 }