Skip to content

Commit

Permalink
Merge pull request #22214 from owncloud/ext-better-dropbox-gdrive
Browse files Browse the repository at this point in the history
Direct links to Google Drive/Dropbox configuration pages from external storage config
  • Loading branch information
Vincent Petry committed May 13, 2016
2 parents 3db709d + ac27163 commit ddea34f
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 29 deletions.
9 changes: 9 additions & 0 deletions apps/files_external/css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions apps/files_external/js/dropbox.js
Original file line number Diff line number Diff line change
@@ -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);
}
});

});
26 changes: 26 additions & 0 deletions apps/files_external/js/gdrive.js
Original file line number Diff line number Diff line change
@@ -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);
}
});

});
10 changes: 6 additions & 4 deletions apps/files_external/js/oauth1.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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();
Expand All @@ -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 {
Expand Down
13 changes: 6 additions & 7 deletions apps/files_external/js/oauth2.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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"]')
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion apps/files_external/lib/auth/oauth1/oauth1.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(IL10N $l) {
(new DefinitionParameter('token_secret', 'token_secret'))
->setType(DefinitionParameter::VALUE_HIDDEN),
])
->setCustomJs('oauth1')
->addCustomJs('oauth1')
;
}

Expand Down
2 changes: 1 addition & 1 deletion apps/files_external/lib/auth/oauth2/oauth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(IL10N $l) {
(new DefinitionParameter('token', 'token'))
->setType(DefinitionParameter::VALUE_HIDDEN),
])
->setCustomJs('oauth2')
->addCustomJs('oauth2')
;
}

Expand Down
2 changes: 1 addition & 1 deletion apps/files_external/lib/auth/publickey/rsa.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct(IL10N $l, IConfig $config) {
(new DefinitionParameter('private_key', 'private_key'))
->setType(DefinitionParameter::VALUE_HIDDEN),
])
->setCustomJs('public_key')
->addCustomJs('public_key')
;
}

Expand Down
1 change: 1 addition & 0 deletions apps/files_external/lib/backend/dropbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function __construct(IL10N $l, OAuth1 $legacyAuth) {
// all parameters handled in OAuth1 mechanism
])
->addAuthScheme(AuthMechanism::SCHEME_OAUTH1)
->addCustomJs('dropbox')
->setLegacyAuthMechanism($legacyAuth)
;
}
Expand Down
1 change: 1 addition & 0 deletions apps/files_external/lib/backend/google.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function __construct(IL10N $l, OAuth2 $legacyAuth) {
// all parameters handled in OAuth2 mechanism
])
->addAuthScheme(AuthMechanism::SCHEME_OAUTH2)
->addCustomJs('gdrive')
->setLegacyAuthMechanism($legacyAuth)
;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/files_external/lib/backend/legacybackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function __construct($class, array $definition, Builtin $authMechanism) {
$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;
Expand Down
22 changes: 15 additions & 7 deletions apps/files_external/lib/frontenddefinitiontrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -92,7 +92,7 @@ public function addParameter(DefinitionParameter $parameter) {
}

/**
* @return string|null
* @return string[]
*/
public function getCustomJs() {
return $this->customJs;
Expand All @@ -102,8 +102,18 @@ public function getCustomJs() {
* @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;
}

Expand All @@ -121,10 +131,8 @@ public function jsonSerializeDefinition() {
$data = [
'name' => $this->getText(),
'configuration' => $configuration,
'custom' => $this->getCustomJs(),
];
if (isset($this->customJs)) {
$data['custom'] = $this->getCustomJs();
}
return $data;
}

Expand Down
12 changes: 8 additions & 4 deletions apps/files_external/templates/settings.php
Original file line number Diff line number Diff line change
@@ -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;

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

Expand Down
2 changes: 1 addition & 1 deletion apps/files_external/tests/backend/legacybackendtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testConstructor() {
$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());

Expand Down
6 changes: 4 additions & 2 deletions apps/files_external/tests/frontenddefinitiontraittest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ public function testJsonSerialization() {
$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);
Expand Down

0 comments on commit ddea34f

Please sign in to comment.