Added name on client

- 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
This commit is contained in:
Thomas Citharel 2016-05-21 18:09:38 +02:00 committed by Jeremy Benoist
parent db4d63fc1a
commit 9c545fe028
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C
13 changed files with 110 additions and 24 deletions

View file

@ -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;
');
}
}

View 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;
}
}

View 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'));

View 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'])
;

View 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'

View 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é'

View file

@ -12,6 +12,12 @@
{{ 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) }}

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

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

View file

@ -12,6 +12,12 @@
{{ 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) }}

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

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

View 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()