diff --git a/apps/files_external/css/settings.css b/apps/files_external/css/settings.css index 9338b8d3ee..6dfb012b15 100644 --- a/apps/files_external/css/settings.css +++ b/apps/files_external/css/settings.css @@ -18,6 +18,11 @@ td.mountPoint, td.backend { width:160px; } #addMountPoint>td.applicable { visibility:hidden; } #addMountPoint>td.hidden { visibility:hidden; } +#externalStorage .icon-settings { + padding: 11px 20px; + vertical-align: text-bottom; +} + #selectBackend { margin-left: -10px; width: 150px; @@ -45,6 +50,10 @@ td.mountPoint, td.backend { width:160px; } margin-right: 6px; } +#externalStorage td.configuration input.disabled-success { + background-color: rgba(134, 255, 110, 0.9); +} + #externalStorage td.applicable div.chzn-container { position: relative; diff --git a/apps/files_external/js/dropbox.js b/apps/files_external/js/dropbox.js new file mode 100644 index 0000000000..8302f5711d --- /dev/null +++ b/apps/files_external/js/dropbox.js @@ -0,0 +1,30 @@ +$(document).ready(function() { + + function generateUrl($tr) { + var app_key = $tr.find('[data-parameter="app_key"]').val(); + if (app_key) { + return 'https://www.dropbox.com/developers/apps/info/' + app_key; + } else { + return 'https://www.dropbox.com/developers/apps'; + } + } + + OCA.External.Settings.mountConfig.whenSelectBackend(function($tr, backend, onCompletion) { + if (backend === 'dropbox') { + var backendEl = $tr.find('.backend'); + var el = $(document.createElement('a')) + .attr('href', generateUrl($tr)) + .attr('target', '_blank') + .attr('title', t('files_external', 'Dropbox App Configuration')) + .addClass('icon-settings svg') + ; + el.on('click', function(event) { + var a = $(event.target); + a.attr('href', generateUrl($(this).closest('tr'))); + }); + el.tooltip({placement: 'top'}); + backendEl.append(el); + } + }); + +}); diff --git a/apps/files_external/js/gdrive.js b/apps/files_external/js/gdrive.js new file mode 100644 index 0000000000..e02cedd6b4 --- /dev/null +++ b/apps/files_external/js/gdrive.js @@ -0,0 +1,26 @@ +$(document).ready(function() { + + function generateUrl($tr) { + // no mapping between client ID and Google 'project', so we always load the same URL + return 'https://console.developers.google.com/'; + } + + OCA.External.Settings.mountConfig.whenSelectBackend(function($tr, backend, onCompletion) { + if (backend === 'googledrive') { + var backendEl = $tr.find('.backend'); + var el = $(document.createElement('a')) + .attr('href', generateUrl($tr)) + .attr('target', '_blank') + .attr('title', t('files_external', 'Google Drive App Configuration')) + .addClass('icon-settings svg') + ; + el.on('click', function(event) { + var a = $(event.target); + a.attr('href', generateUrl($(this).closest('tr'))); + }); + el.tooltip({placement: 'top'}); + backendEl.append(el); + } + }); + +}); diff --git a/apps/files_external/js/oauth1.js b/apps/files_external/js/oauth1.js index e2ba25ebf8..79248a3e3b 100644 --- a/apps/files_external/js/oauth1.js +++ b/apps/files_external/js/oauth1.js @@ -1,5 +1,9 @@ $(document).ready(function() { + function displayGranted($tr) { + $tr.find('.configuration input.auth-param').attr('disabled', 'disabled').addClass('disabled-success'); + } + OCA.External.Settings.mountConfig.whenSelectAuthMechanism(function($tr, authMechanism, scheme, onCompletion) { if (authMechanism === 'oauth1::oauth1') { var config = $tr.find('.configuration'); @@ -13,8 +17,7 @@ $(document).ready(function() { onCompletion.then(function() { var configured = $tr.find('[data-parameter="configured"]'); if ($(configured).val() == 'true') { - $tr.find('.configuration input').attr('disabled', 'disabled'); - $tr.find('.configuration').append(''+t('files_external', 'Access granted')+''); + displayGranted($tr); } else { var app_key = $tr.find('.configuration [data-parameter="app_key"]').val(); var app_secret = $tr.find('.configuration [data-parameter="app_secret"]').val(); @@ -33,8 +36,7 @@ $(document).ready(function() { $(configured).val('true'); OCA.External.Settings.mountConfig.saveStorageConfig($tr, function(status) { if (status) { - $tr.find('.configuration input').attr('disabled', 'disabled'); - $tr.find('.configuration').append(''+t('files_external', 'Access granted')+''); + displayGranted($tr); } }); } else { diff --git a/apps/files_external/js/oauth2.js b/apps/files_external/js/oauth2.js index 2556bf45ca..13b5162694 100644 --- a/apps/files_external/js/oauth2.js +++ b/apps/files_external/js/oauth2.js @@ -1,5 +1,9 @@ $(document).ready(function() { + function displayGranted($tr) { + $tr.find('.configuration input.auth-param').attr('disabled', 'disabled').addClass('disabled-success'); + } + OCA.External.Settings.mountConfig.whenSelectAuthMechanism(function($tr, authMechanism, scheme, onCompletion) { if (authMechanism === 'oauth2::oauth2') { var config = $tr.find('.configuration'); @@ -13,9 +17,7 @@ $(document).ready(function() { onCompletion.then(function() { var configured = $tr.find('[data-parameter="configured"]'); if ($(configured).val() == 'true') { - $tr.find('.configuration input').attr('disabled', 'disabled'); - $tr.find('.configuration').append($('').attr('id', 'access') - .text(t('files_external', 'Access granted'))); + displayGranted($tr); } else { var client_id = $tr.find('.configuration [data-parameter="client_id"]').val(); var client_secret = $tr.find('.configuration [data-parameter="client_secret"]') @@ -43,10 +45,7 @@ $(document).ready(function() { $(configured).val('true'); OCA.External.Settings.mountConfig.saveStorageConfig($tr, function(status) { if (status) { - $tr.find('.configuration input').attr('disabled', 'disabled'); - $tr.find('.configuration').append($('') - .attr('id', 'access') - .text(t('files_external', 'Access granted'))); + displayGranted($tr); } }); } else { diff --git a/apps/files_external/lib/auth/oauth1/oauth1.php b/apps/files_external/lib/auth/oauth1/oauth1.php index dd83c9a6a6..808681530e 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 c89007b52b..d4bba8ef0e 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 9045f6818f..7732beeddf 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/dropbox.php b/apps/files_external/lib/backend/dropbox.php index f915608251..2133c27499 100644 --- a/apps/files_external/lib/backend/dropbox.php +++ b/apps/files_external/lib/backend/dropbox.php @@ -44,6 +44,7 @@ class Dropbox extends Backend { // all parameters handled in OAuth1 mechanism ]) ->addAuthScheme(AuthMechanism::SCHEME_OAUTH1) + ->addCustomJs('dropbox') ->setLegacyAuthMechanism($legacyAuth) ; } diff --git a/apps/files_external/lib/backend/google.php b/apps/files_external/lib/backend/google.php index b2b48a0e40..b18b7bdb34 100644 --- a/apps/files_external/lib/backend/google.php +++ b/apps/files_external/lib/backend/google.php @@ -44,6 +44,7 @@ class Google extends Backend { // all parameters handled in OAuth2 mechanism ]) ->addAuthScheme(AuthMechanism::SCHEME_OAUTH2) + ->addCustomJs('gdrive') ->setLegacyAuthMechanism($legacyAuth) ; } diff --git a/apps/files_external/lib/backend/legacybackend.php b/apps/files_external/lib/backend/legacybackend.php index 084758ff78..752c501e1e 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 9f2b7c40f7..ccc2a75fd1 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 7edd66fe4d..c9cc40b0ba 100644 --- a/apps/files_external/templates/settings.php +++ b/apps/files_external/templates/settings.php @@ -1,5 +1,6 @@ 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 d825b7627b..465b79a6be 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 2afc87762e..b3846fa151 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);