]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Added name on client
authorThomas Citharel <tcit@tcit.fr>
Sat, 21 May 2016 16:09:38 +0000 (18:09 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Mon, 22 Aug 2016 18:18:27 +0000 (20:18 +0200)
- Fix typos in field name
- Added migration for name field in API client table

Manually cherry-picked from PR
https://github.com/wallabag/wallabag/pull/2171

13 files changed:
app/DoctrineMigrations/Version20160812120952.php [new file with mode: 0644]
src/Wallabag/ApiBundle/Entity/Client.php
src/Wallabag/CoreBundle/Controller/DeveloperController.php
src/Wallabag/CoreBundle/Form/Type/ClientType.php
src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/client.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/client_parameters.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/index.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/client.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/client_parameters.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/index.html.twig
tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php

diff --git a/app/DoctrineMigrations/Version20160812120952.php b/app/DoctrineMigrations/Version20160812120952.php
new file mode 100644 (file)
index 0000000..58f070c
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+namespace Application\Migrations;
+
+use Doctrine\DBAL\Migrations\AbstractMigration;
+use Doctrine\DBAL\Schema\Schema;
+
+class Version20160812120952 extends AbstractMigration
+{
+    /**
+     * @param Schema $schema
+     */
+    public function up(Schema $schema)
+    {
+        $this->addSql('ALTER TABLE wallabag_oauth2_clients ADD name CLOB DEFAULT NULL COLLATE BINARY');
+    }
+
+    /**
+     * @param Schema $schema
+     */
+    public function down(Schema $schema)
+    {
+        $this->abortIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');
+        $this->addSql('ALTER TABLE wallabag_oauth2_clients DROP COLUMN name;
+');
+    }
+}
index c04ed0f62f0469f6dbb345a29dbb7aff97c5c62f..3e2f491c012ad94e43609dad08ce4ea6b0a335ed 100644 (file)
@@ -18,8 +18,39 @@ class Client extends BaseClient
      */
     protected $id;
 
+    /**
+     * @var string
+     *
+     * @ORM\Column(name="name", type="text", nullable=true)
+     */
+    protected $name;
+
     public function __construct()
     {
         parent::__construct();
     }
+
+    /**
+     * Get name.
+     *
+     * @return string
+     */
+    public function getName()
+    {
+        return $this->name;
+    }
+
+    /**
+     * Set name.
+     *
+     * @param string $name
+     *
+     * @return Client
+     */
+    public function setName($name)
+    {
+        $this->name = $name;
+
+        return $this;
+    }
 }
index d85ba5ee4a30d82bb6ac8733daf22d7a8fd06bfe..1ea220e52edc164d5321aa0207c30875f30fb181 100644 (file)
@@ -49,12 +49,13 @@ class DeveloperController extends Controller
 
             $this->get('session')->getFlashBag()->add(
                 'notice',
-                'flashes.developer.notice.client_created'
+                $this->get('translator')->trans('flashes.developer.notice.client_created', array('%name%' => $client->getName()))
             );
 
             return $this->render('WallabagCoreBundle:Developer:client_parameters.html.twig', [
                 'client_id' => $client->getPublicId(),
                 'client_secret' => $client->getSecret(),
+                'client_name' => $client->getName(),
             ]);
         }
 
@@ -80,7 +81,7 @@ class DeveloperController extends Controller
 
         $this->get('session')->getFlashBag()->add(
             'notice',
-            'flashes.developer.notice.client_deleted'
+            $this->get('translator')->trans('flashes.developer.notice.client_deleted', array('%name%' => $client->getName()))
         );
 
         return $this->redirect($this->generateUrl('developer'));
index 8b351e6037d449ae1bb9b40e837371e06d94abca..d1fa94e6c314b548b85650a4aaa119ec25f37bbe 100644 (file)
@@ -6,6 +6,7 @@ use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\CallbackTransformer;
 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
 use Symfony\Component\Form\Extension\Core\Type\UrlType;
+use Symfony\Component\Form\Extension\Core\Type\TextType;
 use Symfony\Component\Form\FormBuilderInterface;
 use Symfony\Component\OptionsResolver\OptionsResolver;
 
