From 9bf15f02695823652a0e783c915b039836f51626 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 5 Mar 2016 21:44:39 +0100 Subject: [PATCH] Add listing clients Rename route to be more consistive (ie: prefixed with developer_) --- .../Controller/DeveloperController.php | 33 ++++++++++-- .../Developer/client_parameters.html.twig | 3 +- .../baggy/Developer/howto_app.html.twig | 2 +- .../themes/baggy/Developer/index.html.twig | 41 +++++++++++++- .../Developer/client_parameters.html.twig | 3 +- .../material/Developer/howto_app.html.twig | 2 +- .../themes/material/Developer/index.html.twig | 41 +++++++++++++- .../Controller/DeveloperControllerTest.php | 53 +++++++++++++++++-- 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 */ 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 */ 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 @@

{% trans %}Here are your client parameters.{% endtrans %}

-

{% trans %}Make sure to copy these parameters now. You won’t be able to see them again!{% endtrans %}

  • {% trans %}Client ID:{% endtrans %}
    {{ client_id }}
  • {% trans %}Client secret:{% endtrans %}
    {{ client_secret }}
{% trans %}Back{% endtrans %} - {% trans %}Read the howto "Create my first application"{% endtrans %} + {% trans %}Read the howto "Create my first application"{% endtrans %}
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 @@

The following commands make use of the HTTPie library. Make sure it is installed on your system before using it.

You need a token to communicate between your 3rd application and wallabag API.

-

To create this token, you need to create a new client.

+

To create this token, you need to create a new client.

Now, create your token (replace client_id, client_secret, username and password with the good values):

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 @@
                 

{% trans %}Documentation{% endtrans %}

{% trans %}Clients{% endtrans %}

+

{% trans %}Existing clients{% endtrans %}

+ {% if clients %} +
    + {% for client in clients %} +
  • +
    #{{ client.id }}
    +
    + + + + + + + + + + + + + + + + + +
    {% trans %}Client ID:{% endtrans %}{{ client.id }}_{{ client.randomId }}
    {% trans %}Client secret:{% endtrans %}{{ client.secret }}
    {% trans %}Redirect URIs:{% endtrans %}{{ client.redirectUris|json_encode() }}
    {% trans %}Grant type allowed:{% endtrans %}{{ client.allowedGrantTypes|json_encode() }}
    +

    + {% trans %}You have the ability to remove this client. This action is IRREVERSIBLE !{% endtrans %}
    + {% trans %}If you remove it, every app configured with that client won't be able to auth on your wallabag.{% endtrans %}
    + {% trans %}Remove this client{% endtrans %} +

    +
    +
  • + {% endfor %} +
+ {% else %} + {% trans %}No client yet.{% endtrans %} + {% endif %}
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 @@

{% trans %}Here are your client parameters.{% endtrans %}

-

{% trans %}Make sure to copy these parameters now. You won’t be able to see them again!{% endtrans %}

  • {% trans %}Client ID:{% endtrans %}
    {{ client_id }}
  • {% trans %}Client secret:{% endtrans %}
    {{ client_secret }}
{% trans %}Back{% endtrans %} - {% trans %}Read the howto "Create my first application"{% endtrans %} + {% trans %}Read the howto "Create my first application"{% endtrans %}
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 @@

The following commands make use of the HTTPie library. Make sure it is installed on your system before using it.

You need a token to communicate between your 3rd application and wallabag API.

-

To create this token, you need to create a new client.

+

To create this token, you need to create a new client.

Now, create your token (replace client_id, client_secret, username and password with the good values):

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 @@
                 

{% trans %}Documentation{% endtrans %}

{% trans %}Clients{% endtrans %}

+

{% trans %}Existing clients{% endtrans %}

+ {% if clients %} +
    + {% for client in clients %} +
  • +
    #{{ client.id }}
    +
    + + + + + + + + + + + + + + + + + +
    {% trans %}Client ID:{% endtrans %}{{ client.id }}_{{ client.randomId }}
    {% trans %}Client secret:{% endtrans %}{{ client.secret }}
    {% trans %}Redirect URIs:{% endtrans %}{{ client.redirectUris|json_encode() }}
    {% trans %}Grant type allowed:{% endtrans %}{{ client.allowedGrantTypes|json_encode() }}
    +

    + {% trans %}You have the ability to remove this client. This action is IRREVERSIBLE !{% endtrans %}
    + {% trans %}If you remove it, every app configured with that client won't be able to auth on your wallabag.{% endtrans %}
    + {% trans %}Remove this client{% endtrans %} +

    +
    +
  • + {% endfor %} +
+ {% else %} + {% trans %}No client yet.{% endtrans %} + {% endif %}
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; 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)); } } -- 2.41.0