From 0b16fd577eddf9145ca8d647e432d30ce629ca61 Mon Sep 17 00:00:00 2001 From: Xavier Rousset Date: Tue, 27 Sep 2016 12:24:03 +0200 Subject: [PATCH 1/7] PHRAS-1234 Change wording on setup template --- templates/web/admin/setup.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/web/admin/setup.html.twig b/templates/web/admin/setup.html.twig index e6f2261e19..a3b5d671ca 100644 --- a/templates/web/admin/setup.html.twig +++ b/templates/web/admin/setup.html.twig @@ -4,7 +4,7 @@
- +
From 9c4b3b7429fa9c416e21b8e8be6b515a189173dc Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Wed, 28 Sep 2016 18:40:26 +0200 Subject: [PATCH 2/7] PHRAS-1245 Preserve gitkeep file --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index c490fe30f0..52a2f92d70 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ clean_assets: rm -rf ./node_modules rm -rf ./www/assets rm -rf ./www/bower_components + touch ./node_modules/.gitkeep config: @php bin/console compile:configuration From c13e0861203ad61422eaf62df46db86dcadd60fd Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Mon, 26 Sep 2016 17:32:44 +0200 Subject: [PATCH 3/7] Add option to disable API via configuration setting --- config/configuration.sample.yml | 1 + lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php | 8 ++++++++ lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php | 8 ++++++++ lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php | 8 ++++++++ 4 files changed, 25 insertions(+) diff --git a/config/configuration.sample.yml b/config/configuration.sample.yml index 05b94d7c68..44dead3020 100644 --- a/config/configuration.sample.yml +++ b/config/configuration.sample.yml @@ -6,6 +6,7 @@ main: maintenance: false languages: [] key: '' + api_disable: false api_require_ssl: true api_disabled: true database: diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php index 21a344ed75..5977043b44 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php @@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Api; use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Controller\Api\OAuth2Controller; +use Alchemy\Phrasea\Core\Configuration\PropertyAccess; use Silex\Application; use Silex\ControllerCollection; use Silex\ControllerProviderInterface; @@ -34,6 +35,13 @@ class OAuth2 implements ControllerProviderInterface, ServiceProviderInterface public function connect(Application $app) { + /** @var PropertyAccess $config */ + $config = $app['conf']; + + if ($config->get('api_disable', false) == true) { + return $app['controllers_factory']; + } + /** @var ControllerCollection $controllers */ $controllers = $app['controllers_factory']; diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php index d179c68d96..3136a1488f 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php @@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Api; use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Controller\Api\V1Controller; use Alchemy\Phrasea\Controller\LazyLocator; +use Alchemy\Phrasea\Core\Configuration\PropertyAccess; use Alchemy\Phrasea\Core\Event\Listener\OAuthListener; use Silex\Application; use Silex\ControllerCollection; @@ -46,6 +47,13 @@ class V1 implements ControllerProviderInterface, ServiceProviderInterface public function connect(Application $app) { + /** @var PropertyAccess $config */ + $config = $app['conf']; + + if ($config->get('api_disable', false) == true) { + return $app['controllers_factory']; + } + /** @var ControllerCollection $controllers */ $controllers = $app['controllers_factory']; diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php index 7068e6c7ac..124f5c03b6 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php @@ -15,6 +15,7 @@ use Alchemy\Phrasea\Controller\Api\LazaretController; use Alchemy\Phrasea\Controller\Api\SearchController; use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; +use Alchemy\Phrasea\Core\Configuration\PropertyAccess; use Alchemy\Phrasea\Core\Event\Listener\OAuthListener; use Alchemy\Phrasea\Order\Controller\ApiOrderController; use Silex\Application; @@ -70,6 +71,13 @@ class V2 implements ControllerProviderInterface, ServiceProviderInterface public function connect(Application $app) { + /** @var PropertyAccess $config */ + $config = $app['conf']; + + if ($config->get('api_disable', false) == true) { + return $app['controllers_factory']; + } + $controllers = $this->createCollection($app); $controllers->before(new OAuthListener()); From 5666286e3377bbe9e04e4b1fb6d6ee2037df4151 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Tue, 27 Sep 2016 11:30:49 +0200 Subject: [PATCH 4/7] Fix typo in api_disable param name --- config/configuration.sample.yml | 3 +-- lib/conf.d/configuration.yml | 2 +- resources/ansible/roles/app/tasks/main.yml | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/config/configuration.sample.yml b/config/configuration.sample.yml index 44dead3020..17e8729509 100644 --- a/config/configuration.sample.yml +++ b/config/configuration.sample.yml @@ -6,9 +6,8 @@ main: maintenance: false languages: [] key: '' - api_disable: false + api_disable: true api_require_ssl: true - api_disabled: true database: host: 127.0.0.1 port: 3306 diff --git a/lib/conf.d/configuration.yml b/lib/conf.d/configuration.yml index 36d248db03..fb6b300c28 100644 --- a/lib/conf.d/configuration.yml +++ b/lib/conf.d/configuration.yml @@ -6,7 +6,7 @@ main: maintenance: false key: '' api_require_ssl: true - api_disabled: true + api_disable: true database: host: 'sql-host' port: 3306 diff --git a/resources/ansible/roles/app/tasks/main.yml b/resources/ansible/roles/app/tasks/main.yml index 9c0d497bd6..9be09a9412 100644 --- a/resources/ansible/roles/app/tasks/main.yml +++ b/resources/ansible/roles/app/tasks/main.yml @@ -48,7 +48,7 @@ chdir: /vagrant/ - name: Enable API routes - shell: bin/setup system:config set main.api_disabled false + shell: bin/setup system:config set main.api_disable false args: chdir: /vagrant/ From 7cf5d28a990a16b14bbda4182b15e9d6754d2008 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Tue, 27 Sep 2016 11:38:29 +0200 Subject: [PATCH 5/7] Fix configuration setting access --- lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php | 2 +- lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php | 2 +- lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php index 5977043b44..17a78e6ded 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php @@ -38,7 +38,7 @@ class OAuth2 implements ControllerProviderInterface, ServiceProviderInterface /** @var PropertyAccess $config */ $config = $app['conf']; - if ($config->get('api_disable', false) == true) { + if ($config->get([ 'main', 'api_disable' ], false) == true) { return $app['controllers_factory']; } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php index 3136a1488f..917d9ee0df 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php @@ -50,7 +50,7 @@ class V1 implements ControllerProviderInterface, ServiceProviderInterface /** @var PropertyAccess $config */ $config = $app['conf']; - if ($config->get('api_disable', false) == true) { + if ($config->get([ 'main', 'api_disable' ], false) == true) { return $app['controllers_factory']; } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php index 124f5c03b6..9d5e803646 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php @@ -74,7 +74,7 @@ class V2 implements ControllerProviderInterface, ServiceProviderInterface /** @var PropertyAccess $config */ $config = $app['conf']; - if ($config->get('api_disable', false) == true) { + if ($config->get([ 'main', 'api_disable' ], false) == true) { return $app['controllers_factory']; } From f62c22bc5ca5995968134afa712e2eec5131e5d4 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Wed, 28 Sep 2016 20:58:26 +0200 Subject: [PATCH 6/7] Move setting to registry and form type --- config/configuration.sample.yml | 1 - .../Controller/Admin/SetupController.php | 7 ++++++- .../Phrasea/ControllerProvider/Api/Api.php | 18 ++++++++++++++++++ .../Phrasea/ControllerProvider/Api/OAuth2.php | 7 ++----- .../Phrasea/ControllerProvider/Api/V1.php | 7 ++----- .../Phrasea/ControllerProvider/Api/V2.php | 7 ++----- .../Core/Configuration/RegistryManipulator.php | 17 +++++++++++++++++ .../Form/Configuration/APIClientsFormType.php | 5 +++++ lib/conf.d/configuration.yml | 1 - resources/ansible/roles/app/tasks/main.yml | 2 +- .../puphpet/.gitattributes | 10 ---------- 11 files changed, 53 insertions(+), 29 deletions(-) create mode 100644 lib/Alchemy/Phrasea/ControllerProvider/Api/Api.php delete mode 100644 resources/vagrant/vms/phraseanet-php55-nginx/puphpet/.gitattributes diff --git a/config/configuration.sample.yml b/config/configuration.sample.yml index 17e8729509..19bd3242d2 100644 --- a/config/configuration.sample.yml +++ b/config/configuration.sample.yml @@ -6,7 +6,6 @@ main: maintenance: false languages: [] key: '' - api_disable: true api_require_ssl: true database: host: 127.0.0.1 diff --git a/lib/Alchemy/Phrasea/Controller/Admin/SetupController.php b/lib/Alchemy/Phrasea/Controller/Admin/SetupController.php index 88b0918436..a3738d8e91 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/SetupController.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/SetupController.php @@ -11,6 +11,8 @@ namespace Alchemy\Phrasea\Controller\Admin; use Alchemy\Phrasea\Controller\Controller; +use Alchemy\Phrasea\Core\Configuration\Configuration; +use Alchemy\Phrasea\Core\Configuration\PropertyAccess; use Alchemy\Phrasea\Core\Configuration\RegistryManipulator; use Symfony\Component\HttpFoundation\Request; @@ -20,12 +22,15 @@ class SetupController extends Controller { /** @var RegistryManipulator $manipulator */ $manipulator = $this->app['registry.manipulator']; + /** @var PropertyAccess $config */ + $config = $this->app['conf']; + $form = $manipulator->createForm($this->app['conf']); if ('POST' === $request->getMethod()) { $form->submit($request->request->all()); if ($form->isValid()) { - $this->app['conf']->set('registry', $manipulator->getRegistryData($form)); + $config->set('registry', $manipulator->getRegistryData($form)); return $this->app->redirectPath('setup_display_globals'); } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/Api.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/Api.php new file mode 100644 index 0000000000..eccc9a0f3d --- /dev/null +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/Api.php @@ -0,0 +1,18 @@ +get([ 'registry', 'api-clients', 'api-enabled' ], true) == true; + } +} diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php index 17a78e6ded..d22c385d88 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/OAuth2.php @@ -19,7 +19,7 @@ use Silex\ControllerCollection; use Silex\ControllerProviderInterface; use Silex\ServiceProviderInterface; -class OAuth2 implements ControllerProviderInterface, ServiceProviderInterface +class OAuth2 extends Api implements ControllerProviderInterface, ServiceProviderInterface { public function register(Application $app) { @@ -35,10 +35,7 @@ class OAuth2 implements ControllerProviderInterface, ServiceProviderInterface public function connect(Application $app) { - /** @var PropertyAccess $config */ - $config = $app['conf']; - - if ($config->get([ 'main', 'api_disable' ], false) == true) { + if (! $this->isApiEnabled($app)) { return $app['controllers_factory']; } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php index 917d9ee0df..bd2731a0a4 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php @@ -21,7 +21,7 @@ use Silex\ControllerCollection; use Silex\ControllerProviderInterface; use Silex\ServiceProviderInterface; -class V1 implements ControllerProviderInterface, ServiceProviderInterface +class V1 extends Api implements ControllerProviderInterface, ServiceProviderInterface { const VERSION = '1.5.0'; @@ -47,10 +47,7 @@ class V1 implements ControllerProviderInterface, ServiceProviderInterface public function connect(Application $app) { - /** @var PropertyAccess $config */ - $config = $app['conf']; - - if ($config->get([ 'main', 'api_disable' ], false) == true) { + if (! $this->isApiEnabled($app)) { return $app['controllers_factory']; } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php index 9d5e803646..53eee150b5 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php @@ -23,7 +23,7 @@ use Silex\Controller; use Silex\ControllerProviderInterface; use Silex\ServiceProviderInterface; -class V2 implements ControllerProviderInterface, ServiceProviderInterface +class V2 extends Api implements ControllerProviderInterface, ServiceProviderInterface { use ControllerProviderTrait; @@ -71,10 +71,7 @@ class V2 implements ControllerProviderInterface, ServiceProviderInterface public function connect(Application $app) { - /** @var PropertyAccess $config */ - $config = $app['conf']; - - if ($config->get([ 'main', 'api_disable' ], false) == true) { + if (! $this->isApiEnabled($app)) { return $app['controllers_factory']; } diff --git a/lib/Alchemy/Phrasea/Core/Configuration/RegistryManipulator.php b/lib/Alchemy/Phrasea/Core/Configuration/RegistryManipulator.php index fc65b7fa4a..a8a73423c9 100644 --- a/lib/Alchemy/Phrasea/Core/Configuration/RegistryManipulator.php +++ b/lib/Alchemy/Phrasea/Core/Configuration/RegistryManipulator.php @@ -19,10 +19,26 @@ use Symfony\Component\Translation\TranslatorInterface; class RegistryManipulator { + /** + * @var FormFactoryInterface + */ private $factory; + + /** + * @var array + */ private $languages; + + /** + * @var TranslatorInterface + */ private $translator; + /** + * @param FormFactoryInterface $factory + * @param TranslatorInterface $translator + * @param array $languages + */ public function __construct(FormFactoryInterface $factory, TranslatorInterface $translator, array $languages) { $this->factory = $factory; @@ -128,6 +144,7 @@ class RegistryManipulator 'enabled' => false, ], 'api-clients' => [ + 'api-enabled' => true, 'navigator-enabled' => true, 'office-enabled' => true, ], diff --git a/lib/Alchemy/Phrasea/Form/Configuration/APIClientsFormType.php b/lib/Alchemy/Phrasea/Form/Configuration/APIClientsFormType.php index 27194c264e..21b9f8586c 100644 --- a/lib/Alchemy/Phrasea/Form/Configuration/APIClientsFormType.php +++ b/lib/Alchemy/Phrasea/Form/Configuration/APIClientsFormType.php @@ -18,6 +18,11 @@ class APIClientsFormType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { + $builder->add('api-enabled', 'checkbox', [ + 'label' => 'Enable Phraseanet Web API', + 'help_message' => 'The Phraseanet Web API allows other web application to rely on this instance' + ]); + $builder->add('navigator-enabled', 'checkbox', [ 'label' => 'Authorize *Phraseanet Navigator*', 'help_message' => '*Phraseanet Navigator* is a smartphone application that allow user to connect on this instance', diff --git a/lib/conf.d/configuration.yml b/lib/conf.d/configuration.yml index fb6b300c28..27eb933247 100644 --- a/lib/conf.d/configuration.yml +++ b/lib/conf.d/configuration.yml @@ -6,7 +6,6 @@ main: maintenance: false key: '' api_require_ssl: true - api_disable: true database: host: 'sql-host' port: 3306 diff --git a/resources/ansible/roles/app/tasks/main.yml b/resources/ansible/roles/app/tasks/main.yml index 9be09a9412..d7fe461a52 100644 --- a/resources/ansible/roles/app/tasks/main.yml +++ b/resources/ansible/roles/app/tasks/main.yml @@ -48,7 +48,7 @@ chdir: /vagrant/ - name: Enable API routes - shell: bin/setup system:config set main.api_disable false + shell: bin/setup system:config set registry.api-clients.api-enable true args: chdir: /vagrant/ diff --git a/resources/vagrant/vms/phraseanet-php55-nginx/puphpet/.gitattributes b/resources/vagrant/vms/phraseanet-php55-nginx/puphpet/.gitattributes deleted file mode 100644 index 93f9975f88..0000000000 --- a/resources/vagrant/vms/phraseanet-php55-nginx/puphpet/.gitattributes +++ /dev/null @@ -1,10 +0,0 @@ -# Autodetect text files -* text=auto - -# Force the following filetypes to have unix eols, so Windows does not break them -*.pp text eol=lf -*.sh text eol=lf -*.yaml text eol=lf -Puppetfile text eol=lf -.bash_aliases text eol=lf -.vimrc text eol=lf From 8f99a69add4d34d0fc3f48cac39d4fd62827e452 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Wed, 28 Sep 2016 21:46:23 +0200 Subject: [PATCH 7/7] Fix spaces in Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 52a2f92d70..811621668d 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ clean_assets: rm -rf ./node_modules rm -rf ./www/assets rm -rf ./www/bower_components - touch ./node_modules/.gitkeep + touch ./node_modules/.gitkeep config: @php bin/console compile:configuration