diff options
author | Robin McCorkell <rmccorkell@owncloud.com> | 2016-02-08 13:16:00 +0000 |
---|---|---|
committer | Robin McCorkell <robin@mccorkell.me.uk> | 2016-05-03 11:30:02 +0100 |
commit | de98a6e54cd2d732e0b7c1297e8da43e53bb97c7 (patch) | |
tree | d181a50261fea23ee4366bb70da0f6d02c03d834 /apps/files_external | |
parent | 06293783e0d291a5595b55a3268d8bc0704277db (diff) | |
download | nextcloud-server-de98a6e54cd2d732e0b7c1297e8da43e53bb97c7.tar.gz nextcloud-server-de98a6e54cd2d732e0b7c1297e8da43e53bb97c7.zip |
Allow multiple custom JS files
Diffstat (limited to 'apps/files_external')
8 files changed, 32 insertions, 18 deletions
diff --git a/apps/files_external/lib/auth/oauth1/oauth1.php b/apps/files_external/lib/auth/oauth1/oauth1.php index dd83c9a6a69..808681530ea 100644 --- a/apps/files_external/lib/auth/oauth1/oauth1.php +++ b/apps/files_external/lib/auth/oauth1/oauth1.php @@ -46,7 +46,7 @@ class OAuth1 extends AuthMechanism { (new DefinitionParameter('token_secret', 'token_secret')) ->setType(DefinitionParameter::VALUE_HIDDEN), ]) - ->setCustomJs('oauth1') + ->addCustomJs('oauth1') ; } diff --git a/apps/files_external/lib/auth/oauth2/oauth2.php b/apps/files_external/lib/auth/oauth2/oauth2.php index c89007b52ba..d4bba8ef0eb 100644 --- a/apps/files_external/lib/auth/oauth2/oauth2.php +++ b/apps/files_external/lib/auth/oauth2/oauth2.php @@ -44,7 +44,7 @@ class OAuth2 extends AuthMechanism { (new DefinitionParameter('token', 'token')) ->setType(DefinitionParameter::VALUE_HIDDEN), ]) - ->setCustomJs('oauth2') + ->addCustomJs('oauth2') ; } diff --git a/apps/files_external/lib/auth/publickey/rsa.php b/apps/files_external/lib/auth/publickey/rsa.php index 9045f6818f9..7732beeddf8 100644 --- a/apps/files_external/lib/auth/publickey/rsa.php +++ b/apps/files_external/lib/auth/publickey/rsa.php @@ -52,7 +52,7 @@ class RSA extends AuthMechanism { (new DefinitionParameter('private_key', 'private_key')) ->setType(DefinitionParameter::VALUE_HIDDEN), ]) - ->setCustomJs('public_key') + ->addCustomJs('public_key') ; } diff --git a/apps/files_external/lib/backend/legacybackend.php b/apps/files_external/lib/backend/legacybackend.php index 084758ff78a..752c501e1ec 100644 --- a/apps/files_external/lib/backend/legacybackend.php +++ b/apps/files_external/lib/backend/legacybackend.php @@ -84,7 +84,7 @@ class LegacyBackend extends Backend { $this->setPriority($definition['priority']); } if (isset($definition['custom'])) { - $this->setCustomJs($definition['custom']); + $this->addCustomJs($definition['custom']); } if (isset($definition['has_dependencies']) && $definition['has_dependencies']) { $this->hasDependencies = true; diff --git a/apps/files_external/lib/frontenddefinitiontrait.php b/apps/files_external/lib/frontenddefinitiontrait.php index 9f2b7c40f7f..ccc2a75fd1b 100644 --- a/apps/files_external/lib/frontenddefinitiontrait.php +++ b/apps/files_external/lib/frontenddefinitiontrait.php @@ -36,8 +36,8 @@ trait FrontendDefinitionTrait { /** @var DefinitionParameter[] parameters for mechanism */ private $parameters = []; - /** @var string|null custom JS */ - private $customJs = null; + /** @var string[] custom JS */ + private $customJs = []; /** * @return string @@ -92,7 +92,7 @@ trait FrontendDefinitionTrait { } /** - * @return string|null + * @return string[] */ public function getCustomJs() { return $this->customJs; @@ -102,8 +102,18 @@ trait FrontendDefinitionTrait { * @param string $custom * @return self */ + public function addCustomJs($custom) { + $this->customJs[] = $custom; + return $this; + } + + /** + * @param string $custom + * @return self + * @deprecated 9.1.0, use addCustomJs() instead + */ public function setCustomJs($custom) { - $this->customJs = $custom; + $this->customJs = [$custom]; return $this; } @@ -121,10 +131,8 @@ trait FrontendDefinitionTrait { $data = [ 'name' => $this->getText(), 'configuration' => $configuration, + 'custom' => $this->getCustomJs(), ]; - if (isset($this->customJs)) { - $data['custom'] = $this->getCustomJs(); - } return $data; } diff --git a/apps/files_external/templates/settings.php b/apps/files_external/templates/settings.php index 7edd66fe4d5..c9cc40b0ba0 100644 --- a/apps/files_external/templates/settings.php +++ b/apps/files_external/templates/settings.php @@ -1,5 +1,6 @@ <?php use \OCA\Files_External\Lib\Backend\Backend; + use \OCA\Files_External\Lib\Auth\AuthMechanism; use \OCA\Files_External\Lib\DefinitionParameter; use \OCA\Files_External\Service\BackendService; @@ -16,13 +17,16 @@ // load custom JS foreach ($_['backends'] as $backend) { /** @var Backend $backend */ - if ($backend->getCustomJs()) { - script('files_external', $backend->getCustomJs()); + $scripts = $backend->getCustomJs(); + foreach ($scripts as $script) { + script('files_external', $script); } } foreach ($_['authMechanisms'] as $authMechanism) { - if ($authMechanism->getCustomJs()) { - script('files_external', $authMechanism->getCustomJs()); + /** @var AuthMechanism $authMechanism */ + $scripts = $authMechanism->getCustomJs(); + foreach ($scripts as $script) { + script('files_external', $script); } } diff --git a/apps/files_external/tests/backend/legacybackendtest.php b/apps/files_external/tests/backend/legacybackendtest.php index d825b7627b7..465b79a6be6 100644 --- a/apps/files_external/tests/backend/legacybackendtest.php +++ b/apps/files_external/tests/backend/legacybackendtest.php @@ -62,7 +62,7 @@ class LegacyBackendTest extends \Test\TestCase { $this->assertEquals('\OCA\Files_External\Tests\Backend\LegacyBackendTest', $backend->getStorageClass()); $this->assertEquals('Backend text', $backend->getText()); $this->assertEquals(123, $backend->getPriority()); - $this->assertEquals('foo/bar.js', $backend->getCustomJs()); + $this->assertContains('foo/bar.js', $backend->getCustomJs()); $this->assertArrayHasKey('builtin', $backend->getAuthSchemes()); $this->assertEquals($auth, $backend->getLegacyAuthMechanism()); diff --git a/apps/files_external/tests/frontenddefinitiontraittest.php b/apps/files_external/tests/frontenddefinitiontraittest.php index 2afc87762e9..b3846fa1510 100644 --- a/apps/files_external/tests/frontenddefinitiontraittest.php +++ b/apps/files_external/tests/frontenddefinitiontraittest.php @@ -33,12 +33,14 @@ class FrontendDefinitionTraitTest extends \Test\TestCase { $trait = $this->getMockForTrait('\OCA\Files_External\Lib\FrontendDefinitionTrait'); $trait->setText('test'); $trait->addParameters([$param]); - $trait->setCustomJs('foo/bar.js'); + $trait->addCustomJs('foo/bar.js'); + $trait->addCustomJs('bar/foo.js'); $json = $trait->jsonSerializeDefinition(); $this->assertEquals('test', $json['name']); - $this->assertEquals('foo/bar.js', $json['custom']); + $this->assertContains('foo/bar.js', $json['custom']); + $this->assertContains('bar/foo.js', $json['custom']); $configuration = $json['configuration']; $this->assertArrayHasKey('foo', $configuration); |