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:
Vincent Petry 2016-05-13 17:09:27 +02:00
commit ddea34f959
15 changed files with 111 additions and 29 deletions

View File

@ -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;

View File

@ -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);
}
});
});

View File

@ -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);
}
});
});

View File

@ -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('<span id="access" style="padding-left:0.5em;">'+t('files_external', 'Access granted')+'</span>');
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('<span id="access" style="padding-left:0.5em;">'+t('files_external', 'Access granted')+'</span>');
displayGranted($tr);
}
});
} else {

View File

@ -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($('<span/>').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($('<span/>')
.attr('id', 'access')
.text(t('files_external', 'Access granted')));
displayGranted($tr);
}
});
} else {

View File

@ -46,7 +46,7 @@ class OAuth1 extends AuthMechanism {
(new DefinitionParameter('token_secret', 'token_secret'))
->setType(DefinitionParameter::VALUE_HIDDEN),
])
->setCustomJs('oauth1')
->addCustomJs('oauth1')
;
}

View File

@ -44,7 +44,7 @@ class OAuth2 extends AuthMechanism {
(new DefinitionParameter('token', 'token'))
->setType(DefinitionParameter::VALUE_HIDDEN),
])
->setCustomJs('oauth2')
->addCustomJs('oauth2')
;
}

View File

@ -52,7 +52,7 @@ class RSA extends AuthMechanism {
(new DefinitionParameter('private_key', 'private_key'))
->setType(DefinitionParameter::VALUE_HIDDEN),
])
->setCustomJs('public_key')
->addCustomJs('public_key')
;
}

View File

@ -44,6 +44,7 @@ class Dropbox extends Backend {
// all parameters handled in OAuth1 mechanism
])
->addAuthScheme(AuthMechanism::SCHEME_OAUTH1)
->addCustomJs('dropbox')
->setLegacyAuthMechanism($legacyAuth)
;
}

View File

@ -44,6 +44,7 @@ class Google extends Backend {
// all parameters handled in OAuth2 mechanism
])
->addAuthScheme(AuthMechanism::SCHEME_OAUTH2)
->addCustomJs('gdrive')
->setLegacyAuthMechanism($legacyAuth)
;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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());

View File

@ -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);