From 0dbf1d02600ef4075ceffe9c62c1ed32cc24592f Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Mon, 24 Dec 2012 13:45:52 -0500 Subject: [PATCH 01/23] Show status icons for mount points in external storage UI --- apps/files_external/ajax/addMountPoint.php | 5 +- apps/files_external/css/settings.css | 5 +- apps/files_external/img/error.png | Bin 0 -> 533 bytes apps/files_external/img/success.png | Bin 0 -> 545 bytes apps/files_external/img/waiting.png | Bin 0 -> 512 bytes apps/files_external/js/settings.js | 21 +++++- apps/files_external/lib/amazons3.php | 14 +++- apps/files_external/lib/config.php | 37 ++++++++-- apps/files_external/lib/dropbox.php | 5 +- apps/files_external/lib/ftp.php | 41 ++++++----- apps/files_external/lib/google.php | 4 ++ apps/files_external/lib/smb.php | 50 +++++++------ apps/files_external/lib/swift.php | 45 ++++++------ apps/files_external/lib/webdav.php | 77 ++++++++++++--------- apps/files_external/templates/settings.php | 6 ++ 15 files changed, 203 insertions(+), 107 deletions(-) create mode 100644 apps/files_external/img/error.png create mode 100644 apps/files_external/img/success.png create mode 100644 apps/files_external/img/waiting.png diff --git a/apps/files_external/ajax/addMountPoint.php b/apps/files_external/ajax/addMountPoint.php index 4cd8871b310..fed2ddfcf3d 100644 --- a/apps/files_external/ajax/addMountPoint.php +++ b/apps/files_external/ajax/addMountPoint.php @@ -10,9 +10,10 @@ if ($_POST['isPersonal'] == 'true') { OCP\JSON::checkAdminUser(); $isPersonal = false; } -OC_Mount_Config::addMountPoint($_POST['mountPoint'], +$status = OC_Mount_Config::addMountPoint($_POST['mountPoint'], $_POST['class'], $_POST['classOptions'], $_POST['mountType'], $_POST['applicable'], - $isPersonal); \ No newline at end of file + $isPersonal); +OCP\JSON::success(array('data' => array('message' => $status))); \ No newline at end of file diff --git a/apps/files_external/css/settings.css b/apps/files_external/css/settings.css index ca4b1c3ba89..94b453793b1 100644 --- a/apps/files_external/css/settings.css +++ b/apps/files_external/css/settings.css @@ -1,4 +1,7 @@ -.error { color: #FF3B3B; } +td.status>span { display:inline-block; height:16px; width:16px; } +span.success { background-image: url('../img/success.png'); background-repeat:no-repeat; } +span.error { background-image: url('../img/error.png'); background-repeat:no-repeat; } +span.waiting { background-image: url('../img/waiting.png'); background-repeat:no-repeat; } td.mountPoint, td.backend { width:10em; } td.remove>img { visibility:hidden; padding-top:0.8em; } tr:hover>td.remove>img { visibility:visible; cursor:pointer; } diff --git a/apps/files_external/img/error.png b/apps/files_external/img/error.png new file mode 100644 index 0000000000000000000000000000000000000000..e8cf45e7a41e358da5d573dc48edf966b9d8d3cb GIT binary patch literal 533 zcmV+w0_y#VP)WFU8GbZ8()Nlj2>E@cM*00DVPL_t(I%XO2zP9s4O zguh~X5z9j$Ik*!Eu?ZcT0EtI%c=tr!kViP_BtS$CaeUzg7B7Jj7!|?H{uwjLtV-3> zRn@&>@BFDwr{D!*hBZL|-hfuX?akZEddSzfxLzWDb$|;+?nzd2^ZxSt%L9Lp>wCjo z7RIR5cLWLBC<71IZ`&(?BY?Z(dKqS3StOYXNP-X~AP`{_Kr)0izpLscfF7%Q3VJGf z4;&5s?4Qd>umES9`pRhSHdlY8_f9u^WUw@(B~!+tc1@Q1y$m+`aROHyyL9&FY2k_$#&k$!-Ejh_DEk1(FGggfnJm+z@tivD>aYVgKXg9y8ycq@@yO zj~gC-e!TXp4De(3dX=EbtDDs%pekKkJfLZd55>!KI++RWFU8GbZ8()Nlj2>E@cM*00D(bL_t(I%Vm>6irYXC zMc-GKURaaHl z|G!$?Jl#{fHSB>Muqo~f_yios$A9NKUbS)e)E>a!C1KY)u0x0M@$JXE0^QH{#imD# zvraQ0=N0ifetUZWXaKtB_CTUnfRbLN5O!H_ zxDv+Zb11Z5S`|z+EUcWIojJx*Nfy99NbGK@Dk&8MTF7!`i(L@f$gV<+BxKKMTz+KN z)e&rhw6v)i-3sYyZ~hvL2|^d((}aJKQFFVugR?-@rBQHVk|~O?&00o6S-!}&lBT^= zqokuk5JCwQLXiU$MfU_W!b!#FDfZZ0zm8`TLq0X1L@C6Skc?VT^3p+Qxc1|D2KeFE z-HV`Ksa3|eqNk9m*X#Ybj55IWetaNlAj;^*GPWFU8GbZ8()Nlj2>E@cM*00Cr4L_t(I%Wab}PQySD zMc?=OBI&q6DAPm=ir@@s5Vr7fKnVhgoB>b>3PnmdMUL_*c5Saswz6mc{Mq^QM~u$q z;bDqdA!fiNg-^f{*j7#Ro8vV~UISGZ@E8$cRnye}2%a7vKLrb?s4R>JnFbU?`@81; zsv~&WJgqHP@(A2L!5F2lNMd<&Th+B*U!JF!p9pZ4GAu2?%6f`Smt_&k754co1hHC2 zuMB9jDnk)wWR>%D+MbovuzKZUU{;0@CXsniG{cPKwy`=fCuI=|IP>yea?!V#E~J)= zGK6pfE(Vp{&LD!-GCR&Cjv*SX3?UqCE+jg^`j@EZ8+js~V_Af-1*-nuS-+{aoJ)`o zY%73|xA!%;iYRscJGE;IrT^U0*EctHH@V$z7p?5^AamEdz1c69%d3CO^!2r0+f*dm z'); $(tr).find('.backend').data('class', backendClass); var configurations = $(this).data('configurations'); var td = $(tr).find('td.configuration'); diff --git a/apps/files_external/lib/amazons3.php b/apps/files_external/lib/amazons3.php index 235ade06db6..c1b2e889bba 100644 --- a/apps/files_external/lib/amazons3.php +++ b/apps/files_external/lib/amazons3.php @@ -30,11 +30,19 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common { private static $tempFiles = array(); - // TODO options: storage class, encryption server side, encrypt before upload? + // TODO Update to new AWS SDK public function __construct($params) { - $this->s3 = new AmazonS3(array('key' => $params['key'], 'secret' => $params['secret'])); - $this->bucket = $params['bucket']; + if (isset($params['key']) && isset($params['secret']) && isset($params['bucket'])) { + $this->s3 = new AmazonS3(array('key' => $params['key'], 'secret' => $params['secret'])); + $this->bucket = $params['bucket']; + $test = $this->s3->get_canonical_user_id(); + if (!isset($test['id']) || $test['id'] == '') { + throw new Exception(); + } + } else { + throw new Exception(); + } } private function getObject($path) { diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 1be544fbc07..99d31c5aa2d 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -131,7 +131,9 @@ class OC_Mount_Config { 'class' => $mount['class'], 'backend' => $backends[$mount['class']]['backend'], 'configuration' => $mount['options'], - 'applicable' => array('groups' => array($group), 'users' => array())); + 'applicable' => array('groups' => array($group), 'users' => array()), + 'status' => self::getBackendStatus($mount['class'], $mount['options']) + ); } } } @@ -146,10 +148,13 @@ class OC_Mount_Config { $system[$mountPoint]['applicable']['users'] = array_merge($system[$mountPoint]['applicable']['users'], array($user)); } else { - $system[$mountPoint] = array('class' => $mount['class'], + $system[$mountPoint] = array( + 'class' => $mount['class'], 'backend' => $backends[$mount['class']]['backend'], 'configuration' => $mount['options'], - 'applicable' => array('groups' => array(), 'users' => array($user))); + 'applicable' => array('groups' => array(), 'users' => array($user)), + 'status' => self::getBackendStatus($mount['class'], $mount['options']) + ); } } } @@ -170,14 +175,32 @@ class OC_Mount_Config { if (isset($mountPoints[self::MOUNT_TYPE_USER][$uid])) { foreach ($mountPoints[self::MOUNT_TYPE_USER][$uid] as $mountPoint => $mount) { // Remove '/uid/files/' from mount point - $personal[substr($mountPoint, strlen($uid) + 8)] = array('class' => $mount['class'], - 'backend' => $backends[$mount['class']]['backend'], - 'configuration' => $mount['options']); + $personal[substr($mountPoint, strlen($uid) + 8)] = array( + 'class' => $mount['class'], + 'backend' => $backends[$mount['class']]['backend'], + 'configuration' => $mount['options'], + 'status' => self::getBackendStatus($mount['class'], $mount['options']) + ); } } return $personal; } + private static function getBackendStatus($class, $options) { + foreach ($options as &$option) { + $option = str_replace('$user', OCP\User::getUser(), $option); + } + if (class_exists($class)) { + try { + new $class($options); + return true; + } catch (Exception $exception) { + return false; + } + } + return false; + } + /** * Add directory for mount point to the filesystem * @param OC_Fileview instance $view @@ -259,7 +282,7 @@ class OC_Mount_Config { $mountPoints[$mountType] = $mount; } self::writeData($isPersonal, $mountPoints); - return true; + return self::getBackendStatus($class, $classOptions); } /** diff --git a/apps/files_external/lib/dropbox.php b/apps/files_external/lib/dropbox.php index 33ca14cab15..a4f3f678344 100755 --- a/apps/files_external/lib/dropbox.php +++ b/apps/files_external/lib/dropbox.php @@ -41,7 +41,10 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { $oauth = new Dropbox_OAuth_Curl($params['app_key'], $params['app_secret']); $oauth->setToken($params['token'], $params['token_secret']); $this->dropbox = new Dropbox_API($oauth, 'dropbox'); - $this->mkdir(''); + $test = $this->stat(''); + if (!$test) { + throw new Exception('Creating OC_Filestorage_Dropbox storage failed'); + } } else { throw new Exception('Creating OC_Filestorage_Dropbox storage failed'); } diff --git a/apps/files_external/lib/ftp.php b/apps/files_external/lib/ftp.php index e796ae446bf..ac487156c18 100644 --- a/apps/files_external/lib/ftp.php +++ b/apps/files_external/lib/ftp.php @@ -16,26 +16,35 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{ private static $tempFiles=array(); public function __construct($params) { - $this->host=$params['host']; - $this->user=$params['user']; - $this->password=$params['password']; - if (isset($params['secure'])) { - if (is_string($params['secure'])) { - $this->secure = ($params['secure'] === 'true'); + if (isset($params['host']) && isset($params['user']) && isset($params['password'])) { + $this->host=$params['host']; + $this->user=$params['user']; + $this->password=$params['password']; + if (isset($params['secure'])) { + if (is_string($params['secure'])) { + $this->secure = ($params['secure'] === 'true'); + } else { + $this->secure = (bool)$params['secure']; + } } else { - $this->secure = (bool)$params['secure']; + $this->secure = false; + } + $this->root=isset($params['root'])?$params['root']:'/'; + if ( ! $this->root || $this->root[0]!='/') { + $this->root='/'.$this->root; + } + $test = $this->stat(''); + if (!$test) { + throw new Exception(); + } + //create the root folder if necesary + if ( ! $this->is_dir('')) { + $this->mkdir(''); } } else { - $this->secure = false; - } - $this->root=isset($params['root'])?$params['root']:'/'; - if ( ! $this->root || $this->root[0]!='/') { - $this->root='/'.$this->root; - } - //create the root folder if necesary - if ( ! $this->is_dir('')) { - $this->mkdir(''); + throw new Exception(); } + } /** diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php index c836a5a07c0..19772d4d37f 100644 --- a/apps/files_external/lib/google.php +++ b/apps/files_external/lib/google.php @@ -42,6 +42,10 @@ class OC_Filestorage_Google extends OC_Filestorage_Common { $this->oauth_token = new OAuthToken($params['token'], $params['token_secret']); $this->sig_method = new OAuthSignatureMethod_HMAC_SHA1(); $this->entries = array(); + $test = $this->free_space(''); + if (!$test) { + throw new Exception(); + } } else { throw new Exception('Creating OC_Filestorage_Google storage failed'); } diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php index 071a9cd5f95..97454b46015 100644 --- a/apps/files_external/lib/smb.php +++ b/apps/files_external/lib/smb.php @@ -16,28 +16,36 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{ private $share; public function __construct($params) { - $this->host=$params['host']; - $this->user=$params['user']; - $this->password=$params['password']; - $this->share=$params['share']; - $this->root=isset($params['root'])?$params['root']:'/'; - if ( ! $this->root || $this->root[0]!='/') { - $this->root='/'.$this->root; - } - if (substr($this->root, -1, 1)!='/') { - $this->root.='/'; - } - if ( ! $this->share || $this->share[0]!='/') { - $this->share='/'.$this->share; - } - if (substr($this->share, -1, 1)=='/') { - $this->share=substr($this->share, 0, -1); - } - - //create the root folder if necesary - if ( ! $this->is_dir('')) { - $this->mkdir(''); + if (isset($params['host']) && isset($params['user']) && isset($params['password']) && isset($params['share'])) { + $this->host=$params['host']; + $this->user=$params['user']; + $this->password=$params['password']; + $this->share=$params['share']; + $this->root=isset($params['root'])?$params['root']:'/'; + if ( ! $this->root || $this->root[0]!='/') { + $this->root='/'.$this->root; + } + if (substr($this->root, -1, 1)!='/') { + $this->root.='/'; + } + if ( ! $this->share || $this->share[0]!='/') { + $this->share='/'.$this->share; + } + if (substr($this->share, -1, 1)=='/') { + $this->share=substr($this->share, 0, -1); + } + $test = $this->stat(''); + if (!$test) { + throw new Exception(); + } + //create the root folder if necesary + if ( ! $this->is_dir('')) { + $this->mkdir(''); + } + } else { + throw new Exception(); } + } public function constructUrl($path) { diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php index a071dfdbb03..e2add2c9873 100644 --- a/apps/files_external/lib/swift.php +++ b/apps/files_external/lib/swift.php @@ -267,32 +267,37 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{ } public function __construct($params) { - $this->token=$params['token']; - $this->host=$params['host']; - $this->user=$params['user']; - $this->root=isset($params['root'])?$params['root']:'/'; - if (isset($params['secure'])) { - if (is_string($params['secure'])) { - $this->secure = ($params['secure'] === 'true'); + if (isset($params['token']) && isset($params['host']) && isset($params['user'])) { + $this->token=$params['token']; + $this->host=$params['host']; + $this->user=$params['user']; + $this->root=isset($params['root'])?$params['root']:'/'; + if (isset($params['secure'])) { + if (is_string($params['secure'])) { + $this->secure = ($params['secure'] === 'true'); + } else { + $this->secure = (bool)$params['secure']; + } } else { - $this->secure = (bool)$params['secure']; + $this->secure = false; } - } else { - $this->secure = false; - } - if ( ! $this->root || $this->root[0]!='/') { - $this->root='/'.$this->root; - } - $this->auth = new CF_Authentication($this->user, $this->token, null, $this->host); - $this->auth->authenticate(); + if ( ! $this->root || $this->root[0]!='/') { + $this->root='/'.$this->root; + } + $this->auth = new CF_Authentication($this->user, $this->token, null, $this->host); + $this->auth->authenticate(); - $this->conn = new CF_Connection($this->auth); + $this->conn = new CF_Connection($this->auth); - if ( ! $this->containerExists('/')) { - $this->rootContainer=$this->createContainer('/'); + if ( ! $this->containerExists('/')) { + $this->rootContainer=$this->createContainer('/'); + } else { + $this->rootContainer=$this->getContainer('/'); + } } else { - $this->rootContainer=$this->getContainer('/'); + throw new Exception(); } + } diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php index 68aca228bc5..cfe073a1f1c 100644 --- a/apps/files_external/lib/webdav.php +++ b/apps/files_external/lib/webdav.php @@ -20,47 +20,56 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{ private static $tempFiles=array(); public function __construct($params) { - $host = $params['host']; - //remove leading http[s], will be generated in createBaseUri() - if (substr($host, 0, 8) == "https://") $host = substr($host, 8); - else if (substr($host, 0, 7) == "http://") $host = substr($host, 7); - $this->host=$host; - $this->user=$params['user']; - $this->password=$params['password']; - if (isset($params['secure'])) { - if (is_string($params['secure'])) { - $this->secure = ($params['secure'] === 'true'); + if (isset($params['host']) && isset($params['user']) && isset($params['password'])) { + $host = $params['host']; + //remove leading http[s], will be generated in createBaseUri() + if (substr($host, 0, 8) == "https://") $host = substr($host, 8); + else if (substr($host, 0, 7) == "http://") $host = substr($host, 7); + $this->host=$host; + $this->user=$params['user']; + $this->password=$params['password']; + if (isset($params['secure'])) { + if (is_string($params['secure'])) { + $this->secure = ($params['secure'] === 'true'); + } else { + $this->secure = (bool)$params['secure']; + } } else { - $this->secure = (bool)$params['secure']; + $this->secure = false; + } + $this->root=isset($params['root'])?$params['root']:'/'; + if ( ! $this->root || $this->root[0]!='/') { + $this->root='/'.$this->root; + } + if (substr($this->root, -1, 1)!='/') { + $this->root.='/'; } - } else { - $this->secure = false; - } - $this->root=isset($params['root'])?$params['root']:'/'; - if ( ! $this->root || $this->root[0]!='/') { - $this->root='/'.$this->root; - } - if (substr($this->root, -1, 1)!='/') { - $this->root.='/'; - } - $settings = array( - 'baseUri' => $this->createBaseUri(), - 'userName' => $this->user, - 'password' => $this->password, - ); + $settings = array( + 'baseUri' => $this->createBaseUri(), + 'userName' => $this->user, + 'password' => $this->password, + ); - $this->client = new OC_Connector_Sabre_Client($settings); + $this->client = new OC_Connector_Sabre_Client($settings); - $caview = \OCP\Files::getStorage('files_external'); - if ($caview) { - $certPath=\OCP\Config::getSystemValue('datadirectory').$caview->getAbsolutePath("").'rootcerts.crt'; - if (file_exists($certPath)) { - $this->client->addTrustedCertificates($certPath); + $caview = \OCP\Files::getStorage('files_external'); + if ($caview) { + $certPath=\OCP\Config::getSystemValue('datadirectory').$caview->getAbsolutePath("").'rootcerts.crt'; + if (file_exists($certPath)) { + $this->client->addTrustedCertificates($certPath); + } + } + $test = $this->stat(''); + if (!$test) { + throw new Exception(); } + //create the root folder if necesary + $this->mkdir(''); + } else { + throw new Exception(); } - //create the root folder if necesary - $this->mkdir(''); + } private function createBaseUri() { diff --git a/apps/files_external/templates/settings.php b/apps/files_external/templates/settings.php index dd537d779a6..9702ebfb4c7 100644 --- a/apps/files_external/templates/settings.php +++ b/apps/files_external/templates/settings.php @@ -5,6 +5,7 @@ '> + @@ -17,6 +18,11 @@ array())); ?> $mount): ?> > + From 3c08d2ba23e36dbf79ea5fdabaf931bdad32b3b9 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Mon, 24 Dec 2012 13:48:18 -0500 Subject: [PATCH 02/23] Change callback url to path only in case oauth parameters are still in url --- apps/files_external/js/google.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_external/js/google.js b/apps/files_external/js/google.js index 0b3c314eb5d..f9fb8078612 100644 --- a/apps/files_external/js/google.js +++ b/apps/files_external/js/google.js @@ -60,7 +60,7 @@ $(document).ready(function() { var configured = $(this).parent().find('[data-parameter="configured"]'); var token = $(this).parent().find('[data-parameter="token"]'); var token_secret = $(this).parent().find('[data-parameter="token_secret"]'); - $.post(OC.filePath('files_external', 'ajax', 'google.php'), { step: 1, callback: window.location.href }, function(result) { + $.post(OC.filePath('files_external', 'ajax', 'google.php'), { step: 1, callback: location.protocol + '//' + location.host + location.pathname }, function(result) { if (result && result.status == 'success') { $(configured).val('false'); $(token).val(result.data.request_token); From a0e47a2c67f0fe5ff3ed07174e0922dae67707dc Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Mon, 24 Dec 2012 13:55:37 -0500 Subject: [PATCH 03/23] Prevent javascript error if no value is set for the multiselect --- apps/files_external/js/settings.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js index eb74dd487f7..a3abcfebb8b 100644 --- a/apps/files_external/js/settings.js +++ b/apps/files_external/js/settings.js @@ -27,11 +27,16 @@ OC.MountConfig={ classOptions[$(input).data('parameter')] = $(input).val(); } }); + if ($('#externalStorage').data('admin') === true) { + var multiselect = $(tr).find('.chzn-select').val(); + if (multiselect == null) { + return false; + } + } if (addMountPoint) { var status = false; if ($('#externalStorage').data('admin') === true) { var isPersonal = false; - var multiselect = $(tr).find('.chzn-select').val(); var oldGroups = $(tr).find('.applicable').data('applicable-groups'); var oldUsers = $(tr).find('.applicable').data('applicable-users'); $.each(multiselect, function(index, value) { From 30a07e95737e3bed7be1d418c49fa9b60e160e7b Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 26 Dec 2012 13:35:22 -0500 Subject: [PATCH 04/23] Save configuration after paste events and 2 seconds after typing --- apps/files_external/js/settings.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js index a3abcfebb8b..f2a08ed6dfb 100644 --- a/apps/files_external/js/settings.js +++ b/apps/files_external/js/settings.js @@ -157,8 +157,23 @@ $(document).ready(function() { return defaultMountPoint+append; } - $('#externalStorage td').live('change', function() { - OC.MountConfig.saveStorage($(this).parent()); + $('#externalStorage td').live('paste', function() { + var tr = $(this).parent(); + setTimeout(function() { + OC.MountConfig.saveStorage(tr); + }, 20); + }); + + var timer; + + $('#externalStorage td').live('keyup', function() { + clearTimeout(timer); + var tr = $(this).parent(); + if ($(this).val) { + timer = setTimeout(function() { + OC.MountConfig.saveStorage(tr); + }, 2000); + } }); $('td.remove>img').live('click', function() { From 5d68e04e5a43d6d6f52ff511f899bc831a6aa4be Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 26 Dec 2012 13:45:22 -0500 Subject: [PATCH 05/23] Change callback url for dropbox as well --- apps/files_external/js/dropbox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_external/js/dropbox.js b/apps/files_external/js/dropbox.js index c1e38640708..cc6a37d0511 100644 --- a/apps/files_external/js/dropbox.js +++ b/apps/files_external/js/dropbox.js @@ -61,7 +61,7 @@ $(document).ready(function() { var configured = $(this).parent().find('[data-parameter="configured"]'); var token = $(this).parent().find('[data-parameter="token"]'); var token_secret = $(this).parent().find('[data-parameter="token_secret"]'); - $.post(OC.filePath('files_external', 'ajax', 'dropbox.php'), { step: 1, app_key: app_key, app_secret: app_secret, callback: window.location.href }, function(result) { + $.post(OC.filePath('files_external', 'ajax', 'dropbox.php'), { step: 1, app_key: app_key, app_secret: app_secret, callback: location.protocol + '//' + location.host + location.pathname }, function(result) { if (result && result.status == 'success') { $(configured).val('false'); $(token).val(result.data.request_token); From 48a3966ea979a56e9277f588d6001c47e8a9c606 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 26 Dec 2012 14:04:02 -0500 Subject: [PATCH 06/23] Listen to paste events for dropbox configuration --- apps/files_external/js/dropbox.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/apps/files_external/js/dropbox.js b/apps/files_external/js/dropbox.js index cc6a37d0511..824c47d9f6d 100644 --- a/apps/files_external/js/dropbox.js +++ b/apps/files_external/js/dropbox.js @@ -36,9 +36,20 @@ $(document).ready(function() { } }); - $('#externalStorage tbody tr input').live('keyup', function() { - var tr = $(this).parent().parent(); - if ($(tr).hasClass('OC_Filestorage_Dropbox') && $(tr).find('[data-parameter="configured"]').val() != 'true') { + $('#externalStorage tbody tr.OC_Filestorage_Dropbox td').live('paste', function() { + var tr = $(this).parent(); + setTimeout(function() { + showButton(tr); + }, 20); + }); + + $('#externalStorage tbody tr.OC_Filestorage_Dropbox td').live('keyup', function() { + showButton($(this).parent().parent()); + + }); + + function showButton(tr) { + if ($(tr).find('[data-parameter="configured"]').val() != 'true') { var config = $(tr).find('.configuration'); if ($(tr).find('.mountPoint input').val() != '' && $(config).find('[data-parameter="app_key"]').val() != '' && $(config).find('[data-parameter="app_secret"]').val() != '') { if ($(tr).find('.dropbox').length == 0) { @@ -50,7 +61,7 @@ $(document).ready(function() { $(tr).find('.dropbox').hide(); } } - }); + } $('.dropbox').live('click', function(event) { event.preventDefault(); From d9ff3b68602d511ede1fd8bf2516a842dee2cfd1 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 26 Dec 2012 14:18:51 -0500 Subject: [PATCH 07/23] Fix last commit's variable --- apps/files_external/js/dropbox.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/files_external/js/dropbox.js b/apps/files_external/js/dropbox.js index 824c47d9f6d..247d6bb8bb6 100644 --- a/apps/files_external/js/dropbox.js +++ b/apps/files_external/js/dropbox.js @@ -44,8 +44,7 @@ $(document).ready(function() { }); $('#externalStorage tbody tr.OC_Filestorage_Dropbox td').live('keyup', function() { - showButton($(this).parent().parent()); - + showButton($(this).parent()); }); function showButton(tr) { From ad902a9848a66135ae85a04b1c66b663219a53ea Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Fri, 28 Dec 2012 12:00:48 -0500 Subject: [PATCH 08/23] Move storage backend tests from constructor to test function --- apps/files_external/lib/amazons3.php | 12 ++++++++---- apps/files_external/lib/config.php | 4 ++-- apps/files_external/lib/dropbox.php | 4 ---- apps/files_external/lib/ftp.php | 4 ---- apps/files_external/lib/google.php | 11 +++++++---- apps/files_external/lib/smb.php | 4 ---- apps/files_external/lib/webdav.php | 4 ---- lib/filestorage.php | 1 + lib/filestorage/common.php | 8 ++++++++ 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/apps/files_external/lib/amazons3.php b/apps/files_external/lib/amazons3.php index c1b2e889bba..5ab89df732d 100644 --- a/apps/files_external/lib/amazons3.php +++ b/apps/files_external/lib/amazons3.php @@ -36,10 +36,6 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common { if (isset($params['key']) && isset($params['secret']) && isset($params['bucket'])) { $this->s3 = new AmazonS3(array('key' => $params['key'], 'secret' => $params['secret'])); $this->bucket = $params['bucket']; - $test = $this->s3->get_canonical_user_id(); - if (!isset($test['id']) || $test['id'] == '') { - throw new Exception(); - } } else { throw new Exception(); } @@ -250,4 +246,12 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common { return $response->isOK(); } + public function test() { + $test = $this->s3->get_canonical_user_id(); + if (isset($test['id']) && $test['id'] != '') { + return true; + } + return false; + } + } diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 99d31c5aa2d..fd654f04e98 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -192,8 +192,8 @@ class OC_Mount_Config { } if (class_exists($class)) { try { - new $class($options); - return true; + $storage = new $class($options); + return $storage->test(); } catch (Exception $exception) { return false; } diff --git a/apps/files_external/lib/dropbox.php b/apps/files_external/lib/dropbox.php index a4f3f678344..66dfd3e595e 100755 --- a/apps/files_external/lib/dropbox.php +++ b/apps/files_external/lib/dropbox.php @@ -41,10 +41,6 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { $oauth = new Dropbox_OAuth_Curl($params['app_key'], $params['app_secret']); $oauth->setToken($params['token'], $params['token_secret']); $this->dropbox = new Dropbox_API($oauth, 'dropbox'); - $test = $this->stat(''); - if (!$test) { - throw new Exception('Creating OC_Filestorage_Dropbox storage failed'); - } } else { throw new Exception('Creating OC_Filestorage_Dropbox storage failed'); } diff --git a/apps/files_external/lib/ftp.php b/apps/files_external/lib/ftp.php index ac487156c18..ca408d5d224 100644 --- a/apps/files_external/lib/ftp.php +++ b/apps/files_external/lib/ftp.php @@ -33,10 +33,6 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{ if ( ! $this->root || $this->root[0]!='/') { $this->root='/'.$this->root; } - $test = $this->stat(''); - if (!$test) { - throw new Exception(); - } //create the root folder if necesary if ( ! $this->is_dir('')) { $this->mkdir(''); diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php index 19772d4d37f..8710c979117 100644 --- a/apps/files_external/lib/google.php +++ b/apps/files_external/lib/google.php @@ -42,10 +42,6 @@ class OC_Filestorage_Google extends OC_Filestorage_Common { $this->oauth_token = new OAuthToken($params['token'], $params['token_secret']); $this->sig_method = new OAuthSignatureMethod_HMAC_SHA1(); $this->entries = array(); - $test = $this->free_space(''); - if (!$test) { - throw new Exception(); - } } else { throw new Exception('Creating OC_Filestorage_Google storage failed'); } @@ -594,4 +590,11 @@ class OC_Filestorage_Google extends OC_Filestorage_Common { } + public function test() { + if ($this->free_space('')) { + return true; + } + return false; + } + } \ No newline at end of file diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php index 97454b46015..5b73e993e4f 100644 --- a/apps/files_external/lib/smb.php +++ b/apps/files_external/lib/smb.php @@ -34,10 +34,6 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{ if (substr($this->share, -1, 1)=='/') { $this->share=substr($this->share, 0, -1); } - $test = $this->stat(''); - if (!$test) { - throw new Exception(); - } //create the root folder if necesary if ( ! $this->is_dir('')) { $this->mkdir(''); diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php index cfe073a1f1c..31d36f1e78b 100644 --- a/apps/files_external/lib/webdav.php +++ b/apps/files_external/lib/webdav.php @@ -60,10 +60,6 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{ $this->client->addTrustedCertificates($certPath); } } - $test = $this->stat(''); - if (!$test) { - throw new Exception(); - } //create the root folder if necesary $this->mkdir(''); } else { diff --git a/lib/filestorage.php b/lib/filestorage.php index dd65f4421b7..9d42c0bcb60 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -64,4 +64,5 @@ abstract class OC_Filestorage{ */ abstract public function hasUpdated($path, $time); abstract public function getOwner($path); + abstract public function test(); } diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php index b97eb79d8d4..e2af0c6d7f4 100644 --- a/lib/filestorage/common.php +++ b/lib/filestorage/common.php @@ -288,4 +288,12 @@ abstract class OC_Filestorage_Common extends OC_Filestorage { public function getOwner($path) { return OC_User::getUser(); } + + public function test() { + if ($this->stat('')) { + return true; + } + return false; + } + } From 595e72ade8906346c9de8500685f5968d67afd2f Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Fri, 28 Dec 2012 15:56:48 -0500 Subject: [PATCH 09/23] Fix some of the default mount points creating sub folders i.e. SMB / CIFS, ownCloud / WebDAV --- apps/files_external/js/settings.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js index f2a08ed6dfb..182c427e180 100644 --- a/apps/files_external/js/settings.js +++ b/apps/files_external/js/settings.js @@ -100,7 +100,7 @@ $(document).ready(function() { var backendClass = $(this).val(); $(this).parent().text(selected); if ($(tr).find('.mountPoint input').val() == '') { - $(tr).find('.mountPoint input').val(suggestMountPoint(selected.replace(/\s+/g, ''))); + $(tr).find('.mountPoint input').val(suggestMountPoint(selected)); } $(tr).addClass(backendClass); $(tr).find('.status').append(''); @@ -136,6 +136,11 @@ $(document).ready(function() { }); function suggestMountPoint(defaultMountPoint) { + var pos = defaultMountPoint.indexOf('/'); + if (pos !== -1) { + defaultMountPoint = defaultMountPoint.substring(0, pos); + } + defaultMountPoint = defaultMountPoint.replace(/\s+/g, ''); var i = 1; var append = ''; var match = true; From 442a045ef605f63c1fed3868ef9ddad28c33409b Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Fri, 28 Dec 2012 17:38:24 -0500 Subject: [PATCH 10/23] Fix problems with chosen multiselect --- apps/files_external/js/settings.js | 46 ++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js index 182c427e180..25f6ed57984 100644 --- a/apps/files_external/js/settings.js +++ b/apps/files_external/js/settings.js @@ -39,6 +39,8 @@ OC.MountConfig={ var isPersonal = false; var oldGroups = $(tr).find('.applicable').data('applicable-groups'); var oldUsers = $(tr).find('.applicable').data('applicable-users'); + var groups = []; + var users = []; $.each(multiselect, function(index, value) { var pos = value.indexOf('(group)'); if (pos != -1) { @@ -47,12 +49,14 @@ OC.MountConfig={ if ($.inArray(applicable, oldGroups) != -1) { oldGroups.splice($.inArray(applicable, oldGroups), 1); } + groups.push(applicable); } else { var mountType = 'user'; var applicable = value; if ($.inArray(applicable, oldUsers) != -1) { oldUsers.splice($.inArray(applicable, oldUsers), 1); } + users.push(applicable); } $.post(OC.filePath('files_external', 'ajax', 'addMountPoint.php'), { mountPoint: mountPoint, class: backendClass, classOptions: classOptions, mountType: mountType, applicable: applicable, isPersonal: isPersonal }, function(result) { statusSpan.removeClass(); @@ -63,6 +67,8 @@ OC.MountConfig={ } }); }); + $(tr).find('.applicable').data('applicable-groups', groups); + $(tr).find('.applicable').data('applicable-users', users); var mountType = 'group'; $.each(oldGroups, function(index, applicable) { $.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal }); @@ -128,7 +134,11 @@ $(document).ready(function() { return false; } }); - $('.chz-select').chosen(); + // Reset chosen + var chosen = $(tr).find('.applicable select'); + chosen.parent().find('div').remove(); + chosen.removeAttr('id').removeClass('chzn-done').css({display:'inline-block'}); + chosen.chosen(); $(tr).find('td').last().attr('class', 'remove'); $(tr).find('td').last().removeAttr('style'); $(tr).removeAttr('id'); @@ -171,9 +181,9 @@ $(document).ready(function() { var timer; - $('#externalStorage td').live('keyup', function() { + $('#externalStorage td input').live('keyup', function() { clearTimeout(timer); - var tr = $(this).parent(); + var tr = $(this).parent().parent(); if ($(this).val) { timer = setTimeout(function() { OC.MountConfig.saveStorage(tr); @@ -181,6 +191,10 @@ $(document).ready(function() { } }); + $('.applicable .chzn-select').live('change', function() { + OC.MountConfig.saveStorage($(this).parent().parent()); + }); + $('td.remove>img').live('click', function() { var tr = $(this).parent().parent(); var mountPoint = $(tr).find('.mountPoint input').val(); @@ -193,23 +207,25 @@ $(document).ready(function() { if ($('#externalStorage').data('admin') === true) { var isPersonal = false; var multiselect = $(tr).find('.chzn-select').val(); - $.each(multiselect, function(index, value) { - var pos = value.indexOf('(group)'); - if (pos != -1) { - var mountType = 'group'; - var applicable = value.substr(0, pos); - } else { - var mountType = 'user'; - var applicable = value; - } - $.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal }); - }); + if (multiselect != null) { + $.each(multiselect, function(index, value) { + var pos = value.indexOf('(group)'); + if (pos != -1) { + var mountType = 'group'; + var applicable = value.substr(0, pos); + } else { + var mountType = 'user'; + var applicable = value; + } + $.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal }); + }); + } } else { var mountType = 'user'; var applicable = OC.currentUser; var isPersonal = true; + $.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal }); } - $.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal }); $(tr).remove(); }); From a69de3a8f1dd3ef9a17b0f65b7058681eebb6145 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Tue, 1 Jan 2013 16:19:40 -0500 Subject: [PATCH 11/23] Turn off async for saving mount points, improve input detection for Google and Dropbox 'Grant Access' buttons --- apps/files_external/js/dropbox.js | 49 ++++++++++--------- apps/files_external/js/google.js | 67 ++++++++++++------------- apps/files_external/js/settings.js | 78 ++++++++++++++++++++++++------ 3 files changed, 123 insertions(+), 71 deletions(-) diff --git a/apps/files_external/js/dropbox.js b/apps/files_external/js/dropbox.js index 247d6bb8bb6..92a92467c79 100644 --- a/apps/files_external/js/dropbox.js +++ b/apps/files_external/js/dropbox.js @@ -24,14 +24,12 @@ $(document).ready(function() { $(tr).find('.configuration input').attr('disabled', 'disabled'); $(tr).find('.configuration').append(''+t('files_external', 'Access granted')+''); } else { - OC.dialogs.alert(result.data.message, - t('files_external', 'Error configuring Dropbox storage') - ); + OC.dialogs.alert(result.data.message, t('files_external', 'Error configuring Dropbox storage')); } }); } - } else if ($(this).find('.mountPoint input').val() != '' && $(config).find('[data-parameter="app_key"]').val() != '' && $(config).find('[data-parameter="app_secret"]').val() != '' && $(this).find('.dropbox').length == 0) { - $(this).find('.configuration').append(''+t('files_external', 'Grant access')+''); + } else { + onDropboxInputsChange($(this)); } } }); @@ -39,18 +37,27 @@ $(document).ready(function() { $('#externalStorage tbody tr.OC_Filestorage_Dropbox td').live('paste', function() { var tr = $(this).parent(); setTimeout(function() { - showButton(tr); + onDropboxInputsChange(tr); }, 20); }); $('#externalStorage tbody tr.OC_Filestorage_Dropbox td').live('keyup', function() { - showButton($(this).parent()); + onDropboxInputsChange($(this).parent()); }); - function showButton(tr) { + $('#externalStorage tbody tr.OC_Filestorage_Dropbox .chzn-select').live('change', function() { + onDropboxInputsChange($(this).parent().parent()); + }); + + function onDropboxInputsChange(tr) { if ($(tr).find('[data-parameter="configured"]').val() != 'true') { var config = $(tr).find('.configuration'); - if ($(tr).find('.mountPoint input').val() != '' && $(config).find('[data-parameter="app_key"]').val() != '' && $(config).find('[data-parameter="app_secret"]').val() != '') { + if ($(tr).find('.mountPoint input').val() != '' + && $(config).find('[data-parameter="app_key"]').val() != '' + && $(config).find('[data-parameter="app_secret"]').val() != '' + && ($(tr).find('.chzn-select').length == 0 + || $(tr).find('.chzn-select').val() != null)) + { if ($(tr).find('.dropbox').length == 0) { $(config).append(''+t('files_external', 'Grant access')+''); } else { @@ -64,8 +71,10 @@ $(document).ready(function() { $('.dropbox').live('click', function(event) { event.preventDefault(); + var tr = $(this).parent().parent(); var app_key = $(this).parent().find('[data-parameter="app_key"]').val(); var app_secret = $(this).parent().find('[data-parameter="app_secret"]').val(); + var statusSpan = $(tr).find('.status span'); if (app_key != '' && app_secret != '') { var tr = $(this).parent().parent(); var configured = $(this).parent().find('[data-parameter="configured"]'); @@ -76,25 +85,19 @@ $(document).ready(function() { $(configured).val('false'); $(token).val(result.data.request_token); $(token_secret).val(result.data.request_token_secret); - if (OC.MountConfig.saveStorage(tr)) { - window.location = result.data.url; - } else { - OC.dialogs.alert( - t('files_external', 'Fill out all required fields'), - t('files_external', 'Error configuring Dropbox storage') - ); - } + OC.MountConfig.saveStorage(tr); + statusSpan.removeClass(); + statusSpan.addClass('waiting'); + window.location = result.data.url; } else { - OC.dialogs.alert(result.data.message, - t('files_external', 'Error configuring Dropbox storage') - ); + OC.dialogs.alert(result.data.message, t('files_external', 'Error configuring Dropbox storage')); } }); } else { OC.dialogs.alert( - t('files_external', 'Please provide a valid Dropbox app key and secret.'), - t('files_external', 'Error configuring Dropbox storage') - ); + t('files_external', 'Please provide a valid Dropbox app key and secret.'), + t('files_external', 'Error configuring Dropbox storage') + ); } }); diff --git a/apps/files_external/js/google.js b/apps/files_external/js/google.js index f9fb8078612..a3b3e9cb3d2 100644 --- a/apps/files_external/js/google.js +++ b/apps/files_external/js/google.js @@ -3,8 +3,7 @@ $(document).ready(function() { $('#externalStorage tbody tr.OC_Filestorage_Google').each(function() { var configured = $(this).find('[data-parameter="configured"]'); if ($(configured).val() == 'true') { - $(this).find('.configuration') - .append(''+t('files_external', 'Access granted')+''); + $(this).find('.configuration').append(''+t('files_external', 'Access granted')+''); } else { var token = $(this).find('[data-parameter="token"]'); var token_secret = $(this).find('[data-parameter="token_secret"]'); @@ -22,37 +21,44 @@ $(document).ready(function() { OC.MountConfig.saveStorage(tr); $(tr).find('.configuration').append(''+t('files_external', 'Access granted')+''); } else { - OC.dialogs.alert(result.data.message, - t('files_external', 'Error configuring Google Drive storage') - ); + OC.dialogs.alert(result.data.message, t('files_external', 'Error configuring Google Drive storage')); } }); - } else if ($(this).find('.google').length == 0) { - $(this).find('.configuration').append(''+t('files_external', 'Grant access')+''); + } else { + onGoogleInputsChange(this); } } }); - $('#externalStorage tbody tr').live('change', function() { - if ($(this).hasClass('OC_Filestorage_Google') && $(this).find('[data-parameter="configured"]').val() != 'true') { - if ($(this).find('.mountPoint input').val() != '') { - if ($(this).find('.google').length == 0) { - $(this).find('.configuration').append(''+t('files_external', 'Grant access')+''); - } - } - } + $('#externalStorage tbody tr.OC_Filestorage_Google td').live('paste', function() { + var tr = $(this).parent(); + setTimeout(function() { + onGoogleInputsChange(tr); + }, 20); }); - $('#externalStorage tbody tr .mountPoint input').live('keyup', function() { - var tr = $(this).parent().parent(); - if ($(tr).hasClass('OC_Filestorage_Google') && $(tr).find('[data-parameter="configured"]').val() != 'true' && $(tr).find('.google').length > 0) { - if ($(this).val() != '') { - $(tr).find('.google').show(); - } else { + $('#externalStorage tbody tr.OC_Filestorage_Google td').live('keyup', function() { + onGoogleInputsChange($(this).parent()); + }); + + $('#externalStorage tbody tr.OC_Filestorage_Google .chzn-select').live('change', function() { + onGoogleInputsChange($(this).parent().parent()); + }); + + function onGoogleInputsChange(tr) { + if ($(tr).find('[data-parameter="configured"]').val() != 'true') { + var config = $(tr).find('.configuration'); + if ($(tr).find('.mountPoint input').val() != '' && ($(tr).find('.chzn-select').length == 0 || $(tr).find('.chzn-select').val() != null)) { + if ($(tr).find('.google').length == 0) { + $(config).append(''+t('files_external', 'Grant access')+''); + } else { + $(tr).find('.google').show(); + } + } else if ($(tr).find('.google').length > 0) { $(tr).find('.google').hide(); } } - }); + } $('.google').live('click', function(event) { event.preventDefault(); @@ -60,23 +66,18 @@ $(document).ready(function() { var configured = $(this).parent().find('[data-parameter="configured"]'); var token = $(this).parent().find('[data-parameter="token"]'); var token_secret = $(this).parent().find('[data-parameter="token_secret"]'); + var statusSpan = $(tr).find('.status span'); $.post(OC.filePath('files_external', 'ajax', 'google.php'), { step: 1, callback: location.protocol + '//' + location.host + location.pathname }, function(result) { if (result && result.status == 'success') { $(configured).val('false'); $(token).val(result.data.request_token); $(token_secret).val(result.data.request_token_secret); - if (OC.MountConfig.saveStorage(tr)) { - window.location = result.data.url; - } else { - OC.dialogs.alert( - t('files_external', 'Fill out all required fields'), - t('files_external', 'Error configuring Google Drive storage') - ); - } + OC.MountConfig.saveStorage(tr); + statusSpan.removeClass(); + statusSpan.addClass('waiting'); + window.location = result.data.url; } else { - OC.dialogs.alert(result.data.message, - t('files_external', 'Error configuring Google Drive storage') - ); + OC.dialogs.alert(result.data.message, t('files_external', 'Error configuring Google Drive storage')); } }); }); diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js index 25f6ed57984..b98fcf1b0ae 100644 --- a/apps/files_external/js/settings.js +++ b/apps/files_external/js/settings.js @@ -58,12 +58,25 @@ OC.MountConfig={ } users.push(applicable); } - $.post(OC.filePath('files_external', 'ajax', 'addMountPoint.php'), { mountPoint: mountPoint, class: backendClass, classOptions: classOptions, mountType: mountType, applicable: applicable, isPersonal: isPersonal }, function(result) { - statusSpan.removeClass(); - if (result && result.status == 'success' && result.data.message) { - statusSpan.addClass('success'); - } else { - statusSpan.addClass('error'); + $.ajax({type: 'POST', + url: OC.filePath('files_external', 'ajax', 'addMountPoint.php'), + data: { + mountPoint: mountPoint, + class: backendClass, + classOptions: classOptions, + mountType: mountType, + applicable: applicable, + isPersonal: isPersonal + }, + async: false, + success: function(result) { + statusSpan.removeClass(); + if (result && result.status == 'success' && result.data.message) { + status = true; + statusSpan.addClass('success'); + } else { + statusSpan.addClass('error'); + } } }); }); @@ -71,26 +84,61 @@ OC.MountConfig={ $(tr).find('.applicable').data('applicable-users', users); var mountType = 'group'; $.each(oldGroups, function(index, applicable) { - $.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal }); + $.ajax({type: 'POST', + url: OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), + data: { + mountPoint: mountPoint, + class: backendClass, + classOptions: classOptions, + mountType: mountType, + applicable: applicable, + isPersonal: isPersonal + }, + async: false + }); }); var mountType = 'user'; $.each(oldUsers, function(index, applicable) { - $.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal }); + $.ajax({type: 'POST', + url: OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), + data: { + mountPoint: mountPoint, + class: backendClass, + classOptions: classOptions, + mountType: mountType, + applicable: applicable, + isPersonal: isPersonal + }, + async: false + }); }); } else { var isPersonal = true; var mountType = 'user'; var applicable = OC.currentUser; - $.post(OC.filePath('files_external', 'ajax', 'addMountPoint.php'), { mountPoint: mountPoint, class: backendClass, classOptions: classOptions, mountType: mountType, applicable: applicable, isPersonal: isPersonal }, function(result) { - statusSpan.removeClass(); - if (result && result.status == 'success' && result.data.message) { - statusSpan.addClass('success'); - } else { - statusSpan.addClass('error'); + $.ajax({type: 'POST', + url: OC.filePath('files_external', 'ajax', 'addMountPoint.php'), + data: { + mountPoint: mountPoint, + class: backendClass, + classOptions: classOptions, + mountType: mountType, + applicable: applicable, + isPersonal: isPersonal + }, + async: false, + success: function(result) { + statusSpan.removeClass(); + if (result && result.status == 'success' && result.data.message) { + status = true; + statusSpan.addClass('success'); + } else { + statusSpan.addClass('error'); + } } }); } - return true; + return status; } } }; From d65cb7ae0954e89de0a1b56170ffab683c39e3cc Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 2 Jan 2013 11:54:21 -0500 Subject: [PATCH 12/23] Fix 'Grant Access' button for multiple Google Drive mount points and prevent multiple scripts being added --- apps/files_external/appinfo/update.php | 5 +++++ apps/files_external/js/google.js | 26 +++++++++++++++------- apps/files_external/templates/settings.php | 5 ++--- 3 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 apps/files_external/appinfo/update.php diff --git a/apps/files_external/appinfo/update.php b/apps/files_external/appinfo/update.php new file mode 100644 index 00000000000..15d7e4168ee --- /dev/null +++ b/apps/files_external/appinfo/update.php @@ -0,0 +1,5 @@ +tr:last').prev('tr')); + } + }); + + function setupGoogleRow(tr) { + var configured = $(tr).find('[data-parameter="configured"]'); if ($(configured).val() == 'true') { - $(this).find('.configuration').append(''+t('files_external', 'Access granted')+''); + $(tr).find('.configuration').append(''+t('files_external', 'Access granted')+''); } else { - var token = $(this).find('[data-parameter="token"]'); - var token_secret = $(this).find('[data-parameter="token_secret"]'); + var token = $(tr).find('[data-parameter="token"]'); + var token_secret = $(tr).find('[data-parameter="token_secret"]'); var params = {}; window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) { params[key] = value; }); if (params['oauth_token'] !== undefined && params['oauth_verifier'] !== undefined && decodeURIComponent(params['oauth_token']) == $(token).val()) { - var tr = $(this); $.post(OC.filePath('files_external', 'ajax', 'google.php'), { step: 2, oauth_verifier: params['oauth_verifier'], request_token: $(token).val(), request_token_secret: $(token_secret).val() }, function(result) { if (result && result.status == 'success') { $(token).val(result.access_token); @@ -22,13 +31,14 @@ $(document).ready(function() { $(tr).find('.configuration').append(''+t('files_external', 'Access granted')+''); } else { OC.dialogs.alert(result.data.message, t('files_external', 'Error configuring Google Drive storage')); + onGoogleInputsChange(tr); } }); } else { - onGoogleInputsChange(this); + onGoogleInputsChange(tr); } } - }); + } $('#externalStorage tbody tr.OC_Filestorage_Google td').live('paste', function() { var tr = $(this).parent(); diff --git a/apps/files_external/templates/settings.php b/apps/files_external/templates/settings.php index 9702ebfb4c7..6f22de392fa 100644 --- a/apps/files_external/templates/settings.php +++ b/apps/files_external/templates/settings.php @@ -73,9 +73,8 @@ - - + + From db90f2c296c4a74933c2d258d8b335a3093db0f9 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 2 Jan 2013 12:13:59 -0500 Subject: [PATCH 13/23] Listen to checkbox changes as well --- apps/files_external/js/settings.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js index b98fcf1b0ae..2a8d8d2c284 100644 --- a/apps/files_external/js/settings.js +++ b/apps/files_external/js/settings.js @@ -239,6 +239,10 @@ $(document).ready(function() { } }); + $('#externalStorage td input:checkbox').live('change', function() { + OC.MountConfig.saveStorage($(this).parent().parent().parent()); + }); + $('.applicable .chzn-select').live('change', function() { OC.MountConfig.saveStorage($(this).parent().parent()); }); From 7f218c4dc07edd2393ffa132745dcc0df16508e3 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 2 Jan 2013 13:20:44 -0500 Subject: [PATCH 14/23] Remove accidentally included file --- apps/files_external/appinfo/update.php | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 apps/files_external/appinfo/update.php diff --git a/apps/files_external/appinfo/update.php b/apps/files_external/appinfo/update.php deleted file mode 100644 index 15d7e4168ee..00000000000 --- a/apps/files_external/appinfo/update.php +++ /dev/null @@ -1,5 +0,0 @@ - Date: Wed, 9 Jan 2013 21:47:24 -0500 Subject: [PATCH 15/23] Set status to waiting for Dropbox and Google Drive while authenticating --- apps/files_external/js/dropbox.js | 3 +++ apps/files_external/js/google.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/apps/files_external/js/dropbox.js b/apps/files_external/js/dropbox.js index 92a92467c79..9314a4c7927 100644 --- a/apps/files_external/js/dropbox.js +++ b/apps/files_external/js/dropbox.js @@ -15,6 +15,9 @@ $(document).ready(function() { if (pos != -1 && window.location.search.substr(pos, $(token).val().length) == $(token).val()) { var token_secret = $(this).find('.configuration [data-parameter="token_secret"]'); var tr = $(this); + var statusSpan = $(tr).find('.status span'); + statusSpan.removeClass(); + statusSpan.addClass('waiting'); $.post(OC.filePath('files_external', 'ajax', 'dropbox.php'), { step: 2, app_key: app_key, app_secret: app_secret, request_token: $(token).val(), request_token_secret: $(token_secret).val() }, function(result) { if (result && result.status == 'success') { $(token).val(result.access_token); diff --git a/apps/files_external/js/google.js b/apps/files_external/js/google.js index 89daa0078e8..ad6fc6a0f9a 100644 --- a/apps/files_external/js/google.js +++ b/apps/files_external/js/google.js @@ -22,6 +22,9 @@ $(document).ready(function() { params[key] = value; }); if (params['oauth_token'] !== undefined && params['oauth_verifier'] !== undefined && decodeURIComponent(params['oauth_token']) == $(token).val()) { + var statusSpan = $(tr).find('.status span'); + statusSpan.removeClass(); + statusSpan.addClass('waiting'); $.post(OC.filePath('files_external', 'ajax', 'google.php'), { step: 2, oauth_verifier: params['oauth_verifier'], request_token: $(token).val(), request_token_secret: $(token_secret).val() }, function(result) { if (result && result.status == 'success') { $(token).val(result.access_token); From 6f08b1f829e9d4c49f66b19fdda8c229bc8ae3f3 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Mon, 11 Feb 2013 18:04:54 -0500 Subject: [PATCH 16/23] Change wordings --- apps/files_external/templates/settings.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/files_external/templates/settings.php b/apps/files_external/templates/settings.php index 6f22de392fa..62bbf3a5ae1 100644 --- a/apps/files_external/templates/settings.php +++ b/apps/files_external/templates/settings.php @@ -6,8 +6,8 @@ - - + + '.$l->t('Applicable').''; ?> @@ -30,7 +30,7 @@ + placeholder="t('Folder name'); ?>" />
t('Mount point'); ?> t('Backend'); ?> t('Configuration'); ?>
+ + + +
t('Mount point'); ?>t('Backend'); ?>t('Folder name'); ?>t('External storage'); ?> t('Configuration'); ?>