Merge pull request #22214 from owncloud/ext-better-dropbox-gdrive
Direct links to Google Drive/Dropbox configuration pages from external storage config
This commit is contained in:
commit
ddea34f959
|
@ -18,6 +18,11 @@ td.mountPoint, td.backend { width:160px; }
|
||||||
#addMountPoint>td.applicable { visibility:hidden; }
|
#addMountPoint>td.applicable { visibility:hidden; }
|
||||||
#addMountPoint>td.hidden { visibility:hidden; }
|
#addMountPoint>td.hidden { visibility:hidden; }
|
||||||
|
|
||||||
|
#externalStorage .icon-settings {
|
||||||
|
padding: 11px 20px;
|
||||||
|
vertical-align: text-bottom;
|
||||||
|
}
|
||||||
|
|
||||||
#selectBackend {
|
#selectBackend {
|
||||||
margin-left: -10px;
|
margin-left: -10px;
|
||||||
width: 150px;
|
width: 150px;
|
||||||
|
@ -45,6 +50,10 @@ td.mountPoint, td.backend { width:160px; }
|
||||||
margin-right: 6px;
|
margin-right: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#externalStorage td.configuration input.disabled-success {
|
||||||
|
background-color: rgba(134, 255, 110, 0.9);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#externalStorage td.applicable div.chzn-container {
|
#externalStorage td.applicable div.chzn-container {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
|
@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
|
@ -1,5 +1,9 @@
|
||||||
$(document).ready(function() {
|
$(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) {
|
OCA.External.Settings.mountConfig.whenSelectAuthMechanism(function($tr, authMechanism, scheme, onCompletion) {
|
||||||
if (authMechanism === 'oauth1::oauth1') {
|
if (authMechanism === 'oauth1::oauth1') {
|
||||||
var config = $tr.find('.configuration');
|
var config = $tr.find('.configuration');
|
||||||
|
@ -13,8 +17,7 @@ $(document).ready(function() {
|
||||||
onCompletion.then(function() {
|
onCompletion.then(function() {
|
||||||
var configured = $tr.find('[data-parameter="configured"]');
|
var configured = $tr.find('[data-parameter="configured"]');
|
||||||
if ($(configured).val() == 'true') {
|
if ($(configured).val() == 'true') {
|
||||||
$tr.find('.configuration input').attr('disabled', 'disabled');
|
displayGranted($tr);
|
||||||
$tr.find('.configuration').append('<span id="access" style="padding-left:0.5em;">'+t('files_external', 'Access granted')+'</span>');
|
|
||||||
} else {
|
} else {
|
||||||
var app_key = $tr.find('.configuration [data-parameter="app_key"]').val();
|
var app_key = $tr.find('.configuration [data-parameter="app_key"]').val();
|
||||||
var app_secret = $tr.find('.configuration [data-parameter="app_secret"]').val();
|
var app_secret = $tr.find('.configuration [data-parameter="app_secret"]').val();
|
||||||
|
@ -33,8 +36,7 @@ $(document).ready(function() {
|
||||||
$(configured).val('true');
|
$(configured).val('true');
|
||||||
OCA.External.Settings.mountConfig.saveStorageConfig($tr, function(status) {
|
OCA.External.Settings.mountConfig.saveStorageConfig($tr, function(status) {
|
||||||
if (status) {
|
if (status) {
|
||||||
$tr.find('.configuration input').attr('disabled', 'disabled');
|
displayGranted($tr);
|
||||||
$tr.find('.configuration').append('<span id="access" style="padding-left:0.5em;">'+t('files_external', 'Access granted')+'</span>');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
$(document).ready(function() {
|
$(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) {
|
OCA.External.Settings.mountConfig.whenSelectAuthMechanism(function($tr, authMechanism, scheme, onCompletion) {
|
||||||
if (authMechanism === 'oauth2::oauth2') {
|
if (authMechanism === 'oauth2::oauth2') {
|
||||||
var config = $tr.find('.configuration');
|
var config = $tr.find('.configuration');
|
||||||
|
@ -13,9 +17,7 @@ $(document).ready(function() {
|
||||||
onCompletion.then(function() {
|
onCompletion.then(function() {
|
||||||
var configured = $tr.find('[data-parameter="configured"]');
|
var configured = $tr.find('[data-parameter="configured"]');
|
||||||
if ($(configured).val() == 'true') {
|
if ($(configured).val() == 'true') {
|
||||||
$tr.find('.configuration input').attr('disabled', 'disabled');
|
displayGranted($tr);
|
||||||
$tr.find('.configuration').append($('<span/>').attr('id', 'access')
|
|
||||||
.text(t('files_external', 'Access granted')));
|
|
||||||
} else {
|
} else {
|
||||||
var client_id = $tr.find('.configuration [data-parameter="client_id"]').val();
|
var client_id = $tr.find('.configuration [data-parameter="client_id"]').val();
|
||||||
var client_secret = $tr.find('.configuration [data-parameter="client_secret"]')
|
var client_secret = $tr.find('.configuration [data-parameter="client_secret"]')
|
||||||
|
@ -43,10 +45,7 @@ $(document).ready(function() {
|
||||||
$(configured).val('true');
|
$(configured).val('true');
|
||||||
OCA.External.Settings.mountConfig.saveStorageConfig($tr, function(status) {
|
OCA.External.Settings.mountConfig.saveStorageConfig($tr, function(status) {
|
||||||
if (status) {
|
if (status) {
|
||||||
$tr.find('.configuration input').attr('disabled', 'disabled');
|
displayGranted($tr);
|
||||||
$tr.find('.configuration').append($('<span/>')
|
|
||||||
.attr('id', 'access')
|
|
||||||
.text(t('files_external', 'Access granted')));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -46,7 +46,7 @@ class OAuth1 extends AuthMechanism {
|
||||||
(new DefinitionParameter('token_secret', 'token_secret'))
|
(new DefinitionParameter('token_secret', 'token_secret'))
|
||||||
->setType(DefinitionParameter::VALUE_HIDDEN),
|
->setType(DefinitionParameter::VALUE_HIDDEN),
|
||||||
])
|
])
|
||||||
->setCustomJs('oauth1')
|
->addCustomJs('oauth1')
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ class OAuth2 extends AuthMechanism {
|
||||||
(new DefinitionParameter('token', 'token'))
|
(new DefinitionParameter('token', 'token'))
|
||||||
->setType(DefinitionParameter::VALUE_HIDDEN),
|
->setType(DefinitionParameter::VALUE_HIDDEN),
|
||||||
])
|
])
|
||||||
->setCustomJs('oauth2')
|
->addCustomJs('oauth2')
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ class RSA extends AuthMechanism {
|
||||||
(new DefinitionParameter('private_key', 'private_key'))
|
(new DefinitionParameter('private_key', 'private_key'))
|
||||||
->setType(DefinitionParameter::VALUE_HIDDEN),
|
->setType(DefinitionParameter::VALUE_HIDDEN),
|
||||||
])
|
])
|
||||||
->setCustomJs('public_key')
|
->addCustomJs('public_key')
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ class Dropbox extends Backend {
|
||||||
// all parameters handled in OAuth1 mechanism
|
// all parameters handled in OAuth1 mechanism
|
||||||
])
|
])
|
||||||
->addAuthScheme(AuthMechanism::SCHEME_OAUTH1)
|
->addAuthScheme(AuthMechanism::SCHEME_OAUTH1)
|
||||||
|
->addCustomJs('dropbox')
|
||||||
->setLegacyAuthMechanism($legacyAuth)
|
->setLegacyAuthMechanism($legacyAuth)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ class Google extends Backend {
|
||||||
// all parameters handled in OAuth2 mechanism
|
// all parameters handled in OAuth2 mechanism
|
||||||
])
|
])
|
||||||
->addAuthScheme(AuthMechanism::SCHEME_OAUTH2)
|
->addAuthScheme(AuthMechanism::SCHEME_OAUTH2)
|
||||||
|
->addCustomJs('gdrive')
|
||||||
->setLegacyAuthMechanism($legacyAuth)
|
->setLegacyAuthMechanism($legacyAuth)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ class LegacyBackend extends Backend {
|
||||||
$this->setPriority($definition['priority']);
|
$this->setPriority($definition['priority']);
|
||||||
}
|
}
|
||||||
if (isset($definition['custom'])) {
|
if (isset($definition['custom'])) {
|
||||||
$this->setCustomJs($definition['custom']);
|
$this->addCustomJs($definition['custom']);
|
||||||
}
|
}
|
||||||
if (isset($definition['has_dependencies']) && $definition['has_dependencies']) {
|
if (isset($definition['has_dependencies']) && $definition['has_dependencies']) {
|
||||||
$this->hasDependencies = true;
|
$this->hasDependencies = true;
|
||||||
|
|
|
@ -36,8 +36,8 @@ trait FrontendDefinitionTrait {
|
||||||
/** @var DefinitionParameter[] parameters for mechanism */
|
/** @var DefinitionParameter[] parameters for mechanism */
|
||||||
private $parameters = [];
|
private $parameters = [];
|
||||||
|
|
||||||
/** @var string|null custom JS */
|
/** @var string[] custom JS */
|
||||||
private $customJs = null;
|
private $customJs = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
|
@ -92,7 +92,7 @@ trait FrontendDefinitionTrait {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
public function getCustomJs() {
|
public function getCustomJs() {
|
||||||
return $this->customJs;
|
return $this->customJs;
|
||||||
|
@ -102,8 +102,18 @@ trait FrontendDefinitionTrait {
|
||||||
* @param string $custom
|
* @param string $custom
|
||||||
* @return self
|
* @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) {
|
public function setCustomJs($custom) {
|
||||||
$this->customJs = $custom;
|
$this->customJs = [$custom];
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,10 +131,8 @@ trait FrontendDefinitionTrait {
|
||||||
$data = [
|
$data = [
|
||||||
'name' => $this->getText(),
|
'name' => $this->getText(),
|
||||||
'configuration' => $configuration,
|
'configuration' => $configuration,
|
||||||
|
'custom' => $this->getCustomJs(),
|
||||||
];
|
];
|
||||||
if (isset($this->customJs)) {
|
|
||||||
$data['custom'] = $this->getCustomJs();
|
|
||||||
}
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
use \OCA\Files_External\Lib\Backend\Backend;
|
use \OCA\Files_External\Lib\Backend\Backend;
|
||||||
|
use \OCA\Files_External\Lib\Auth\AuthMechanism;
|
||||||
use \OCA\Files_External\Lib\DefinitionParameter;
|
use \OCA\Files_External\Lib\DefinitionParameter;
|
||||||
use \OCA\Files_External\Service\BackendService;
|
use \OCA\Files_External\Service\BackendService;
|
||||||
|
|
||||||
|
@ -16,13 +17,16 @@
|
||||||
// load custom JS
|
// load custom JS
|
||||||
foreach ($_['backends'] as $backend) {
|
foreach ($_['backends'] as $backend) {
|
||||||
/** @var Backend $backend */
|
/** @var Backend $backend */
|
||||||
if ($backend->getCustomJs()) {
|
$scripts = $backend->getCustomJs();
|
||||||
script('files_external', $backend->getCustomJs());
|
foreach ($scripts as $script) {
|
||||||
|
script('files_external', $script);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($_['authMechanisms'] as $authMechanism) {
|
foreach ($_['authMechanisms'] as $authMechanism) {
|
||||||
if ($authMechanism->getCustomJs()) {
|
/** @var AuthMechanism $authMechanism */
|
||||||
script('files_external', $authMechanism->getCustomJs());
|
$scripts = $authMechanism->getCustomJs();
|
||||||
|
foreach ($scripts as $script) {
|
||||||
|
script('files_external', $script);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ class LegacyBackendTest extends \Test\TestCase {
|
||||||
$this->assertEquals('\OCA\Files_External\Tests\Backend\LegacyBackendTest', $backend->getStorageClass());
|
$this->assertEquals('\OCA\Files_External\Tests\Backend\LegacyBackendTest', $backend->getStorageClass());
|
||||||
$this->assertEquals('Backend text', $backend->getText());
|
$this->assertEquals('Backend text', $backend->getText());
|
||||||
$this->assertEquals(123, $backend->getPriority());
|
$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->assertArrayHasKey('builtin', $backend->getAuthSchemes());
|
||||||
$this->assertEquals($auth, $backend->getLegacyAuthMechanism());
|
$this->assertEquals($auth, $backend->getLegacyAuthMechanism());
|
||||||
|
|
||||||
|
|
|
@ -33,12 +33,14 @@ class FrontendDefinitionTraitTest extends \Test\TestCase {
|
||||||
$trait = $this->getMockForTrait('\OCA\Files_External\Lib\FrontendDefinitionTrait');
|
$trait = $this->getMockForTrait('\OCA\Files_External\Lib\FrontendDefinitionTrait');
|
||||||
$trait->setText('test');
|
$trait->setText('test');
|
||||||
$trait->addParameters([$param]);
|
$trait->addParameters([$param]);
|
||||||
$trait->setCustomJs('foo/bar.js');
|
$trait->addCustomJs('foo/bar.js');
|
||||||
|
$trait->addCustomJs('bar/foo.js');
|
||||||
|
|
||||||
$json = $trait->jsonSerializeDefinition();
|
$json = $trait->jsonSerializeDefinition();
|
||||||
|
|
||||||
$this->assertEquals('test', $json['name']);
|
$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'];
|
$configuration = $json['configuration'];
|
||||||
$this->assertArrayHasKey('foo', $configuration);
|
$this->assertArrayHasKey('foo', $configuration);
|
||||||
|
|
Loading…
Reference in New Issue