diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-05-01 22:13:35 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-06-20 16:03:14 +0200 |
commit | b8427f22f06cab58383ec3080f09715c712c65ef (patch) | |
tree | 0f71278c3296774f86cba8cf4381f9aa4f9b3086 | |
parent | 5a9bc00726ddaf7c8798d4932d0a8b7a38422670 (diff) | |
download | wallabag-b8427f22f06cab58383ec3080f09715c712c65ef.tar.gz wallabag-b8427f22f06cab58383ec3080f09715c712c65ef.tar.zst wallabag-b8427f22f06cab58383ec3080f09715c712c65ef.zip |
Add menu access to site credentials CRUD
22 files changed, 258 insertions, 14 deletions
diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSiteCredentialData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSiteCredentialData.php new file mode 100644 index 00000000..866f55a4 --- /dev/null +++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSiteCredentialData.php | |||
@@ -0,0 +1,34 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\DataFixtures\ORM; | ||
4 | |||
5 | use Doctrine\Common\DataFixtures\AbstractFixture; | ||
6 | use Doctrine\Common\DataFixtures\OrderedFixtureInterface; | ||
7 | use Doctrine\Common\Persistence\ObjectManager; | ||
8 | use Wallabag\CoreBundle\Entity\SiteCredential; | ||
9 | |||
10 | class LoadSiteCredentialData extends AbstractFixture implements OrderedFixtureInterface | ||
11 | { | ||
12 | /** | ||
13 | * {@inheritdoc} | ||
14 | */ | ||
15 | public function load(ObjectManager $manager) | ||
16 | { | ||
17 | $credential = new SiteCredential($this->getReference('admin-user')); | ||
18 | $credential->setHost('example.com'); | ||
19 | $credential->setUsername('foo'); | ||
20 | $credential->setPassword('bar'); | ||
21 | |||
22 | $manager->persist($credential); | ||
23 | |||
24 | $manager->flush(); | ||
25 | } | ||
26 | |||
27 | /** | ||
28 | * {@inheritdoc} | ||
29 | */ | ||
30 | public function getOrder() | ||
31 | { | ||
32 | return 50; | ||
33 | } | ||
34 | } | ||
diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php index 94615687..ae69492d 100644 --- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php +++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php | |||
@@ -7,7 +7,7 @@ use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfigBuilder; | |||
7 | use Graby\SiteConfig\ConfigBuilder; | 7 | use Graby\SiteConfig\ConfigBuilder; |
8 | use Psr\Log\LoggerInterface; | 8 | use Psr\Log\LoggerInterface; |
9 | use Wallabag\CoreBundle\Repository\SiteCredentialRepository; | 9 | use Wallabag\CoreBundle\Repository\SiteCredentialRepository; |
10 | use Wallabag\UserBundle\Entity\User; | 10 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; |
11 | 11 | ||
12 | class GrabySiteConfigBuilder implements SiteConfigBuilder | 12 | class GrabySiteConfigBuilder implements SiteConfigBuilder |
13 | { | 13 | { |
@@ -27,7 +27,7 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder | |||
27 | private $logger; | 27 | private $logger; |
28 | 28 | ||
29 | /** | 29 | /** |
30 | * @var User | 30 | * @var Wallabag\UserBundle\Entity\User|null |
31 | */ | 31 | */ |
32 | private $currentUser; | 32 | private $currentUser; |
33 | 33 | ||
@@ -36,16 +36,19 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder | |||
36 | * GrabySiteConfigBuilder constructor. | 36 | * GrabySiteConfigBuilder constructor. |
37 | * | 37 | * |
38 | * @param ConfigBuilder $grabyConfigBuilder | 38 | * @param ConfigBuilder $grabyConfigBuilder |
39 | * @param User $currentUser | 39 | * @param TokenStorage $token |
40 | * @param SiteCredentialRepository $credentialRepository | 40 | * @param SiteCredentialRepository $credentialRepository |
41 | * @param LoggerInterface $logger | 41 | * @param LoggerInterface $logger |
42 | */ | 42 | */ |
43 | public function __construct(ConfigBuilder $grabyConfigBuilder, User $currentUser, SiteCredentialRepository $credentialRepository, LoggerInterface $logger) | 43 | public function __construct(ConfigBuilder $grabyConfigBuilder, TokenStorage $token, SiteCredentialRepository $credentialRepository, LoggerInterface $logger) |
44 | { | 44 | { |
45 | $this->grabyConfigBuilder = $grabyConfigBuilder; | 45 | $this->grabyConfigBuilder = $grabyConfigBuilder; |
46 | $this->credentialRepository = $credentialRepository; | 46 | $this->credentialRepository = $credentialRepository; |
47 | $this->currentUser = $currentUser; | ||
48 | $this->logger = $logger; | 47 | $this->logger = $logger; |
48 | |||
49 | if ($token->getToken()) { | ||
50 | $this->currentUser = $token->getToken()->getUser(); | ||
51 | } | ||
49 | } | 52 | } |
50 | 53 | ||
51 | /** | 54 | /** |
@@ -59,7 +62,10 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder | |||
59 | $host = substr($host, 4); | 62 | $host = substr($host, 4); |
60 | } | 63 | } |
61 | 64 | ||
62 | $credentials = $this->credentialRepository->findOneByHostAndUser($host, $this->currentUser->getId()); | 65 | $credentials = null; |
66 | if ($this->currentUser) { | ||
67 | $credentials = $this->credentialRepository->findOneByHostAndUser($host, $this->currentUser->getId()); | ||
68 | } | ||
63 | 69 | ||
64 | if (null === $credentials) { | 70 | if (null === $credentials) { |
65 | $this->logger->debug('Auth: no credentials available for host.', ['host' => $host]); | 71 | $this->logger->debug('Auth: no credentials available for host.', ['host' => $host]); |
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index a59152d3..09bc77fe 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml | |||
@@ -63,7 +63,7 @@ services: | |||
63 | class: Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder | 63 | class: Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder |
64 | arguments: | 64 | arguments: |
65 | - "@wallabag_core.graby.config_builder" | 65 | - "@wallabag_core.graby.config_builder" |
66 | - "@=service('security.token_storage').getToken().getUser()" | 66 | - "@security.token_storage" |
67 | - "@wallabag_core.site_credential_repository" | 67 | - "@wallabag_core.site_credential_repository" |
68 | - '@logger' | 68 | - '@logger' |
69 | tags: | 69 | tags: |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index ef58a16b..3a3fb91d 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml | |||
@@ -32,6 +32,7 @@ menu: | |||
32 | # save_link: 'Save a link' | 32 | # save_link: 'Save a link' |
33 | back_to_unread: 'Tilbage til de ulæste artikler' | 33 | back_to_unread: 'Tilbage til de ulæste artikler' |
34 | # users_management: 'Users management' | 34 | # users_management: 'Users management' |
35 | # site_credentials: 'Site credentials' | ||
35 | top: | 36 | top: |
36 | add_new_entry: 'Tilføj ny artikel' | 37 | add_new_entry: 'Tilføj ny artikel' |
37 | search: 'Søg' | 38 | search: 'Søg' |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index d026a030..85f0e1a3 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml | |||
@@ -32,6 +32,7 @@ menu: | |||
32 | save_link: 'Link speichern' | 32 | save_link: 'Link speichern' |
33 | back_to_unread: 'Zurück zu ungelesenen Artikeln' | 33 | back_to_unread: 'Zurück zu ungelesenen Artikeln' |
34 | users_management: 'Benutzerverwaltung' | 34 | users_management: 'Benutzerverwaltung' |
35 | # site_credentials: 'Site credentials' | ||
35 | top: | 36 | top: |
36 | add_new_entry: 'Neuen Artikel hinzufügen' | 37 | add_new_entry: 'Neuen Artikel hinzufügen' |
37 | search: 'Suche' | 38 | search: 'Suche' |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index 12feb7dd..284fa2fb 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml | |||
@@ -32,6 +32,7 @@ menu: | |||
32 | save_link: 'Save a link' | 32 | save_link: 'Save a link' |
33 | back_to_unread: 'Back to unread articles' | 33 | back_to_unread: 'Back to unread articles' |
34 | users_management: 'Users management' | 34 | users_management: 'Users management' |
35 | site_credentials: 'Site credentials' | ||
35 | top: | 36 | top: |
36 | add_new_entry: 'Add a new entry' | 37 | add_new_entry: 'Add a new entry' |
37 | search: 'Search' | 38 | search: 'Search' |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index 2351d467..33bb879c 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml | |||
@@ -32,6 +32,7 @@ menu: | |||
32 | save_link: 'Guardar un enlace' | 32 | save_link: 'Guardar un enlace' |
33 | back_to_unread: 'Volver a los artículos sin leer' | 33 | back_to_unread: 'Volver a los artículos sin leer' |
34 | users_management: 'Configuración de usuarios' | 34 | users_management: 'Configuración de usuarios' |
35 | # site_credentials: 'Site credentials' | ||
35 | top: | 36 | top: |
36 | add_new_entry: 'Añadir un nuevo artículo' | 37 | add_new_entry: 'Añadir un nuevo artículo' |
37 | search: 'Buscar' | 38 | search: 'Buscar' |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index 32e1ff42..90eb119c 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml | |||
@@ -32,6 +32,7 @@ menu: | |||
32 | save_link: 'ذخیرهٔ یک پیوند' | 32 | save_link: 'ذخیرهٔ یک پیوند' |
33 | back_to_unread: 'بازگشت به خواندهنشدهها' | 33 | back_to_unread: 'بازگشت به خواندهنشدهها' |
34 | # users_management: 'Users management' | 34 | # users_management: 'Users management' |
35 | # site_credentials: 'Site credentials' | ||
35 | top: | 36 | top: |
36 | add_new_entry: 'افزودن مقالهٔ تازه' | 37 | add_new_entry: 'افزودن مقالهٔ تازه' |
37 | search: 'جستجو' | 38 | search: 'جستجو' |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index 17eaf015..542ddf48 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml | |||
@@ -32,6 +32,7 @@ menu: | |||
32 | save_link: "Sauvegarder un nouvel article" | 32 | save_link: "Sauvegarder un nouvel article" |
33 | back_to_unread: "Retour aux articles non lus" | 33 | back_to_unread: "Retour aux articles non lus" |
34 | users_management: "Gestion des utilisateurs" | 34 | users_management: "Gestion des utilisateurs" |
35 | site_credentials: 'Accès aux sites' | ||
35 | top: | 36 | top: |
36 | add_new_entry: "Sauvegarder un nouvel article" | 37 | add_new_entry: "Sauvegarder un nouvel article" |
37 | search: "Rechercher" | 38 | search: "Rechercher" |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index 752085c8..5cb2a68f 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml | |||
@@ -32,6 +32,7 @@ menu: | |||
32 | save_link: 'Salva collegamento' | 32 | save_link: 'Salva collegamento' |
33 | back_to_unread: 'Torna ai contenuti non letti' | 33 | back_to_unread: 'Torna ai contenuti non letti' |
34 | # users_management: 'Users management' | 34 | # users_management: 'Users management' |
35 | # site_credentials: 'Site credentials' | ||
35 | top: | 36 | top: |
36 | add_new_entry: 'Aggiungi un nuovo contenuto' | 37 | add_new_entry: 'Aggiungi un nuovo contenuto' |
37 | search: 'Cerca' | 38 | search: 'Cerca' |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index 9e941de0..bc11b2a4 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml | |||
@@ -32,6 +32,7 @@ menu: | |||
32 | save_link: 'Enregistrar un novèl article' | 32 | save_link: 'Enregistrar un novèl article' |
33 | back_to_unread: 'Tornar als articles pas legits' | 33 | back_to_unread: 'Tornar als articles pas legits' |
34 | users_management: 'Gestion dels utilizaires' | 34 | users_management: 'Gestion dels utilizaires' |
35 | # site_credentials: 'Site credentials' | ||
35 | top: | 36 | top: |
36 | add_new_entry: 'Enregistrar un novèl article' | 37 | add_new_entry: 'Enregistrar un novèl article' |
37 | search: 'Cercar' | 38 | search: 'Cercar' |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index 38e051f5..033d6ac5 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml | |||
@@ -32,6 +32,7 @@ menu: | |||
32 | save_link: 'Zapisz link' | 32 | save_link: 'Zapisz link' |
33 | back_to_unread: 'Powrót do nieprzeczytanych artykułów' | 33 | back_to_unread: 'Powrót do nieprzeczytanych artykułów' |
34 | users_management: 'Zarządzanie użytkownikami' | 34 | users_management: 'Zarządzanie użytkownikami' |
35 | # site_credentials: 'Site credentials' | ||
35 | top: | 36 | top: |
36 | add_new_entry: 'Dodaj nowy wpis' | 37 | add_new_entry: 'Dodaj nowy wpis' |
37 | search: 'Szukaj' | 38 | search: 'Szukaj' |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml index d3b245b8..c70c2496 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml | |||
@@ -32,6 +32,7 @@ menu: | |||
32 | save_link: 'Salvar um link' | 32 | save_link: 'Salvar um link' |
33 | back_to_unread: 'Voltar para os artigos não lidos' | 33 | back_to_unread: 'Voltar para os artigos não lidos' |
34 | users_management: 'Gestão de Usuários' | 34 | users_management: 'Gestão de Usuários' |
35 | # site_credentials: 'Site credentials' | ||
35 | top: | 36 | top: |
36 | add_new_entry: 'Adicionar uma nova entrada' | 37 | add_new_entry: 'Adicionar uma nova entrada' |
37 | search: 'Pesquisa' | 38 | search: 'Pesquisa' |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index 66c72429..a5dc44f0 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml | |||
@@ -32,6 +32,7 @@ menu: | |||
32 | # save_link: 'Save a link' | 32 | # save_link: 'Save a link' |
33 | back_to_unread: 'Înapoi la articolele necitite' | 33 | back_to_unread: 'Înapoi la articolele necitite' |
34 | # users_management: 'Users management' | 34 | # users_management: 'Users management' |
35 | # site_credentials: 'Site credentials' | ||
35 | top: | 36 | top: |
36 | add_new_entry: 'Introdu un nou articol' | 37 | add_new_entry: 'Introdu un nou articol' |
37 | search: 'Căutare' | 38 | search: 'Căutare' |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml index 34ae5b87..4d01e7f7 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml | |||
@@ -32,6 +32,7 @@ menu: | |||
32 | # save_link: 'Save a link' | 32 | # save_link: 'Save a link' |
33 | back_to_unread: 'Okunmayan makalelere geri dön' | 33 | back_to_unread: 'Okunmayan makalelere geri dön' |
34 | # users_management: 'Users management' | 34 | # users_management: 'Users management' |
35 | # site_credentials: 'Site credentials' | ||
35 | top: | 36 | top: |
36 | add_new_entry: 'Yeni bir makale ekle' | 37 | add_new_entry: 'Yeni bir makale ekle' |
37 | search: 'Ara' | 38 | search: 'Ara' |
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/edit.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/edit.html.twig index 8448f17e..882be430 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/edit.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/edit.html.twig | |||
@@ -49,7 +49,7 @@ | |||
49 | <button onclick="return confirm('{{ 'site_credential.form.delete_confirm'|trans|escape('js') }}')" type="submit" class="btn waves-effect waves-light red">{{ 'site_credential.form.delete'|trans }}</button> | 49 | <button onclick="return confirm('{{ 'site_credential.form.delete_confirm'|trans|escape('js') }}')" type="submit" class="btn waves-effect waves-light red">{{ 'site_credential.form.delete'|trans }}</button> |
50 | {{ form_end(delete_form) }} | 50 | {{ form_end(delete_form) }} |
51 | </p> | 51 | </p> |
52 | <p><a class="waves-effect waves-light btn blue-grey" href="{{ path('site_credential_index') }}">{{ 'site_credential.form.back_to_list'|trans }}</a></p> | 52 | <p><a class="waves-effect waves-light btn blue-grey" href="{{ path('site_credentials_index') }}">{{ 'site_credential.form.back_to_list'|trans }}</a></p> |
53 | </div> | 53 | </div> |
54 | </div> | 54 | </div> |
55 | </div> | 55 | </div> |
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig index fda60b31..c128bceb 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig | |||
@@ -25,7 +25,7 @@ | |||
25 | <td>{{ credential.host }}</td> | 25 | <td>{{ credential.host }}</td> |
26 | <td>{{ credential.username }}</td> | 26 | <td>{{ credential.username }}</td> |
27 | <td> | 27 | <td> |
28 | <a href="{{ path('site_credential_edit', { 'id': credential.id }) }}">{{ 'site_credential.list.edit_action'|trans }}</a> | 28 | <a href="{{ path('site_credentials_edit', { 'id': credential.id }) }}">{{ 'site_credential.list.edit_action'|trans }}</a> |
29 | </td> | 29 | </td> |
30 | </tr> | 30 | </tr> |
31 | {% endfor %} | 31 | {% endfor %} |
@@ -33,7 +33,7 @@ | |||
33 | </table> | 33 | </table> |
34 | <br /> | 34 | <br /> |
35 | <p> | 35 | <p> |
36 | <a href="{{ path('site_credential_new') }}" class="waves-effect waves-light btn">{{ 'site_credential.list.create_new_one'|trans }}</a> | 36 | <a href="{{ path('site_credentials_new') }}" class="waves-effect waves-light btn">{{ 'site_credential.list.create_new_one'|trans }}</a> |
37 | </p> | 37 | </p> |
38 | </div> | 38 | </div> |
39 | </div> | 39 | </div> |
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/new.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/new.html.twig index bf713902..3c008cde 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/new.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/new.html.twig | |||
@@ -42,7 +42,7 @@ | |||
42 | {{ form_widget(form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} | 42 | {{ form_widget(form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} |
43 | {{ form_rest(form) }} | 43 | {{ form_rest(form) }} |
44 | </form> | 44 | </form> |
45 | <p><a class="waves-effect waves-light btn blue-grey" href="{{ path('site_credential_index') }}">{{ 'site_credential.form.back_to_list'|trans }}</a></p> | 45 | <p><a class="waves-effect waves-light btn blue-grey" href="{{ path('site_credentials_index') }}">{{ 'site_credential.form.back_to_list'|trans }}</a></p> |
46 | </div> | 46 | </div> |
47 | </div> | 47 | </div> |
48 | </div> | 48 | </div> |
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig index 42aeace9..17fa13bb 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig | |||
@@ -38,6 +38,9 @@ | |||
38 | {{ render(controller("WallabagCoreBundle:Entry:searchForm", {'currentRoute': app.request.attributes.get('_route')})) }} | 38 | {{ render(controller("WallabagCoreBundle:Entry:searchForm", {'currentRoute': app.request.attributes.get('_route')})) }} |
39 | </div> | 39 | </div> |
40 | </li> | 40 | </li> |
41 | {% if craue_setting('restricted_access') %} | ||
42 | <li class="menu site_credentials"><a href="{{ path('site_credentials_index') }}">{{ 'menu.left.site_credentials'|trans }}</a></li> | ||
43 | {% endif %} | ||
41 | <li class="menu config"><a href="{{ path('config') }}">{{ 'menu.left.config'|trans }}</a></li> | 44 | <li class="menu config"><a href="{{ path('config') }}">{{ 'menu.left.config'|trans }}</a></li> |
42 | {% if is_granted('ROLE_SUPER_ADMIN') %} | 45 | {% if is_granted('ROLE_SUPER_ADMIN') %} |
43 | <li class="menu users"><a href="{{ path('user_index') }}">{{ 'menu.left.users_management'|trans }}</a></li> | 46 | <li class="menu users"><a href="{{ path('user_index') }}">{{ 'menu.left.users_management'|trans }}</a></li> |
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig index 2dab1c18..60907e11 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig | |||
@@ -66,6 +66,11 @@ | |||
66 | <li class="bold {% if currentRoute == 'config' %}active{% endif %}"> | 66 | <li class="bold {% if currentRoute == 'config' %}active{% endif %}"> |
67 | <a class="waves-effect" href="{{ path('config') }}">{{ 'menu.left.config'|trans }}</a> | 67 | <a class="waves-effect" href="{{ path('config') }}">{{ 'menu.left.config'|trans }}</a> |
68 | </li> | 68 | </li> |
69 | {% if craue_setting('restricted_access') %} | ||
70 | <li class="bold {% if currentRoute starts with 'site_credentials_' %}active{% endif %}"> | ||
71 | <a class="waves-effect" href="{{ path('site_credentials_index') }}">{{ 'menu.left.site_credentials'|trans }}</a> | ||
72 | </li> | ||
73 | {% endif %} | ||
69 | {% if is_granted('ROLE_SUPER_ADMIN') %} | 74 | {% if is_granted('ROLE_SUPER_ADMIN') %} |
70 | <li class="bold {% if currentRoute starts with 'user_' %}active{% endif %}"> | 75 | <li class="bold {% if currentRoute starts with 'user_' %}active{% endif %}"> |
71 | <a class="waves-effect" href="{{ path('user_index') }}">{{ 'menu.left.users_management'|trans }}</a> | 76 | <a class="waves-effect" href="{{ path('user_index') }}">{{ 'menu.left.users_management'|trans }}</a> |
diff --git a/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php new file mode 100644 index 00000000..47bf0907 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php | |||
@@ -0,0 +1,140 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
6 | |||
7 | class SiteCredentialControllerTest extends WallabagCoreTestCase | ||
8 | { | ||
9 | public function testListSiteCredential() | ||
10 | { | ||
11 | $this->logInAs('admin'); | ||
12 | $client = $this->getClient(); | ||
13 | |||
14 | $crawler = $client->request('GET', '/site-credentials/'); | ||
15 | |||
16 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
17 | |||
18 | $body = $crawler->filter('body')->extract(['_text'])[0]; | ||
19 | |||
20 | $this->assertContains('site_credential.description', $body); | ||
21 | $this->assertContains('site_credential.list.create_new_one', $body); | ||
22 | } | ||
23 | |||
24 | public function testNewSiteCredential() | ||
25 | { | ||
26 | $this->logInAs('admin'); | ||
27 | $client = $this->getClient(); | ||
28 | |||
29 | $crawler = $client->request('GET', '/site-credentials/new'); | ||
30 | |||
31 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
32 | |||
33 | $body = $crawler->filter('body')->extract(['_text'])[0]; | ||
34 | |||
35 | $this->assertContains('site_credential.new_site_credential', $body); | ||
36 | $this->assertContains('site_credential.form.back_to_list', $body); | ||
37 | |||
38 | $form = $crawler->filter('button[id=site_credential_save]')->form(); | ||
39 | |||
40 | $data = [ | ||
41 | 'site_credential[host]' => 'google.io', | ||
42 | 'site_credential[username]' => 'sergei', | ||
43 | 'site_credential[password]' => 'microsoft', | ||
44 | ]; | ||
45 | |||
46 | $client->submit($form, $data); | ||
47 | |||
48 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
49 | |||
50 | $crawler = $client->followRedirect(); | ||
51 | |||
52 | $this->assertContains('flashes.site_credential.notice.added', $crawler->filter('body')->extract(['_text'])[0]); | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * @depends testNewSiteCredential | ||
57 | */ | ||
58 | public function testEditSiteCredential() | ||
59 | { | ||
60 | $this->logInAs('admin'); | ||
61 | $client = $this->getClient(); | ||
62 | |||
63 | $credential = $client->getContainer() | ||
64 | ->get('doctrine.orm.entity_manager') | ||
65 | ->getRepository('WallabagCoreBundle:SiteCredential') | ||
66 | ->findOneByHost('google.io'); | ||
67 | |||
68 | $crawler = $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); | ||
69 | |||
70 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
71 | |||
72 | $body = $crawler->filter('body')->extract(['_text'])[0]; | ||
73 | |||
74 | $this->assertContains('site_credential.edit_site_credential', $body); | ||
75 | $this->assertContains('site_credential.form.back_to_list', $body); | ||
76 | |||
77 | $form = $crawler->filter('button[id=site_credential_save]')->form(); | ||
78 | |||
79 | $data = [ | ||
80 | 'site_credential[host]' => 'google.io', | ||
81 | 'site_credential[username]' => 'larry', | ||
82 | 'site_credential[password]' => 'microsoft', | ||
83 | ]; | ||
84 | |||
85 | $client->submit($form, $data); | ||
86 | |||
87 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
88 | |||
89 | $crawler = $client->followRedirect(); | ||
90 | |||
91 | $this->assertContains('flashes.site_credential.notice.updated', $crawler->filter('body')->extract(['_text'])[0]); | ||
92 | $this->assertContains('larry', $crawler->filter('input[id=site_credential_username]')->attr('value')); | ||
93 | } | ||
94 | |||
95 | /** | ||
96 | * @depends testNewSiteCredential | ||
97 | */ | ||
98 | public function testEditFromADifferentUserSiteCredential() | ||
99 | { | ||
100 | $this->logInAs('bob'); | ||
101 | $client = $this->getClient(); | ||
102 | |||
103 | $credential = $client->getContainer() | ||
104 | ->get('doctrine.orm.entity_manager') | ||
105 | ->getRepository('WallabagCoreBundle:SiteCredential') | ||
106 | ->findOneByHost('google.io'); | ||
107 | |||
108 | $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); | ||
109 | |||
110 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | ||
111 | } | ||
112 | |||
113 | /** | ||
114 | * @depends testNewSiteCredential | ||
115 | */ | ||
116 | public function testDeleteSiteCredential() | ||
117 | { | ||
118 | $this->logInAs('admin'); | ||
119 | $client = $this->getClient(); | ||
120 | |||
121 | $credential = $client->getContainer() | ||
122 | ->get('doctrine.orm.entity_manager') | ||
123 | ->getRepository('WallabagCoreBundle:SiteCredential') | ||
124 | ->findOneByHost('google.io'); | ||
125 | |||
126 | $crawler = $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); | ||
127 | |||
128 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
129 | |||
130 | $deleteForm = $crawler->filter('body')->selectButton('site_credential.form.delete')->form(); | ||
131 | |||
132 | $client->submit($deleteForm, []); | ||
133 | |||
134 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
135 | |||
136 | $crawler = $client->followRedirect(); | ||
137 | |||
138 | $this->assertContains('flashes.site_credential.notice.deleted', $crawler->filter('body')->extract(['_text'])[0]); | ||
139 | } | ||
140 | } | ||
diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index 8b50bce9..980f7579 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php | |||
@@ -8,6 +8,8 @@ use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig; | |||
8 | use Graby\SiteConfig\SiteConfig as GrabySiteConfig; | 8 | use Graby\SiteConfig\SiteConfig as GrabySiteConfig; |
9 | use PHPUnit_Framework_TestCase; | 9 | use PHPUnit_Framework_TestCase; |
10 | use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder; | 10 | use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder; |
11 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; | ||
12 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; | ||
11 | 13 | ||
12 | class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase | 14 | class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase |
13 | { | 15 | { |
@@ -17,7 +19,7 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase | |||
17 | public function testBuildConfigExists() | 19 | public function testBuildConfigExists() |
18 | { | 20 | { |
19 | /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */ | 21 | /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */ |
20 | $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder') | 22 | $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder') |
21 | ->disableOriginalConstructor() | 23 | ->disableOriginalConstructor() |
22 | ->getMock(); | 24 | ->getMock(); |
23 | 25 | ||
@@ -38,9 +40,30 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase | |||
38 | $handler = new TestHandler(); | 40 | $handler = new TestHandler(); |
39 | $logger->pushHandler($handler); | 41 | $logger->pushHandler($handler); |
40 | 42 | ||
43 | $siteCrentialRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\SiteCredentialRepository') | ||
44 | ->disableOriginalConstructor() | ||
45 | ->getMock(); | ||
46 | $siteCrentialRepo->expects($this->once()) | ||
47 | ->method('findOneByHostAndUser') | ||
48 | ->with('example.com', 1) | ||
49 | ->willReturn(['username' => 'foo', 'password' => 'bar']); | ||
50 | |||
51 | $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') | ||
52 | ->disableOriginalConstructor() | ||
53 | ->getMock(); | ||
54 | $user->expects($this->once()) | ||
55 | ->method('getId') | ||
56 | ->willReturn(1); | ||
57 | |||
58 | $token = new UsernamePasswordToken($user, 'pass', 'provider'); | ||
59 | |||
60 | $tokenStorage = new TokenStorage(); | ||
61 | $tokenStorage->setToken($token); | ||
62 | |||
41 | $this->builder = new GrabySiteConfigBuilder( | 63 | $this->builder = new GrabySiteConfigBuilder( |
42 | $grabyConfigBuilderMock, | 64 | $grabyConfigBuilderMock, |
43 | ['example.com' => ['username' => 'foo', 'password' => 'bar']], | 65 | $tokenStorage, |
66 | $siteCrentialRepo, | ||
44 | $logger | 67 | $logger |
45 | ); | 68 | ); |
46 | 69 | ||
@@ -82,9 +105,30 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase | |||
82 | $handler = new TestHandler(); | 105 | $handler = new TestHandler(); |
83 | $logger->pushHandler($handler); | 106 | $logger->pushHandler($handler); |
84 | 107 | ||
108 | $siteCrentialRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\SiteCredentialRepository') | ||
109 | ->disableOriginalConstructor() | ||
110 | ->getMock(); | ||
111 | $siteCrentialRepo->expects($this->once()) | ||
112 | ->method('findOneByHostAndUser') | ||
113 | ->with('unknown.com', 1) | ||
114 | ->willReturn(null); | ||
115 | |||
116 | $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') | ||
117 | ->disableOriginalConstructor() | ||
118 | ->getMock(); | ||
119 | $user->expects($this->once()) | ||
120 | ->method('getId') | ||
121 | ->willReturn(1); | ||
122 | |||
123 | $token = new UsernamePasswordToken($user, 'pass', 'provider'); | ||
124 | |||
125 | $tokenStorage = new TokenStorage(); | ||
126 | $tokenStorage->setToken($token); | ||
127 | |||
85 | $this->builder = new GrabySiteConfigBuilder( | 128 | $this->builder = new GrabySiteConfigBuilder( |
86 | $grabyConfigBuilderMock, | 129 | $grabyConfigBuilderMock, |
87 | [], | 130 | $tokenStorage, |
131 | $siteCrentialRepo, | ||
88 | $logger | 132 | $logger |
89 | ); | 133 | ); |
90 | 134 | ||