From 8526bbb347a7b1ea18b225b4dda40029534636db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Tue, 7 Jun 2016 16:53:16 +0200 Subject: [PATCH 1/4] Add support to know where the storage test comes from --- apps/files_external/js/settings.js | 5 ++++- apps/files_external/js/statusmanager.js | 1 + .../lib/Controller/GlobalStoragesController.php | 5 +++-- .../files_external/lib/Controller/StoragesController.php | 9 +++++---- .../lib/Controller/UserGlobalStoragesController.php | 7 ++++--- .../lib/Controller/UserStoragesController.php | 9 +++++---- apps/files_external/lib/config.php | 4 ++-- 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js index 8d2cb52d67..4d5a08a5de 100644 --- a/apps/files_external/js/settings.js +++ b/apps/files_external/js/settings.js @@ -299,7 +299,8 @@ StorageConfig.prototype = { mountPoint: this.mountPoint, backend: this.backend, authMechanism: this.authMechanism, - backendOptions: this.backendOptions + backendOptions: this.backendOptions, + origin: 'settings' }; if (this.id) { data.id = this.id; @@ -326,6 +327,7 @@ StorageConfig.prototype = { $.ajax({ type: 'GET', url: OC.generateUrl(this._url + '/{id}', {id: this.id}), + data: {'origin': 'settings'}, success: options.success, error: options.error }); @@ -908,6 +910,7 @@ MountConfigListView.prototype = _.extend({ $.ajax({ type: 'GET', url: OC.generateUrl('apps/files_external/userglobalstorages'), + data: {'origin' : 'settings'}, contentType: 'application/json', success: function(result) { var onCompletion = jQuery.Deferred(); diff --git a/apps/files_external/js/statusmanager.js b/apps/files_external/js/statusmanager.js index 118ec17d24..57acc562de 100644 --- a/apps/files_external/js/statusmanager.js +++ b/apps/files_external/js/statusmanager.js @@ -78,6 +78,7 @@ OCA.External.StatusManager = { defObj = $.ajax({ type: 'GET', url: OC.webroot + '/index.php/apps/files_external/' + ((mountData.type === 'personal') ? 'userstorages' : 'userglobalstorages') + '/' + mountData.id, + data: {'origin' : 'statusmanager'}, success: function (response) { if (response && response.status === 0) { self.mountStatus[mountData.mount_point] = response; diff --git a/apps/files_external/lib/Controller/GlobalStoragesController.php b/apps/files_external/lib/Controller/GlobalStoragesController.php index 6f9278ce6f..af71a4831c 100644 --- a/apps/files_external/lib/Controller/GlobalStoragesController.php +++ b/apps/files_external/lib/Controller/GlobalStoragesController.php @@ -139,7 +139,8 @@ class GlobalStoragesController extends StoragesController { $mountOptions, $applicableUsers, $applicableGroups, - $priority + $priority, + $origin = null ) { $storage = $this->createStorage( $mountPoint, @@ -172,7 +173,7 @@ class GlobalStoragesController extends StoragesController { ); } - $this->updateStorageStatus($storage); + $this->updateStorageStatus($storage, $origin); return new DataResponse( $storage, diff --git a/apps/files_external/lib/Controller/StoragesController.php b/apps/files_external/lib/Controller/StoragesController.php index aa6a04ecb8..213518ff4a 100644 --- a/apps/files_external/lib/Controller/StoragesController.php +++ b/apps/files_external/lib/Controller/StoragesController.php @@ -238,7 +238,7 @@ abstract class StoragesController extends Controller { * * @param StorageConfig $storage storage configuration */ - protected function updateStorageStatus(StorageConfig &$storage) { + protected function updateStorageStatus(StorageConfig &$storage, $origin = null) { try { $this->manipulateStorageConfig($storage); @@ -249,7 +249,8 @@ abstract class StoragesController extends Controller { \OC_Mount_Config::getBackendStatus( $backend->getStorageClass(), $storage->getBackendOptions(), - false + false, + $origin ) ); } catch (InsufficientDataForMeaningfulAnswerException $e) { @@ -293,11 +294,11 @@ abstract class StoragesController extends Controller { * * @return DataResponse */ - public function show($id) { + public function show($id, $origin = null) { try { $storage = $this->service->getStorage($id); - $this->updateStorageStatus($storage); + $this->updateStorageStatus($storage, $origin); } catch (NotFoundException $e) { return new DataResponse( [ diff --git a/apps/files_external/lib/Controller/UserGlobalStoragesController.php b/apps/files_external/lib/Controller/UserGlobalStoragesController.php index 1c94a1e963..5050962a52 100644 --- a/apps/files_external/lib/Controller/UserGlobalStoragesController.php +++ b/apps/files_external/lib/Controller/UserGlobalStoragesController.php @@ -111,11 +111,11 @@ class UserGlobalStoragesController extends StoragesController { * * @NoAdminRequired */ - public function show($id) { + public function show($id, $origin = null) { try { $storage = $this->service->getStorage($id); - $this->updateStorageStatus($storage); + $this->updateStorageStatus($storage, $origin); } catch (NotFoundException $e) { return new DataResponse( [ @@ -146,7 +146,8 @@ class UserGlobalStoragesController extends StoragesController { */ public function update( $id, - $backendOptions + $backendOptions, + $origin = null ) { try { $storage = $this->service->getStorage($id); diff --git a/apps/files_external/lib/Controller/UserStoragesController.php b/apps/files_external/lib/Controller/UserStoragesController.php index 936da7ec5e..73f7178b14 100644 --- a/apps/files_external/lib/Controller/UserStoragesController.php +++ b/apps/files_external/lib/Controller/UserStoragesController.php @@ -101,8 +101,8 @@ class UserStoragesController extends StoragesController { * * {@inheritdoc} */ - public function show($id) { - return parent::show($id); + public function show($id, $origin = null) { + return parent::show($id, $origin); } /** @@ -170,7 +170,8 @@ class UserStoragesController extends StoragesController { $backend, $authMechanism, $backendOptions, - $mountOptions + $mountOptions, + $origin = null ) { $storage = $this->createStorage( $mountPoint, @@ -200,7 +201,7 @@ class UserStoragesController extends StoragesController { ); } - $this->updateStorageStatus($storage); + $this->updateStorageStatus($storage, $origin); return new DataResponse( $storage, diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 86aafcf577..51d6244978 100644 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -215,7 +215,7 @@ class OC_Mount_Config { * @return int see self::STATUS_* * @throws Exception */ - public static function getBackendStatus($class, $options, $isPersonal) { + public static function getBackendStatus($class, $options, $isPersonal, $origin = null) { if (self::$skipTest) { return StorageNotAvailableException::STATUS_SUCCESS; } @@ -228,7 +228,7 @@ class OC_Mount_Config { $storage = new $class($options); try { - $result = $storage->test($isPersonal); + $result = $storage->test($isPersonal, $origin); $storage->setAvailability($result); if ($result) { return StorageNotAvailableException::STATUS_SUCCESS; From 110edd3d3ca37d496b54c651ab049cbaab503423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Tue, 7 Jun 2016 18:25:17 +0200 Subject: [PATCH 2/4] Rename variable --- apps/files_external/js/settings.js | 6 +++--- apps/files_external/js/statusmanager.js | 2 +- .../lib/Controller/GlobalStoragesController.php | 4 ++-- apps/files_external/lib/Controller/StoragesController.php | 8 ++++---- .../lib/Controller/UserGlobalStoragesController.php | 8 ++++---- .../lib/Controller/UserStoragesController.php | 8 ++++---- apps/files_external/lib/config.php | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js index 4d5a08a5de..2477f513db 100644 --- a/apps/files_external/js/settings.js +++ b/apps/files_external/js/settings.js @@ -300,7 +300,7 @@ StorageConfig.prototype = { backend: this.backend, authMechanism: this.authMechanism, backendOptions: this.backendOptions, - origin: 'settings' + testOnly: true }; if (this.id) { data.id = this.id; @@ -327,7 +327,7 @@ StorageConfig.prototype = { $.ajax({ type: 'GET', url: OC.generateUrl(this._url + '/{id}', {id: this.id}), - data: {'origin': 'settings'}, + data: {'testOnly': true}, success: options.success, error: options.error }); @@ -910,7 +910,7 @@ MountConfigListView.prototype = _.extend({ $.ajax({ type: 'GET', url: OC.generateUrl('apps/files_external/userglobalstorages'), - data: {'origin' : 'settings'}, + data: {'testOnly' : true}, contentType: 'application/json', success: function(result) { var onCompletion = jQuery.Deferred(); diff --git a/apps/files_external/js/statusmanager.js b/apps/files_external/js/statusmanager.js index 57acc562de..91974f2d04 100644 --- a/apps/files_external/js/statusmanager.js +++ b/apps/files_external/js/statusmanager.js @@ -78,7 +78,7 @@ OCA.External.StatusManager = { defObj = $.ajax({ type: 'GET', url: OC.webroot + '/index.php/apps/files_external/' + ((mountData.type === 'personal') ? 'userstorages' : 'userglobalstorages') + '/' + mountData.id, - data: {'origin' : 'statusmanager'}, + data: {'testOnly' : false}, success: function (response) { if (response && response.status === 0) { self.mountStatus[mountData.mount_point] = response; diff --git a/apps/files_external/lib/Controller/GlobalStoragesController.php b/apps/files_external/lib/Controller/GlobalStoragesController.php index af71a4831c..e606bacd8c 100644 --- a/apps/files_external/lib/Controller/GlobalStoragesController.php +++ b/apps/files_external/lib/Controller/GlobalStoragesController.php @@ -140,7 +140,7 @@ class GlobalStoragesController extends StoragesController { $applicableUsers, $applicableGroups, $priority, - $origin = null + $testOnly = null ) { $storage = $this->createStorage( $mountPoint, @@ -173,7 +173,7 @@ class GlobalStoragesController extends StoragesController { ); } - $this->updateStorageStatus($storage, $origin); + $this->updateStorageStatus($storage, $testOnly); return new DataResponse( $storage, diff --git a/apps/files_external/lib/Controller/StoragesController.php b/apps/files_external/lib/Controller/StoragesController.php index 213518ff4a..8eb5506d53 100644 --- a/apps/files_external/lib/Controller/StoragesController.php +++ b/apps/files_external/lib/Controller/StoragesController.php @@ -238,7 +238,7 @@ abstract class StoragesController extends Controller { * * @param StorageConfig $storage storage configuration */ - protected function updateStorageStatus(StorageConfig &$storage, $origin = null) { + protected function updateStorageStatus(StorageConfig &$storage, $testOnly = null) { try { $this->manipulateStorageConfig($storage); @@ -250,7 +250,7 @@ abstract class StoragesController extends Controller { $backend->getStorageClass(), $storage->getBackendOptions(), false, - $origin + $testOnly ) ); } catch (InsufficientDataForMeaningfulAnswerException $e) { @@ -294,11 +294,11 @@ abstract class StoragesController extends Controller { * * @return DataResponse */ - public function show($id, $origin = null) { + public function show($id, $testOnly = null) { try { $storage = $this->service->getStorage($id); - $this->updateStorageStatus($storage, $origin); + $this->updateStorageStatus($storage, $testOnly); } catch (NotFoundException $e) { return new DataResponse( [ diff --git a/apps/files_external/lib/Controller/UserGlobalStoragesController.php b/apps/files_external/lib/Controller/UserGlobalStoragesController.php index 5050962a52..8376a00559 100644 --- a/apps/files_external/lib/Controller/UserGlobalStoragesController.php +++ b/apps/files_external/lib/Controller/UserGlobalStoragesController.php @@ -111,11 +111,11 @@ class UserGlobalStoragesController extends StoragesController { * * @NoAdminRequired */ - public function show($id, $origin = null) { + public function show($id, $testOnly = null) { try { $storage = $this->service->getStorage($id); - $this->updateStorageStatus($storage, $origin); + $this->updateStorageStatus($storage, $testOnly); } catch (NotFoundException $e) { return new DataResponse( [ @@ -147,7 +147,7 @@ class UserGlobalStoragesController extends StoragesController { public function update( $id, $backendOptions, - $origin = null + $testOnly = null ) { try { $storage = $this->service->getStorage($id); @@ -172,7 +172,7 @@ class UserGlobalStoragesController extends StoragesController { ); } - $this->updateStorageStatus($storage); + $this->updateStorageStatus($storage, $testOnly); $this->sanitizeStorage($storage); return new DataResponse( diff --git a/apps/files_external/lib/Controller/UserStoragesController.php b/apps/files_external/lib/Controller/UserStoragesController.php index 73f7178b14..ca949df8a0 100644 --- a/apps/files_external/lib/Controller/UserStoragesController.php +++ b/apps/files_external/lib/Controller/UserStoragesController.php @@ -101,8 +101,8 @@ class UserStoragesController extends StoragesController { * * {@inheritdoc} */ - public function show($id, $origin = null) { - return parent::show($id, $origin); + public function show($id, $testOnly = null) { + return parent::show($id, $testOnly); } /** @@ -171,7 +171,7 @@ class UserStoragesController extends StoragesController { $authMechanism, $backendOptions, $mountOptions, - $origin = null + $testOnly = null ) { $storage = $this->createStorage( $mountPoint, @@ -201,7 +201,7 @@ class UserStoragesController extends StoragesController { ); } - $this->updateStorageStatus($storage, $origin); + $this->updateStorageStatus($storage, $testOnly); return new DataResponse( $storage, diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 51d6244978..95220f86cf 100644 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -215,7 +215,7 @@ class OC_Mount_Config { * @return int see self::STATUS_* * @throws Exception */ - public static function getBackendStatus($class, $options, $isPersonal, $origin = null) { + public static function getBackendStatus($class, $options, $isPersonal, $testOnly = null) { if (self::$skipTest) { return StorageNotAvailableException::STATUS_SUCCESS; } @@ -228,7 +228,7 @@ class OC_Mount_Config { $storage = new $class($options); try { - $result = $storage->test($isPersonal, $origin); + $result = $storage->test($isPersonal, $testOnly); $storage->setAvailability($result); if ($result) { return StorageNotAvailableException::STATUS_SUCCESS; From a2b00582bc4708eded399091b4aa3f851cada3a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Tue, 7 Jun 2016 18:27:10 +0200 Subject: [PATCH 3/4] Fix test --- apps/files_external/tests/js/settingsSpec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/files_external/tests/js/settingsSpec.js b/apps/files_external/tests/js/settingsSpec.js index 7aa49b2c82..8f01c16b38 100644 --- a/apps/files_external/tests/js/settingsSpec.js +++ b/apps/files_external/tests/js/settingsSpec.js @@ -223,7 +223,8 @@ describe('OCA.External.Settings tests', function() { applicableGroups: [], mountOptions: { 'previews': true - } + }, + testOnly: true }); // TODO: respond and check data-id From 7d85bed1fc18af55fa29a3740aacf333273eced2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Wed, 8 Jun 2016 12:48:33 +0200 Subject: [PATCH 4/4] Change the default value to true instead of null --- .../lib/Controller/GlobalStoragesController.php | 2 +- apps/files_external/lib/Controller/StoragesController.php | 4 ++-- .../lib/Controller/UserGlobalStoragesController.php | 4 ++-- apps/files_external/lib/Controller/UserStoragesController.php | 4 ++-- apps/files_external/lib/config.php | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/files_external/lib/Controller/GlobalStoragesController.php b/apps/files_external/lib/Controller/GlobalStoragesController.php index e606bacd8c..471e3b5159 100644 --- a/apps/files_external/lib/Controller/GlobalStoragesController.php +++ b/apps/files_external/lib/Controller/GlobalStoragesController.php @@ -140,7 +140,7 @@ class GlobalStoragesController extends StoragesController { $applicableUsers, $applicableGroups, $priority, - $testOnly = null + $testOnly = true ) { $storage = $this->createStorage( $mountPoint, diff --git a/apps/files_external/lib/Controller/StoragesController.php b/apps/files_external/lib/Controller/StoragesController.php index 8eb5506d53..e50426f488 100644 --- a/apps/files_external/lib/Controller/StoragesController.php +++ b/apps/files_external/lib/Controller/StoragesController.php @@ -238,7 +238,7 @@ abstract class StoragesController extends Controller { * * @param StorageConfig $storage storage configuration */ - protected function updateStorageStatus(StorageConfig &$storage, $testOnly = null) { + protected function updateStorageStatus(StorageConfig &$storage, $testOnly = true) { try { $this->manipulateStorageConfig($storage); @@ -294,7 +294,7 @@ abstract class StoragesController extends Controller { * * @return DataResponse */ - public function show($id, $testOnly = null) { + public function show($id, $testOnly = true) { try { $storage = $this->service->getStorage($id); diff --git a/apps/files_external/lib/Controller/UserGlobalStoragesController.php b/apps/files_external/lib/Controller/UserGlobalStoragesController.php index 8376a00559..f65e578507 100644 --- a/apps/files_external/lib/Controller/UserGlobalStoragesController.php +++ b/apps/files_external/lib/Controller/UserGlobalStoragesController.php @@ -111,7 +111,7 @@ class UserGlobalStoragesController extends StoragesController { * * @NoAdminRequired */ - public function show($id, $testOnly = null) { + public function show($id, $testOnly = true) { try { $storage = $this->service->getStorage($id); @@ -147,7 +147,7 @@ class UserGlobalStoragesController extends StoragesController { public function update( $id, $backendOptions, - $testOnly = null + $testOnly = true ) { try { $storage = $this->service->getStorage($id); diff --git a/apps/files_external/lib/Controller/UserStoragesController.php b/apps/files_external/lib/Controller/UserStoragesController.php index ca949df8a0..28663090e8 100644 --- a/apps/files_external/lib/Controller/UserStoragesController.php +++ b/apps/files_external/lib/Controller/UserStoragesController.php @@ -101,7 +101,7 @@ class UserStoragesController extends StoragesController { * * {@inheritdoc} */ - public function show($id, $testOnly = null) { + public function show($id, $testOnly = true) { return parent::show($id, $testOnly); } @@ -171,7 +171,7 @@ class UserStoragesController extends StoragesController { $authMechanism, $backendOptions, $mountOptions, - $testOnly = null + $testOnly = true ) { $storage = $this->createStorage( $mountPoint, diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 95220f86cf..3510b675d4 100644 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -215,7 +215,7 @@ class OC_Mount_Config { * @return int see self::STATUS_* * @throws Exception */ - public static function getBackendStatus($class, $options, $isPersonal, $testOnly = null) { + public static function getBackendStatus($class, $options, $isPersonal, $testOnly = true) { if (self::$skipTest) { return StorageNotAvailableException::STATUS_SUCCESS; }