@@ -14,7 +15,8 @@ class ClientType extends AbstractType
     public function buildForm(FormBuilderInterface $builder, array $options)
     {
         $builder
-            ->add('redirect_uris', UrlType::class, ['required' => true, 'label' => 'developer.client.form.redirect_uris_label'])
+            ->add('name', TextType::class, ['label' => 'developer.client.form.name_label'])
+            ->add('redirect_uris', UrlType::class, ['required' => false, 'label' => 'developer.client.form.redirect_uris_label'])
             ->add('save', SubmitType::class, ['label' => 'developer.client.form.save_label'])
         ;
 
index 826bd47083a64ba1d8196f4bedf87fde7bca789a..2c087421d33adcde57f31fbcbfb3574453ad9f1b 100644 (file)
@@ -352,19 +352,21 @@ developer:
         field_grant_types: 'Grant type allowed'
         no_client: 'No client yet.'
     remove:
-        warn_message_1: 'You have the ability to remove this client. This action is IRREVERSIBLE !'
+        warn_message_1: 'You have the ability to remove the client %name%. This action is IRREVERSIBLE !'
         warn_message_2: "If you remove it, every app configured with that client won't be able to auth on your wallabag."
-        action: 'Remove this client'
+        action: 'Remove the client %name%'
     client:
         page_title: 'Developer > New client'
         page_description: 'You are about to create a new client. Please fill the field below for the redirect URI of your application.'
         form:
-            redirect_uris_label: 'Redirect URIs'
+            name_label: 'Name of the client'
+            redirect_uris_label: 'Redirect URIs (optional)'
             save_label: 'Create a new client'
         action_back: 'Back'
     client_parameter:
         page_title: 'Developer > Client parameters'
         page_description: 'Here are your client parameters.'
+        field_name: 'Client name'
         field_id: 'Client ID'
         field_secret: 'Client secret'
         back: 'Back'
@@ -417,5 +419,5 @@ flashes:
             summary: 'Import summary: %imported% imported, %skipped% already saved.'
     developer:
         notice:
-            client_created: 'New client created.'
-            client_deleted: 'Client deleted'
+            client_created: 'New client %name% created.'
+            client_deleted: 'Client %name% deleted'
index 7c1464e18fbeb82a69f5cbd85e01ca41eeaa09ff..542f61c2081e43be9581ae646816ff21826971ed 100644 (file)
@@ -343,7 +343,7 @@ developer:
     list_methods: "Lister toutes les méthodes de l'API"
     clients:
         title: 'Clients'
-        create_new: 'Créer une nouveau client'
+        create_new: 'Créer un nouveau client'
     existing_clients:
         title: 'Les clients existants'
         field_id: 'ID Client'
@@ -352,19 +352,21 @@ developer:
         field_grant_types: 'Type de privilège accordé'
         no_client: 'Aucun client pour le moment'
     remove:
-        warn_message_1: 'Vous avez la possibilité de supprimer un client. Cette action est IRREVERSIBLE !'
-        warn_message_2: "Si vous supprimez un client, toutes les applications qui l'utilisaient ne fonctionneront plus avec votre compte wallabag."
-        action: 'Supprimer ce client'
+        warn_message_1: 'Vous avez la possibilité de supprimer le client %name%. Cette action est IRREVERSIBLE !'
+        warn_message_2: "Si vous supprimez le client %name%, toutes les applications qui l'utilisaient ne fonctionneront plus avec votre compte wallabag."
+        action: 'Supprimer le client %name%'
     client:
         page_title: 'Développeur > Nouveau client'
         page_description: "Vous allez créer un nouveau client. Merci de remplir l'url de redirection vers votre application."
         form:
-            redirect_uris_label: 'URLs de redirection'
+            name_label: "Nom du client"
+            redirect_uris_label: 'URLs de redirection (optionnel)'
             save_label: 'Créer un nouveau client'
         action_back: 'Retour'
     client_parameter:
         page_title: 'Développeur > Les paramètres de votre client'
         page_description: 'Voilà les paramètres de votre client'
+        field_name: 'Nom du client'
         field_id: 'ID Client'
         field_secret: 'Clé secrète'
         back: 'Retour'
@@ -417,5 +419,5 @@ flashes:
             summary: "Rapport d'import: %imported% importés, %skipped% déjà présent."
     developer:
         notice:
-            client_created: 'Nouveau client créé'
-            client_deleted: 'Client supprimé'
+            client_created: 'Nouveau client %name% créé'
+            client_deleted: 'Client %name% supprimé'
index 78a9dc046175955982304f5b71e289c383d9fec1..8a5da71a9233d581f4f2c583abca6ba719556dfe 100644 (file)
                 {{ form_start(form) }}
                 {{ form_errors(form) }}
 
+                <div class="input-field col s12">
+                    {{ form_label(form.name) }}
+                    {{ form_errors(form.name) }}
+                    {{ form_widget(form.name) }}
+                </div>
+
                 <div class="input-field col s12">
                     {{ form_label(form.redirect_uris) }}
                     {{ form_errors(form.redirect_uris) }}
index b615fa3b6a8e1aa0eb3609a5a1c34c89eb660da3..b498cceb4863ed3e0c8462bdf92616a8bf2011f0 100644 (file)
@@ -9,6 +9,7 @@
             <div class="row">
                 <p>{{ 'developer.client_parameter.page_description'|trans }}</p>
                 <ul>
+                    <li>{{ 'developer.client_parameter.field_name'|trans }}: <strong><pre>{{ client_name }}</pre></strong></li>
                     <li>{{ 'developer.client_parameter.field_id'|trans }}: <strong><pre>{{ client_id }}</pre></strong></li>
                     <li>{{ 'developer.client_parameter.field_secret'|trans }}: <strong><pre>{{ client_secret }}</pre></strong></li>
                 </ul>
index 001c5cbbc7c1768632c887caa583a54bb063e110..3430c0d4fbba61d92534d0d706eb9fb93fed23d9 100644 (file)
@@ -28,7 +28,7 @@
                     <ul class="collapsible" data-collapsible="expandable">
                         {% for client in clients %}
                             <li>
-                                <div class="collapsible-header">#{{ client.id }}</div>
+                                <div class="collapsible-header">{{ client.name }} - #{{ client.id }}</div>
                                 <div class="collapsible-body">
                                     <table class="striped">
                                         <tr>
@@ -49,9 +49,9 @@
                                         </tr>
                                     </table>
                                     <p>
-                                        {{ 'developer.remove.warn_message_1'|trans }}<br/>
-                                        {{ 'developer.remove.warn_message_2'|trans }}<br/>
-                                        <a class="waves-effect waves-light red btn" href="{{ path('developer_delete_client', {'id': client.id}) }}">{{ 'developer.remove.action'|trans }}</a>
+                                        {{ 'developer.remove.warn_message_1'|trans({'%name%': client.name }) }}<br/>
+                                        {{ 'developer.remove.warn_message_2'|trans({'%name%': client.name }) }}<br/>
+                                        <a class="waves-effect waves-light red btn" href="{{ path('developer_delete_client', {'id': client.id}) }}">{{ 'developer.remove.action'|trans({'%name%': client.name }) }}</a>
                                     </p>
                                 </div>
                             </li>
index 78a9dc046175955982304f5b71e289c383d9fec1..8a5da71a9233d581f4f2c583abca6ba719556dfe 100644 (file)
                 {{ form_start(form) }}
                 {{ form_errors(form) }}
 
+                <div class="input-field col s12">
+                    {{ form_label(form.name) }}
+                    {{ form_errors(form.name) }}
+                    {{ form_widget(form.name) }}
+                </div>
+
                 <div class="input-field col s12">
                     {{ form_label(form.redirect_uris) }}
                     {{ form_errors(form.redirect_uris) }}
index b615fa3b6a8e1aa0eb3609a5a1c34c89eb660da3..b498cceb4863ed3e0c8462bdf92616a8bf2011f0 100644 (file)
@@ -9,6 +9,7 @@
             <div class="row">
                 <p>{{ 'developer.client_parameter.page_description'|trans }}</p>
                 <ul>
+                    <li>{{ 'developer.client_parameter.field_name'|trans }}: <strong><pre>{{ client_name }}</pre></strong></li>
                     <li>{{ 'developer.client_parameter.field_id'|trans }}: <strong><pre>{{ client_id }}</pre></strong></li>
                     <li>{{ 'developer.client_parameter.field_secret'|trans }}: <strong><pre>{{ client_secret }}</pre></strong></li>
                 </ul>
index 001c5cbbc7c1768632c887caa583a54bb063e110..3430c0d4fbba61d92534d0d706eb9fb93fed23d9 100644 (file)
@@ -28,7 +28,7 @@
                     <ul class="collapsible" data-collapsible="expandable">
                         {% for client in clients %}
                             <li>
-                                <div class="collapsible-header">#{{ client.id }}</div>
+                                <div class="collapsible-header">{{ client.name }} - #{{ client.id }}</div>
                                 <div class="collapsible-body">
                                     <table class="striped">
                                         <tr>
@@ -49,9 +49,9 @@
                                         </tr>
                                     </table>
                                     <p>
-                                        {{ 'developer.remove.warn_message_1'|trans }}<br/>
-                                        {{ 'developer.remove.warn_message_2'|trans }}<br/>
-                                        <a class="waves-effect waves-light red btn" href="{{ path('developer_delete_client', {'id': client.id}) }}">{{ 'developer.remove.action'|trans }}</a>
+                                        {{ 'developer.remove.warn_message_1'|trans({'%name%': client.name }) }}<br/>
+                                        {{ 'developer.remove.warn_message_2'|trans({'%name%': client.name }) }}<br/>
+                                        <a class="waves-effect waves-light red btn" href="{{ path('developer_delete_client', {'id': client.id}) }}">{{ 'developer.remove.action'|trans({'%name%': client.name }) }}</a>
                                     </p>
                                 </div>
                             </li>
index 79452ace4a6078d10bd11bf95f99d17c7020559c..97ed0d58fa01ce99abfd65bf2f0163344e582a59 100644 (file)
@@ -18,12 +18,19 @@ class DeveloperControllerTest extends WallabagCoreTestCase
 
         $form = $crawler->filter('button[type=submit]')->form();
 
-        $client->submit($form);
+        $data = [
+            'client[name]' => 'My app',
+        ];
+
+        $crawler = $client->submit($form, $data);
 
         $this->assertEquals(200, $client->getResponse()->getStatusCode());
 
         $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
         $this->assertGreaterThan(count($nbClients), count($newNbClients));
+
+        $this->assertGreaterThan(1, $alert = $crawler->filter('.settings ul li strong')->extract(['_text']));
+        $this->assertContains('My app', $alert[0]);
     }
 
     public function testListingClient()