aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--app/DoctrineMigrations/Version20170602075214.php52
-rw-r--r--app/Resources/CraueConfigBundle/translations/CraueConfigBundle.da.yml1
-rw-r--r--app/Resources/CraueConfigBundle/translations/CraueConfigBundle.de.yml1
-rw-r--r--app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml1
-rw-r--r--app/Resources/CraueConfigBundle/translations/CraueConfigBundle.es.yml1
-rw-r--r--app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fa.yml1
-rw-r--r--app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fr.yml1
-rw-r--r--app/Resources/CraueConfigBundle/translations/CraueConfigBundle.it.yml1
-rw-r--r--app/Resources/CraueConfigBundle/translations/CraueConfigBundle.oc.yml1
-rw-r--r--app/Resources/CraueConfigBundle/translations/CraueConfigBundle.pl.yml1
-rw-r--r--app/Resources/CraueConfigBundle/translations/CraueConfigBundle.pt.yml1
-rw-r--r--app/Resources/CraueConfigBundle/translations/CraueConfigBundle.ro.yml1
-rw-r--r--app/Resources/CraueConfigBundle/translations/CraueConfigBundle.tr.yml1
-rw-r--r--app/config/config.yml37
-rw-r--r--app/config/security.yml1
-rw-r--r--app/config/wallabag.yml164
-rw-r--r--src/Wallabag/ApiBundle/Controller/UserRestController.php23
-rw-r--r--src/Wallabag/CoreBundle/Command/InstallCommand.php160
-rw-r--r--src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php174
-rw-r--r--src/Wallabag/CoreBundle/DependencyInjection/Configuration.php11
-rw-r--r--src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php1
-rw-r--r--tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php98
-rw-r--r--tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php10
23 files changed, 358 insertions, 385 deletions
diff --git a/app/DoctrineMigrations/Version20170602075214.php b/app/DoctrineMigrations/Version20170602075214.php
new file mode 100644
index 00000000..451d16ba
--- /dev/null
+++ b/app/DoctrineMigrations/Version20170602075214.php
@@ -0,0 +1,52 @@
1<?php
2
3namespace Application\Migrations;
4
5use Doctrine\DBAL\Migrations\AbstractMigration;
6use Doctrine\DBAL\Schema\Schema;
7use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8use Symfony\Component\DependencyInjection\ContainerInterface;
9
10/**
11 * Add api_user_registration in craue_config_setting.
12 */
13class Version20170602075214 extends AbstractMigration implements ContainerAwareInterface
14{
15 /**
16 * @var ContainerInterface
17 */
18 private $container;
19
20 public function setContainer(ContainerInterface $container = null)
21 {
22 $this->container = $container;
23 }
24
25 private function getTable($tableName)
26 {
27 return $this->container->getParameter('database_table_prefix').$tableName;
28 }
29
30 /**
31 * @param Schema $schema
32 */
33 public function up(Schema $schema)
34 {
35 $apiUserRegistration = $this->container
36 ->get('doctrine.orm.default_entity_manager')
37 ->getConnection()
38 ->fetchArray('SELECT * FROM '.$this->getTable('craue_config_setting')." WHERE name = 'api_user_registration'");
39
40 $this->skipIf(false !== $apiUserRegistration, 'It seems that you already played this migration.');
41
42 $this->addSql('INSERT INTO '.$this->getTable('craue_config_setting')." (name, value, section) VALUES ('api_user_registration', '0', 'api')");
43 }
44
45 /**
46 * @param Schema $schema
47 */
48 public function down(Schema $schema)
49 {
50 $this->addSql('DELETE FROM '.$this->getTable('craue_config_setting')." WHERE name = 'api_user_registration';");
51 }
52}
diff --git a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.da.yml b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.da.yml
index d1f7e3b5..20e938f5 100644
--- a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.da.yml
+++ b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.da.yml
@@ -34,3 +34,4 @@ demo_mode_username: "Demobruger"
34# share_public: Allow public url for entries 34# share_public: Allow public url for entries
35# download_images_enabled: Download images locally 35# download_images_enabled: Download images locally
36# restricted_access: Enable authentication for websites with paywall 36# restricted_access: Enable authentication for websites with paywall
37# api_user_registration: Enable user to be registered using the API
diff --git a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.de.yml b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.de.yml
index 1105675b..526d41bc 100644
--- a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.de.yml
+++ b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.de.yml
@@ -34,3 +34,4 @@ demo_mode_username: "Test-Benutzer"
34share_public: Erlaube eine öffentliche URL für Einträge 34share_public: Erlaube eine öffentliche URL für Einträge
35# download_images_enabled: Download images locally 35# download_images_enabled: Download images locally
36# restricted_access: Enable authentication for websites with paywall 36# restricted_access: Enable authentication for websites with paywall
37# api_user_registration: Enable user to be registered using the API
diff --git a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml
index 802599b3..3c0037f3 100644
--- a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml
+++ b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml
@@ -34,3 +34,4 @@ demo_mode_username: "Demo user"
34share_public: Allow public url for entries 34share_public: Allow public url for entries
35download_images_enabled: Download images locally 35download_images_enabled: Download images locally
36restricted_access: Enable authentication for websites with paywall 36restricted_access: Enable authentication for websites with paywall
37api_user_registration: Enable user to be registered using the API
diff --git a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.es.yml b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.es.yml
index b3ac18ed..99869669 100644
--- a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.es.yml
+++ b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.es.yml
@@ -34,3 +34,4 @@ demo_mode_username: "Nombre de usuario demo"
34share_public: Permitir URL pública para los artículos 34share_public: Permitir URL pública para los artículos
35download_images_enabled: Descargar imágenes localmente 35download_images_enabled: Descargar imágenes localmente
36restricted_access: Activar autenticación para websites con paywall 36restricted_access: Activar autenticación para websites con paywall
37# api_user_registration: Enable user to be registered using the API
diff --git a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fa.yml b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fa.yml
index c73d63e2..2e1307e5 100644
--- a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fa.yml
+++ b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fa.yml
@@ -34,3 +34,4 @@ modify_settings: "اعمال"
34# share_public: Allow public url for entries 34# share_public: Allow public url for entries
35# download_images_enabled: Download images locally 35# download_images_enabled: Download images locally
36# restricted_access: Enable authentication for websites with paywall 36# restricted_access: Enable authentication for websites with paywall
37# api_user_registration: Enable user to be registered using the API
diff --git a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fr.yml b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fr.yml
index a53174ae..454053ad 100644
--- a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fr.yml
+++ b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.fr.yml
@@ -34,3 +34,4 @@ demo_mode_username: "Utilisateur de la démo"
34share_public: Autoriser une URL publique pour les articles 34share_public: Autoriser une URL publique pour les articles
35download_images_enabled: Télécharger les images en local 35download_images_enabled: Télécharger les images en local
36restricted_access: Activer l'authentification pour les articles derrière un paywall 36restricted_access: Activer l'authentification pour les articles derrière un paywall
37api_user_registration: Activer la création de compte depuis l'API
diff --git a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.it.yml b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.it.yml
index 3d53fc8d..4dbd2ff8 100644
--- a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.it.yml
+++ b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.it.yml
@@ -34,3 +34,4 @@ demo_mode_username: "Utente Demo"
34# share_public: Allow public url for entries 34# share_public: Allow public url for entries
35# download_images_enabled: Download images locally 35# download_images_enabled: Download images locally
36# restricted_access: Enable authentication for websites with paywall 36# restricted_access: Enable authentication for websites with paywall
37api_user_registration: Abilita la registrazione dell'utente attraverso l'API
diff --git a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.oc.yml b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.oc.yml
index 79f75245..00c06638 100644
--- a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.oc.yml
+++ b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.oc.yml
@@ -34,3 +34,4 @@ demo_mode_username: "Utilizaire de la demostracion"
34share_public: Autorizar una URL publica pels articles 34share_public: Autorizar una URL publica pels articles
35download_images_enabled: Telecargar los imatges en local 35download_images_enabled: Telecargar los imatges en local
36restricted_access: Activar l'autenticacion pels sites amb peatge 36restricted_access: Activar l'autenticacion pels sites amb peatge
37# api_user_registration: Enable user to be registered using the API
diff --git a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.pl.yml b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.pl.yml
index 02fe98e3..ada11b3a 100644
--- a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.pl.yml
+++ b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.pl.yml
@@ -34,3 +34,4 @@ demo_mode_username: "Użytkownik Demonstracyjny"
34share_public: Zezwalaj na publiczny adres url dla wpisow 34share_public: Zezwalaj na publiczny adres url dla wpisow
35download_images_enabled: Pobierz obrazy lokalnie 35download_images_enabled: Pobierz obrazy lokalnie
36restricted_access: Włącz autoryzację dla stron z paywallem 36restricted_access: Włącz autoryzację dla stron z paywallem
37api_user_registration: Włącz rejestrację użytkownika przy użyciu API
diff --git a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.pt.yml b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.pt.yml
index 4a061bce..59af9610 100644
--- a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.pt.yml
+++ b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.pt.yml
@@ -34,3 +34,4 @@ demo_mode_username: "Usuário demo"
34# share_public: Allow public url for entries 34# share_public: Allow public url for entries
35# download_images_enabled: Download images locally 35# download_images_enabled: Download images locally
36# restricted_access: Enable authentication for websites with paywall 36# restricted_access: Enable authentication for websites with paywall
37# api_user_registration: Enable user to be registered using the API
diff --git a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.ro.yml b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.ro.yml
index 5ee48074..104e37c6 100644
--- a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.ro.yml
+++ b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.ro.yml
@@ -34,3 +34,4 @@ modify_settings: "aplică"
34# share_public: Allow public url for entries 34# share_public: Allow public url for entries
35# download_images_enabled: Download images locally 35# download_images_enabled: Download images locally
36# restricted_access: Enable authentication for websites with paywall 36# restricted_access: Enable authentication for websites with paywall
37# api_user_registration: Enable user to be registered using the API
diff --git a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.tr.yml b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.tr.yml
index d83a4b7b..1579366d 100644
--- a/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.tr.yml
+++ b/app/Resources/CraueConfigBundle/translations/CraueConfigBundle.tr.yml
@@ -34,3 +34,4 @@
34# share_public: Allow public url for entries 34# share_public: Allow public url for entries
35# download_images_enabled: Download images locally 35# download_images_enabled: Download images locally
36# restricted_access: Enable authentication for websites with paywall 36# restricted_access: Enable authentication for websites with paywall
37# api_user_registration: Enable user to be registered using the API
diff --git a/app/config/config.yml b/app/config/config.yml
index 04f8547d..2bc5e3b3 100644
--- a/app/config/config.yml
+++ b/app/config/config.yml
@@ -2,6 +2,7 @@ imports:
2 - { resource: parameters.yml } 2 - { resource: parameters.yml }
3 - { resource: security.yml } 3 - { resource: security.yml }
4 - { resource: services.yml } 4 - { resource: services.yml }
5 - { resource: wallabag.yml }
5 6
6parameters: 7parameters:
7 # Allows to use the live reload feature for changes in assets 8 # Allows to use the live reload feature for changes in assets
@@ -34,42 +35,6 @@ framework:
34 http_method_override: true 35 http_method_override: true
35 assets: ~ 36 assets: ~
36 37
37wallabag_core:
38 version: 2.2.3
39 paypal_url: "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9UBA65LG3FX9Y&lc=gb"
40 languages:
41 en: 'English'
42 fr: 'Français'
43 de: 'Deutsch'
44 tr: 'Türkçe'
45 fa: 'فارسی'
46 ro: 'Română'
47 pl: 'Polish'
48 da: 'Dansk'
49 es: 'Español'
50 oc: 'Occitan'
51 it: 'Italiano'
52 pt: 'Português'
53 items_on_page: 12
54 theme: material
55 language: '%locale%'
56 rss_limit: 50
57 reading_speed: 1
58 cache_lifetime: 10
59 action_mark_as_read: 1
60 list_mode: 0
61 fetching_error_message_title: 'No title found'
62 fetching_error_message: |
63 wallabag can't retrieve contents for this article. Please <a href="http://doc.wallabag.org/en/user/errors_during_fetching.html#how-can-i-help-to-fix-that">troubleshoot this issue</a>.
64 api_limit_mass_actions: 10
65
66wallabag_user:
67 registration_enabled: "%fosuser_registration%"
68
69wallabag_import:
70 allow_mimetypes: ['application/octet-stream', 'application/json', 'text/plain', 'text/csv']
71 resource_dir: "%kernel.root_dir%/../web/uploads/import"
72
73# Twig Configuration 38# Twig Configuration
74twig: 39twig:
75 debug: "%kernel.debug%" 40 debug: "%kernel.debug%"
diff --git a/app/config/security.yml b/app/config/security.yml
index efb00a53..ffb1d356 100644
--- a/app/config/security.yml
+++ b/app/config/security.yml
@@ -56,6 +56,7 @@ security:
56 access_control: 56 access_control:
57 - { path: ^/api/doc, roles: IS_AUTHENTICATED_ANONYMOUSLY } 57 - { path: ^/api/doc, roles: IS_AUTHENTICATED_ANONYMOUSLY }
58 - { path: ^/api/version, roles: IS_AUTHENTICATED_ANONYMOUSLY } 58 - { path: ^/api/version, roles: IS_AUTHENTICATED_ANONYMOUSLY }
59 - { path: ^/api/user, roles: IS_AUTHENTICATED_ANONYMOUSLY }
59 - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } 60 - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
60 - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } 61 - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
61 - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } 62 - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
diff --git a/app/config/wallabag.yml b/app/config/wallabag.yml
new file mode 100644
index 00000000..d8c593c6
--- /dev/null
+++ b/app/config/wallabag.yml
@@ -0,0 +1,164 @@
1wallabag_core:
2 version: 2.2.3
3 paypal_url: "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9UBA65LG3FX9Y&lc=gb"
4 languages:
5 en: 'English'
6 fr: 'Français'
7 de: 'Deutsch'
8 tr: 'Türkçe'
9 fa: 'فارسی'
10 ro: 'Română'
11 pl: 'Polish'
12 da: 'Dansk'
13 es: 'Español'
14 oc: 'Occitan'
15 it: 'Italiano'
16 pt: 'Português'
17 items_on_page: 12
18 theme: material
19 language: '%locale%'
20 rss_limit: 50
21 reading_speed: 1
22 cache_lifetime: 10
23 action_mark_as_read: 1
24 list_mode: 0
25 fetching_error_message_title: 'No title found'
26 fetching_error_message: |
27 wallabag can't retrieve contents for this article. Please <a href="http://doc.wallabag.org/en/user/errors_during_fetching.html#how-can-i-help-to-fix-that">troubleshoot this issue</a>.
28 api_limit_mass_actions: 10
29 default_internal_settings:
30 -
31 name: share_public
32 value: 1
33 section: entry
34 -
35 name: carrot
36 value: 1
37 section: entry
38 -
39 name: share_diaspora
40 value: 1
41 section: entry
42 -
43 name: diaspora_url
44 value: http://diasporapod.com
45 section: entry
46 -
47 name: share_unmark
48 value: 1
49 section: entry
50 -
51 name: unmark_url
52 value: https://unmark.it
53 section: entry
54 -
55 name: share_shaarli
56 value: 1
57 section: entry
58 -
59 name: share_scuttle
60 value: 1
61 section: entry
62 -
63 name: shaarli_url
64 value: http://myshaarli.com
65 section: entry
66 -
67 name: scuttle_url
68 value: http://scuttle.org
69 section: entry
70 -
71 name: share_mail
72 value: 1
73 section: entry
74 -
75 name: share_twitter
76 value: 1
77 section: entry
78 -
79 name: show_printlink
80 value: 1
81 section: entry
82 -
83 name: restricted_access
84 value: 0
85 section: entry
86 -
87 name: export_epub
88 value: 1
89 section: export
90 -
91 name: export_mobi
92 value: 1
93 section: export
94 -
95 name: export_pdf
96 value: 1
97 section: export
98 -
99 name: export_csv
100 value: 1
101 section: export
102 -
103 name: export_json
104 value: 1
105 section: export
106 -
107 name: export_txt
108 value: 1
109 section: export
110 -
111 name: export_xml
112 value: 1
113 section: export
114 -
115 name: import_with_redis
116 value: 0
117 section: import
118 -
119 name: import_with_rabbitmq
120 value: 0
121 section: import
122 -
123 name: piwik_enabled
124 value: 0
125 section: analytics
126 -
127 name: piwik_host
128 value: v2.wallabag.org
129 section: analytics
130 -
131 name: piwik_site_id
132 value: 1
133 section: analytics
134 -
135 name: demo_mode_enabled
136 value: 0
137 section: misc
138 -
139 name: demo_mode_username
140 value: wallabag
141 section: misc
142 -
143 name: download_images_enabled
144 value: 0
145 section: misc
146 -
147 name: wallabag_support_url
148 value: https://www.wallabag.org/pages/support.html
149 section: misc
150 -
151 name: wallabag_url
152 value: http://v2.wallabag.org
153 section: misc
154 -
155 name: api_user_registration
156 value: 0
157 section: api
158
159wallabag_user:
160 registration_enabled: "%fosuser_registration%"
161
162wallabag_import:
163 allow_mimetypes: ['application/octet-stream', 'application/json', 'text/plain', 'text/csv']
164 resource_dir: "%kernel.root_dir%/../web/uploads/import"
diff --git a/src/Wallabag/ApiBundle/Controller/UserRestController.php b/src/Wallabag/ApiBundle/Controller/UserRestController.php
index a1b78e3f..8f675b8d 100644
--- a/src/Wallabag/ApiBundle/Controller/UserRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/UserRestController.php
@@ -43,16 +43,18 @@ class UserRestController extends WallabagRestController
43 */ 43 */
44 public function putUserAction(Request $request) 44 public function putUserAction(Request $request)
45 { 45 {
46 if (!$this->container->getParameter('fosuser_registration')) { 46 if (!$this->getParameter('fosuser_registration') || !$this->get('craue_config')->get('api_user_registration')) {
47 $json = $this->get('serializer')->serialize(['error' => "Server doesn't allow registrations"], 'json'); 47 $json = $this->get('serializer')->serialize(['error' => "Server doesn't allow registrations"], 'json');
48 48
49 return (new JsonResponse())->setJson($json)->setStatusCode(403); 49 return (new JsonResponse())
50 ->setJson($json)
51 ->setStatusCode(JsonResponse::HTTP_FORBIDDEN);
50 } 52 }
51 53
52 $userManager = $this->get('fos_user.user_manager'); 54 $userManager = $this->get('fos_user.user_manager');
53 $user = $userManager->createUser(); 55 $user = $userManager->createUser();
54 // enable created user by default 56 // user will be disabled BY DEFAULT to avoid spamming account to be enabled
55 $user->setEnabled(true); 57 $user->setEnabled(false);
56 58
57 $form = $this->createForm('Wallabag\UserBundle\Form\NewUserType', $user, [ 59 $form = $this->createForm('Wallabag\UserBundle\Form\NewUserType', $user, [
58 'csrf_protection' => false, 60 'csrf_protection' => false,
@@ -90,7 +92,9 @@ class UserRestController extends WallabagRestController
90 92
91 $json = $this->get('serializer')->serialize(['error' => $errors], 'json'); 93 $json = $this->get('serializer')->serialize(['error' => $errors], 'json');
92 94
93 return (new JsonResponse())->setJson($json)->setStatusCode(400); 95 return (new JsonResponse())
96 ->setJson($json)
97 ->setStatusCode(JsonResponse::HTTP_BAD_REQUEST);
94 } 98 }
95 99
96 $userManager->updateUser($user); 100 $userManager->updateUser($user);
@@ -99,17 +103,18 @@ class UserRestController extends WallabagRestController
99 $event = new UserEvent($user, $request); 103 $event = new UserEvent($user, $request);
100 $this->get('event_dispatcher')->dispatch(FOSUserEvents::USER_CREATED, $event); 104 $this->get('event_dispatcher')->dispatch(FOSUserEvents::USER_CREATED, $event);
101 105
102 return $this->sendUser($user); 106 return $this->sendUser($user, JsonResponse::HTTP_CREATED);
103 } 107 }
104 108
105 /** 109 /**
106 * Send user response. 110 * Send user response.
107 * 111 *
108 * @param User $user 112 * @param User $user
113 * @param int $status HTTP Status code to send
109 * 114 *
110 * @return JsonResponse 115 * @return JsonResponse
111 */ 116 */
112 private function sendUser(User $user) 117 private function sendUser(User $user, $status = JsonResponse::HTTP_OK)
113 { 118 {
114 $json = $this->get('serializer')->serialize( 119 $json = $this->get('serializer')->serialize(
115 $user, 120 $user,
@@ -117,7 +122,9 @@ class UserRestController extends WallabagRestController
117 SerializationContext::create()->setGroups(['user_api']) 122 SerializationContext::create()->setGroups(['user_api'])
118 ); 123 );
119 124
120 return (new JsonResponse())->setJson($json); 125 return (new JsonResponse())
126 ->setJson($json)
127 ->setStatusCode($status);
121 } 128 }
122 129
123 /** 130 /**
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php
index d9608246..0f119377 100644
--- a/src/Wallabag/CoreBundle/Command/InstallCommand.php
+++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php
@@ -292,165 +292,7 @@ class InstallCommand extends ContainerAwareCommand
292 // cleanup before insert new stuff 292 // cleanup before insert new stuff
293 $em->createQuery('DELETE FROM CraueConfigBundle:Setting')->execute(); 293 $em->createQuery('DELETE FROM CraueConfigBundle:Setting')->execute();
294 294
295 $settings = [ 295 foreach ($this->getContainer()->getParameter('wallabag_core.default_internal_settings') as $setting) {
296 [
297 'name' => 'share_public',
298 'value' => '1',
299 'section' => 'entry',
300 ],
301 [
302 'name' => 'carrot',
303 'value' => '1',
304 'section' => 'entry',
305 ],
306 [
307 'name' => 'share_diaspora',
308 'value' => '1',
309 'section' => 'entry',
310 ],
311 [
312 'name' => 'diaspora_url',
313 'value' => 'http://diasporapod.com',
314 'section' => 'entry',
315 ],
316 [
317 'name' => 'share_unmark',
318 'value' => '1',
319 'section' => 'entry',
320 ],
321 [
322 'name' => 'unmark_url',
323 'value' => 'https://unmark.it',
324 'section' => 'entry',
325 ],
326 [
327 'name' => 'share_shaarli',
328 'value' => '1',
329 'section' => 'entry',
330 ],
331 [
332 'name' => 'shaarli_url',
333 'value' => 'http://myshaarli.com',
334 'section' => 'entry',
335 ],
336 [
337 'name' => 'share_scuttle',
338 'value' => '1',
339 'section' => 'entry',
340 ],
341 [
342 'name' => 'scuttle_url',
343 'value' => 'http://scuttle.org',
344 'section' => 'entry',
345 ],
346 [
347 'name' => 'share_mail',
348 'value' => '1',
349 'section' => 'entry',
350 ],
351 [
352 'name' => 'share_twitter',
353 'value' => '1',
354 'section' => 'entry',
355 ],
356 [
357 'name' => 'export_epub',
358 'value' => '1',
359 'section' => 'export',
360 ],
361 [
362 'name' => 'export_mobi',
363 'value' => '1',
364 'section' => 'export',
365 ],
366 [
367 'name' => 'export_pdf',
368 'value' => '1',
369 'section' => 'export',
370 ],
371 [
372 'name' => 'export_csv',
373 'value' => '1',
374 'section' => 'export',
375 ],
376 [
377 'name' => 'export_json',
378 'value' => '1',
379 'section' => 'export',
380 ],
381 [
382 'name' => 'export_txt',
383 'value' => '1',
384 'section' => 'export',
385 ],
386 [
387 'name' => 'export_xml',
388 'value' => '1',
389 'section' => 'export',
390 ],
391 [
392 'name' => 'import_with_redis',
393 'value' => '0',
394 'section' => 'import',
395 ],
396 [
397 'name' => 'import_with_rabbitmq',
398 'value' => '0',
399 'section' => 'import',
400 ],
401 [
402 'name' => 'show_printlink',
403 'value' => '1',
404 'section' => 'entry',
405 ],
406 [
407 'name' => 'wallabag_support_url',
408 'value' => 'https://www.wallabag.org/pages/support.html',
409 'section' => 'misc',
410 ],
411 [
412 'name' => 'wallabag_url',
413 'value' => '',
414 'section' => 'misc',
415 ],
416 [
417 'name' => 'piwik_enabled',
418 'value' => '0',
419 'section' => 'analytics',
420 ],
421 [
422 'name' => 'piwik_host',
423 'value' => 'v2.wallabag.org',
424 'section' => 'analytics',
425 ],
426 [
427 'name' => 'piwik_site_id',
428 'value' => '1',
429 'section' => 'analytics',
430 ],
431 [
432 'name' => 'demo_mode_enabled',
433 'value' => '0',
434 'section' => 'misc',
435 ],
436 [
437 'name' => 'demo_mode_username',
438 'value' => 'wallabag',
439 'section' => 'misc',
440 ],
441 [
442 'name' => 'download_images_enabled',
443 'value' => '0',
444 'section' => 'misc',
445 ],
446 [
447 'name' => 'restricted_access',
448 'value' => '0',
449 'section' => 'entry',
450 ],
451 ];
452
453 foreach ($settings as $setting) {
454 $newSetting = new Setting(); 296 $newSetting = new Setting();
455 $newSetting->setName($setting['name']); 297 $newSetting->setName($setting['name']);
456 $newSetting->setValue($setting['value']); 298 $newSetting->setValue($setting['value']);
diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php
index aaeb9ee9..a52288e6 100644
--- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php
+++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSettingData.php
@@ -6,173 +6,27 @@ use Doctrine\Common\DataFixtures\AbstractFixture;
6use Doctrine\Common\DataFixtures\OrderedFixtureInterface; 6use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
7use Doctrine\Common\Persistence\ObjectManager; 7use Doctrine\Common\Persistence\ObjectManager;
8use Craue\ConfigBundle\Entity\Setting; 8use Craue\ConfigBundle\Entity\Setting;
9use Symfony\Component\DependencyInjection\ContainerAwareInterface;
10use Symfony\Component\DependencyInjection\ContainerInterface;
9 11
10class LoadSettingData extends AbstractFixture implements OrderedFixtureInterface 12class LoadSettingData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
11{ 13{
12 /** 14 /**
15 * @var ContainerInterface
16 */
17 private $container;
18
19 public function setContainer(ContainerInterface $container = null)
20 {
21 $this->container = $container;
22 }
23
24 /**
13 * {@inheritdoc} 25 * {@inheritdoc}
14 */ 26 */
15 public function load(ObjectManager $manager) 27 public function load(ObjectManager $manager)
16 { 28 {
17 $settings = [ 29 foreach ($this->container->getParameter('wallabag_core.default_internal_settings') as $setting) {
18 [
19 'name' => 'share_public',
20 'value' => '1',
21 'section' => 'entry',
22 ],
23 [
24 'name' => 'carrot',
25 'value' => '1',
26 'section' => 'entry',
27 ],
28 [
29 'name' => 'share_diaspora',
30 'value' => '1',
31 'section' => 'entry',
32 ],
33 [
34 'name' => 'diaspora_url',
35 'value' => 'http://diasporapod.com',
36 'section' => 'entry',
37 ],
38 [
39 'name' => 'share_unmark',
40 'value' => '1',
41 'section' => 'entry',
42 ],
43 [
44 'name' => 'unmark_url',
45 'value' => 'https://unmark.it',
46 'section' => 'entry',
47 ],
48 [
49 'name' => 'share_shaarli',
50 'value' => '1',
51 'section' => 'entry',
52 ],
53 [
54 'name' => 'share_scuttle',
55 'value' => '1',
56 'section' => 'entry',
57 ],
58 [
59 'name' => 'shaarli_url',
60 'value' => 'http://myshaarli.com',
61 'section' => 'entry',
62 ],
63 [
64 'name' => 'scuttle_url',
65 'value' => 'http://scuttle.org',
66 'section' => 'entry',
67 ],
68 [
69 'name' => 'share_mail',
70 'value' => '1',
71 'section' => 'entry',
72 ],
73 [
74 'name' => 'share_twitter',
75 'value' => '1',
76 'section' => 'entry',
77 ],
78 [
79 'name' => 'export_epub',
80 'value' => '1',
81 'section' => 'export',
82 ],
83 [
84 'name' => 'export_mobi',
85 'value' => '1',
86 'section' => 'export',
87 ],
88 [
89 'name' => 'export_pdf',
90 'value' => '1',
91 'section' => 'export',
92 ],
93 [
94 'name' => 'export_csv',
95 'value' => '1',
96 'section' => 'export',
97 ],
98 [
99 'name' => 'export_json',
100 'value' => '1',
101 'section' => 'export',
102 ],
103 [
104 'name' => 'export_txt',
105 'value' => '1',
106 'section' => 'export',
107 ],
108 [
109 'name' => 'export_xml',
110 'value' => '1',
111 'section' => 'export',
112 ],
113 [
114 'name' => 'import_with_redis',
115 'value' => '0',
116 'section' => 'import',
117 ],
118 [
119 'name' => 'import_with_rabbitmq',
120 'value' => '0',
121 'section' => 'import',
122 ],
123 [
124 'name' => 'show_printlink',
125 'value' => '1',
126 'section' => 'entry',
127 ],
128 [
129 'name' => 'wallabag_support_url',
130 'value' => 'https://www.wallabag.org/pages/support.html',
131 'section' => 'misc',
132 ],
133 [
134 'name' => 'wallabag_url',
135 'value' => 'http://v2.wallabag.org',
136 'section' => 'misc',
137 ],
138 [
139 'name' => 'piwik_enabled',
140 'value' => '0',
141 'section' => 'analytics',
142 ],
143 [
144 'name' => 'piwik_host',
145 'value' => 'v2.wallabag.org',
146 'section' => 'analytics',
147 ],
148 [
149 'name' => 'piwik_site_id',
150 'value' => '1',
151 'section' => 'analytics',
152 ],
153 [
154 'name' => 'demo_mode_enabled',
155 'value' => '0',
156 'section' => 'misc',
157 ],
158 [
159 'name' => 'demo_mode_username',
160 'value' => 'wallabag',
161 'section' => 'misc',
162 ],
163 [
164 'name' => 'download_images_enabled',
165 'value' => '0',
166 'section' => 'misc',
167 ],
168 [
169 'name' => 'restricted_access',
170 'value' => '0',
171 'section' => 'entry',
172 ],
173 ];
174
175 foreach ($settings as $setting) {
176 $newSetting = new Setting(); 30 $newSetting = new Setting();
177 $newSetting->setName($setting['name']); 31 $newSetting->setName($setting['name']);
178 $newSetting->setValue($setting['value']); 32 $newSetting->setValue($setting['value']);
diff --git a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php
index 8b5b5744..33df92d3 100644
--- a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php
+++ b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php
@@ -52,6 +52,17 @@ class Configuration implements ConfigurationInterface
52 ->scalarNode('api_limit_mass_actions') 52 ->scalarNode('api_limit_mass_actions')
53 ->defaultValue(10) 53 ->defaultValue(10)
54 ->end() 54 ->end()
55 ->arrayNode('default_internal_settings')
56 ->prototype('array')
57 ->children()
58 ->scalarNode('name')->end()
59 ->scalarNode('value')->end()
60 ->enumNode('section')
61 ->values(['entry', 'misc', 'api', 'analytics', 'export', 'import'])
62 ->end()
63 ->end()
64 ->end()
65 ->end()
55 ->end() 66 ->end()
56 ; 67 ;
57 68
diff --git a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php
index a2a703cb..b4d8a386 100644
--- a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php
+++ b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php
@@ -28,6 +28,7 @@ class WallabagCoreExtension extends Extension
28 $container->setParameter('wallabag_core.fetching_error_message', $config['fetching_error_message']); 28 $container->setParameter('wallabag_core.fetching_error_message', $config['fetching_error_message']);
29 $container->setParameter('wallabag_core.fetching_error_message_title', $config['fetching_error_message_title']); 29 $container->setParameter('wallabag_core.fetching_error_message_title', $config['fetching_error_message_title']);
30 $container->setParameter('wallabag_core.api_limit_mass_actions', $config['api_limit_mass_actions']); 30 $container->setParameter('wallabag_core.api_limit_mass_actions', $config['api_limit_mass_actions']);
31 $container->setParameter('wallabag_core.default_internal_settings', $config['default_internal_settings']);
31 32
32 $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); 33 $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
33 $loader->load('services.yml'); 34 $loader->load('services.yml');
diff --git a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php
index 3f4969a5..5735bc58 100644
--- a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php
@@ -27,15 +27,32 @@ class UserRestControllerTest extends WallabagApiTestCase
27 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); 27 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
28 } 28 }
29 29
30 public function testGetUserWithoutAuthentication()
31 {
32 $client = static::createClient();
33 $client->request('GET', '/api/user.json');
34 $this->assertEquals(401, $client->getResponse()->getStatusCode());
35
36 $content = json_decode($client->getResponse()->getContent(), true);
37
38 $this->assertArrayHasKey('error', $content);
39 $this->assertArrayHasKey('error_description', $content);
40
41 $this->assertEquals('access_denied', $content['error']);
42
43 $this->assertEquals('application/json', $client->getResponse()->headers->get('Content-Type'));
44 }
45
30 public function testCreateNewUser() 46 public function testCreateNewUser()
31 { 47 {
48 $this->client->getContainer()->get('craue_config')->set('api_user_registration', 1);
32 $this->client->request('PUT', '/api/user.json', [ 49 $this->client->request('PUT', '/api/user.json', [
33 'username' => 'google', 50 'username' => 'google',
34 'password' => 'googlegoogle', 51 'password' => 'googlegoogle',
35 'email' => 'wallabag@google.com', 52 'email' => 'wallabag@google.com',
36 ]); 53 ]);
37 54
38 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 55 $this->assertEquals(201, $this->client->getResponse()->getStatusCode());
39 56
40 $content = json_decode($this->client->getResponse()->getContent(), true); 57 $content = json_decode($this->client->getResponse()->getContent(), true);
41 58
@@ -50,30 +67,51 @@ class UserRestControllerTest extends WallabagApiTestCase
50 67
51 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); 68 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
52 69
53 // remove the created user to avoid side effect on other tests 70 $this->client->getContainer()->get('craue_config')->set('api_user_registration', 0);
54 // @todo remove these lines when test will be isolated 71 }
55 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); 72
73 public function testCreateNewUserWithoutAuthentication()
74 {
75 // create a new client instead of using $this->client to be sure client isn't authenticated
76 $client = static::createClient();
77 $client->getContainer()->get('craue_config')->set('api_user_registration', 1);
78 $client->request('PUT', '/api/user.json', [
79 'username' => 'google',
80 'password' => 'googlegoogle',
81 'email' => 'wallabag@google.com',
82 ]);
83
84 $this->assertEquals(201, $client->getResponse()->getStatusCode());
85
86 $content = json_decode($client->getResponse()->getContent(), true);
56 87
57 $query = $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Config c WHERE c.user = :user_id'); 88 $this->assertArrayHasKey('id', $content);
58 $query->setParameter('user_id', $content['id']); 89 $this->assertArrayHasKey('email', $content);
59 $query->execute(); 90 $this->assertArrayHasKey('username', $content);
91 $this->assertArrayHasKey('created_at', $content);
92 $this->assertArrayHasKey('updated_at', $content);
60 93
61 $query = $em->createQuery('DELETE FROM Wallabag\UserBundle\Entity\User u WHERE u.id = :id'); 94 $this->assertEquals('wallabag@google.com', $content['email']);
62 $query->setParameter('id', $content['id']); 95 $this->assertEquals('google', $content['username']);
63 $query->execute(); 96
97 $this->assertEquals('application/json', $client->getResponse()->headers->get('Content-Type'));
98
99 $client->getContainer()->get('craue_config')->set('api_user_registration', 0);
64 } 100 }
65 101
66 public function testCreateNewUserWithExistingEmail() 102 public function testCreateNewUserWithExistingEmail()
67 { 103 {
68 $this->client->request('PUT', '/api/user.json', [ 104 $client = static::createClient();
105 $client->getContainer()->get('craue_config')->set('api_user_registration', 1);
106 $client->request('PUT', '/api/user.json', [
69 'username' => 'admin', 107 'username' => 'admin',
70 'password' => 'googlegoogle', 108 'password' => 'googlegoogle',
71 'email' => 'bigboss@wallabag.org', 109 'email' => 'bigboss@wallabag.org',
72 ]); 110 ]);
73 111
74 $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); 112 $this->assertEquals(400, $client->getResponse()->getStatusCode());
75 113
76 $content = json_decode($this->client->getResponse()->getContent(), true); 114 $content = json_decode($client->getResponse()->getContent(), true);
77 115
78 $this->assertArrayHasKey('error', $content); 116 $this->assertArrayHasKey('error', $content);
79 $this->assertArrayHasKey('username', $content['error']); 117 $this->assertArrayHasKey('username', $content['error']);
@@ -85,26 +123,50 @@ class UserRestControllerTest extends WallabagApiTestCase
85 $this->assertEquals('This value is already used.', $content['error']['username'][0]); 123 $this->assertEquals('This value is already used.', $content['error']['username'][0]);
86 $this->assertEquals('This value is already used.', $content['error']['email'][0]); 124 $this->assertEquals('This value is already used.', $content['error']['email'][0]);
87 125
88 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); 126 $this->assertEquals('application/json', $client->getResponse()->headers->get('Content-Type'));
127
128 $client->getContainer()->get('craue_config')->set('api_user_registration', 0);
89 } 129 }
90 130
91 public function testCreateNewUserWithTooShortPassword() 131 public function testCreateNewUserWithTooShortPassword()
92 { 132 {
93 $this->client->request('PUT', '/api/user.json', [ 133 $client = static::createClient();
134 $client->getContainer()->get('craue_config')->set('api_user_registration', 1);
135 $client->request('PUT', '/api/user.json', [
94 'username' => 'facebook', 136 'username' => 'facebook',
95 'password' => 'face', 137 'password' => 'face',
96 'email' => 'facebook@wallabag.org', 138 'email' => 'facebook@wallabag.org',
97 ]); 139 ]);
98 140
99 $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); 141 $this->assertEquals(400, $client->getResponse()->getStatusCode());
100 142
101 $content = json_decode($this->client->getResponse()->getContent(), true); 143 $content = json_decode($client->getResponse()->getContent(), true);
102 144
103 $this->assertArrayHasKey('error', $content); 145 $this->assertArrayHasKey('error', $content);
104 $this->assertArrayHasKey('password', $content['error']); 146 $this->assertArrayHasKey('password', $content['error']);
105 147
106 $this->assertEquals('validator.password_too_short', $content['error']['password'][0]); 148 $this->assertEquals('validator.password_too_short', $content['error']['password'][0]);
107 149
108 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); 150 $this->assertEquals('application/json', $client->getResponse()->headers->get('Content-Type'));
151
152 $client->getContainer()->get('craue_config')->set('api_user_registration', 0);
153 }
154
155 public function testCreateNewUserWhenRegistrationIsDisabled()
156 {
157 $client = static::createClient();
158 $client->request('PUT', '/api/user.json', [
159 'username' => 'facebook',
160 'password' => 'face',
161 'email' => 'facebook@wallabag.org',
162 ]);
163
164 $this->assertEquals(403, $client->getResponse()->getStatusCode());
165
166 $content = json_decode($client->getResponse()->getContent(), true);
167
168 $this->assertArrayHasKey('error', $content);
169
170 $this->assertEquals('application/json', $client->getResponse()->headers->get('Content-Type'));
109 } 171 }
110} 172}
diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
index c87e58de..df638e8f 100644
--- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
@@ -8,12 +8,14 @@ class WallabagRestControllerTest extends WallabagApiTestCase
8{ 8{
9 public function testGetVersion() 9 public function testGetVersion()
10 { 10 {
11 $this->client->request('GET', '/api/version'); 11 // create a new client instead of using $this->client to be sure client isn't authenticated
12 $client = static::createClient();
13 $client->request('GET', '/api/version');
12 14
13 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 15 $this->assertEquals(200, $client->getResponse()->getStatusCode());
14 16
15 $content = json_decode($this->client->getResponse()->getContent(), true); 17 $content = json_decode($client->getResponse()->getContent(), true);
16 18
17 $this->assertEquals($this->client->getContainer()->getParameter('wallabag_core.version'), $content); 19 $this->assertEquals($client->getContainer()->getParameter('wallabag_core.version'), $content);
18 } 20 }
19} 21}