Merge pull request #20920 from owncloud/issue_20888
Add dialog to enter credentials on errored mount point
This commit is contained in:
commit
342c2aac98
|
@ -255,8 +255,9 @@ abstract class StoragesController extends Controller {
|
|||
)
|
||||
);
|
||||
} catch (InsufficientDataForMeaningfulAnswerException $e) {
|
||||
$status = $e->getCode() ? $e->getCode() : StorageNotAvailableException::STATUS_INDETERMINATE;
|
||||
$storage->setStatus(
|
||||
StorageNotAvailableException::STATUS_INDETERMINATE,
|
||||
$status,
|
||||
$this->l10n->t('Insufficient data: %s', [$e->getMessage()])
|
||||
);
|
||||
} catch (StorageNotAvailableException $e) {
|
||||
|
|
|
@ -82,16 +82,16 @@ OCA.External.StatusManager = {
|
|||
if (response && response.status === 0) {
|
||||
self.mountStatus[mountData.mount_point] = response;
|
||||
} else {
|
||||
if (response && response.statusMessage) {
|
||||
var statusCode = response.status ? response.status : 1;
|
||||
var statusMessage = response.statusMessage ? response.statusMessage : t('files_external', 'Empty response from the server')
|
||||
// failure response with error message
|
||||
self.mountStatus[mountData.mount_point] = { type: mountData.type,
|
||||
status: 1,
|
||||
error: response.statusMessage};
|
||||
} else {
|
||||
self.mountStatus[mountData.mount_point] = { type: mountData.type,
|
||||
status: 1,
|
||||
error: t('files_external', 'Empty response from the server')};
|
||||
}
|
||||
self.mountStatus[mountData.mount_point] = {
|
||||
type: mountData.type,
|
||||
status: statusCode,
|
||||
id: mountData.id,
|
||||
error: statusMessage,
|
||||
userProvided: response.userProvided
|
||||
};
|
||||
}
|
||||
afterCallback(mountData, self.mountStatus[mountData.mount_point]);
|
||||
},
|
||||
|
@ -101,12 +101,17 @@ OCA.External.StatusManager = {
|
|||
// In this case the error is because mount point use Login credentials and don't exist in the session
|
||||
message = t('files_external', 'Couldn\'t access. Please logout and login to activate this mount point');
|
||||
} else {
|
||||
message = t('files_external', 'Couldn\'t get the information from the ownCloud server: {code} {type}', {code: jqxhr.status, type: error});
|
||||
message = t('files_external', 'Couldn\'t get the information from the ownCloud server: {code} {type}', {
|
||||
code: jqxhr.status,
|
||||
type: error
|
||||
});
|
||||
}
|
||||
self.mountStatus[mountData.mount_point] = { type: mountData.type,
|
||||
self.mountStatus[mountData.mount_point] = {
|
||||
type: mountData.type,
|
||||
status: 1,
|
||||
location: mountData.location,
|
||||
error: message};
|
||||
error: message
|
||||
};
|
||||
afterCallback(mountData, self.mountStatus[mountData.mount_point]);
|
||||
}
|
||||
});
|
||||
|
@ -164,20 +169,24 @@ OCA.External.StatusManager = {
|
|||
*/
|
||||
|
||||
manageMountPointError: function (name) {
|
||||
var self = this;
|
||||
this.getMountStatus($.proxy(function (allMountStatus) {
|
||||
if (typeof allMountStatus[name] !== 'undefined' || allMountStatus[name].status === 1) {
|
||||
if (allMountStatus.hasOwnProperty(name) && allMountStatus[name].status > 0 && allMountStatus[name].status < 7) {
|
||||
var mountData = allMountStatus[name];
|
||||
if (mountData.type === "system") {
|
||||
if (mountData.userProvided) {
|
||||
// personal mount whit credentials problems
|
||||
this.showCredentialsDialog(name, mountData);
|
||||
} else {
|
||||
OC.dialogs.confirm(t('files_external', 'There was an error with message: ') + mountData.error + '. Do you want to review mount point config in admin settings page?', t('files_external', 'External mount error'), function (e) {
|
||||
if (e === true) {
|
||||
window.location.href = OC.generateUrl('/settings/admin#files_external');
|
||||
OC.redirect(OC.generateUrl('/settings/admin#files_external'));
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
OC.dialogs.confirm(t('files_external', 'There was an error with message: ') + mountData.error + '. Do you want to review mount point config in personal settings page?', t('files_external', 'External mount error'), function (e) {
|
||||
if (e === true) {
|
||||
window.location.href = OC.generateUrl('/settings/personal#external-storage');
|
||||
OC.redirect(OC.generateUrl('/settings/personal#' + t('files_external', 'external-storage')));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -194,10 +203,10 @@ OCA.External.StatusManager = {
|
|||
processMountStatusIndividual: function (mountData, mountStatus) {
|
||||
|
||||
var mountPoint = mountData.mount_point;
|
||||
if (mountStatus.status === 1) {
|
||||
if (mountStatus.status > 0) {
|
||||
var trElement = FileList.findFileEl(OCA.External.StatusManager.Utils.jqSelEscape(mountPoint));
|
||||
|
||||
route = OCA.External.StatusManager.Utils.getIconRoute(trElement) + '-error';
|
||||
var route = OCA.External.StatusManager.Utils.getIconRoute(trElement) + '-error';
|
||||
|
||||
if (OCA.External.StatusManager.Utils.isCorrectViewAndRootFolder()) {
|
||||
OCA.External.StatusManager.Utils.showIconError(mountPoint, $.proxy(OCA.External.StatusManager.manageMountPointError, OCA.External.StatusManager), route);
|
||||
|
@ -265,9 +274,11 @@ OCA.External.StatusManager = {
|
|||
|
||||
var ajaxQueue = [];
|
||||
$.each(list, function (key, value) {
|
||||
var queueElement = {funcName: $.proxy(self.getMountStatusForMount, self),
|
||||
var queueElement = {
|
||||
funcName: $.proxy(self.getMountStatusForMount, self),
|
||||
funcArgs: [value,
|
||||
$.proxy(self.processMountStatusIndividual, self)]};
|
||||
$.proxy(self.processMountStatusIndividual, self)]
|
||||
};
|
||||
ajaxQueue.push(queueElement);
|
||||
});
|
||||
|
||||
|
@ -308,9 +319,11 @@ OCA.External.StatusManager = {
|
|||
if (recheck && value.mount_point in self.mountStatus) {
|
||||
delete self.mountStatus[value.mount_point];
|
||||
}
|
||||
var queueElement = {funcName: $.proxy(self.getMountStatusForMount, self),
|
||||
var queueElement = {
|
||||
funcName: $.proxy(self.getMountStatusForMount, self),
|
||||
funcArgs: [value,
|
||||
$.proxy(self.processMountStatusIndividual, self)]};
|
||||
$.proxy(self.processMountStatusIndividual, self)]
|
||||
};
|
||||
ajaxQueue.push(queueElement);
|
||||
});
|
||||
new OCA.External.StatusManager.RollingQueue(ajaxQueue, 4).runQueue();
|
||||
|
@ -330,8 +343,6 @@ OCA.External.StatusManager = {
|
|||
|
||||
var self = this;
|
||||
var mountListData = [];
|
||||
var recheckPersonalGlobal = false;
|
||||
var recheckAdminGlobal = false;
|
||||
|
||||
if (!self.mountStatus) {
|
||||
self.mountStatus = {};
|
||||
|
@ -355,6 +366,90 @@ OCA.External.StatusManager = {
|
|||
|
||||
self.processMountList(mountListData);
|
||||
self.launchPartialConnectivityCheck(mountListData, recheck);
|
||||
},
|
||||
|
||||
credentialsDialogTemplate:
|
||||
'<div id="files_external_div_form"><div>' +
|
||||
'<div>{{credentials_text}}</div>' +
|
||||
'<form>' +
|
||||
'<input type="text" name="username" placeholder="{{placeholder_username}}"/>' +
|
||||
'<input type="password" name="password" placeholder="{{placeholder_password}}"/>' +
|
||||
'</form>' +
|
||||
'</div></div>',
|
||||
|
||||
/**
|
||||
* Function to display custom dialog to enter credentials
|
||||
* @param mountPoint
|
||||
* @param mountData
|
||||
*/
|
||||
showCredentialsDialog: function (mountPoint, mountData) {
|
||||
var template = Handlebars.compile(OCA.External.StatusManager.credentialsDialogTemplate);
|
||||
var dialog = $(template({
|
||||
credentials_text: t('files_external', 'Please enter the credentials for the {mount} mount', {
|
||||
'mount': mountPoint
|
||||
}),
|
||||
placeholder_username: t('files_external', 'Username'),
|
||||
placeholder_password: t('files_external', 'Password')
|
||||
}));
|
||||
|
||||
$('body').append(dialog);
|
||||
|
||||
var apply = function () {
|
||||
var username = dialog.find('[name=username]').val();
|
||||
var password = dialog.find('[name=password]').val();
|
||||
var endpoint = OC.generateUrl('apps/files_external/userglobalstorages/{id}', {
|
||||
id: mountData.id
|
||||
});
|
||||
$('.oc-dialog-close').hide();
|
||||
$.ajax({
|
||||
type: 'PUT',
|
||||
url: endpoint,
|
||||
data: {
|
||||
backendOptions: {
|
||||
user: username,
|
||||
password: password
|
||||
}
|
||||
},
|
||||
success: function (data) {
|
||||
OC.Notification.showTemporary(t('files_external', 'Credentials saved'));
|
||||
dialog.ocdialog('close');
|
||||
/* Trigger status check again */
|
||||
OCA.External.StatusManager.recheckConnectivityForMount([OC.basename(data.mountPoint)], true);
|
||||
},
|
||||
error: function () {
|
||||
$('.oc-dialog-close').show();
|
||||
OC.Notification.showTemporary(t('files_external', 'Credentials saving failed'));
|
||||
}
|
||||
});
|
||||
return false;
|
||||
};
|
||||
|
||||
var ocdialogParams = {
|
||||
modal: true,
|
||||
title: t('files_external', 'Credentials required'),
|
||||
buttons: [{
|
||||
text: t('files_external', 'Save'),
|
||||
click: apply,
|
||||
closeOnEscape: true
|
||||
}],
|
||||
closeOnExcape: true
|
||||
};
|
||||
|
||||
dialog.ocdialog(ocdialogParams)
|
||||
.bind('ocdialogclose', function () {
|
||||
dialog.ocdialog('destroy').remove();
|
||||
});
|
||||
|
||||
dialog.find('form').on('submit', apply);
|
||||
dialog.find('form input:first').focus();
|
||||
dialog.find('form input').keyup(function (e) {
|
||||
if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) {
|
||||
$(e.target).closest('form').submit();
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -130,6 +130,16 @@ class ConfigAdapter implements IMountProvider {
|
|||
$impl = new FailedStorage(['exception' => $e]);
|
||||
}
|
||||
|
||||
try {
|
||||
$availability = $impl->getAvailability();
|
||||
if (!$availability['available']) {
|
||||
$impl = new FailedStorage(['exception' => null]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// propagate exception into filesystem
|
||||
$impl = new FailedStorage(['exception' => $e]);
|
||||
}
|
||||
|
||||
$mount = new MountPoint(
|
||||
$impl,
|
||||
'/' . $user->getUID() . '/files' . $storage->getMountPoint(),
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
namespace OCA\Files_External\Lib;
|
||||
|
||||
use OC\Files\Cache\CacheEntry;
|
||||
use OCP\Constants;
|
||||
use OCP\Files\Cache\ICache;
|
||||
|
||||
/**
|
||||
|
@ -40,7 +41,7 @@ class FailedCache implements ICache {
|
|||
'size' => 0,
|
||||
'mimetype' => 'httpd/unix-directory',
|
||||
'mimepart' => 'httpd',
|
||||
'permissions' => 0,
|
||||
'permissions' => Constants::PERMISSION_READ,
|
||||
'mtime' => time()
|
||||
]);
|
||||
} else {
|
||||
|
|
|
@ -27,4 +27,15 @@ use \OCP\Files\StorageNotAvailableException;
|
|||
* Authentication mechanism or backend has insufficient data
|
||||
*/
|
||||
class InsufficientDataForMeaningfulAnswerException extends StorageNotAvailableException {
|
||||
/**
|
||||
* StorageNotAvailableException constructor.
|
||||
*
|
||||
* @param string $message
|
||||
* @param int $code
|
||||
* @param \Exception $previous
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public function __construct($message = '', $code = self::STATUS_INDETERMINATE, \Exception $previous = null) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -314,4 +314,17 @@ class SMB extends Common {
|
|||
|| Server::NativeAvailable()
|
||||
) ? true : ['smbclient'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a storage for availability
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function test() {
|
||||
try {
|
||||
return parent::test();
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
namespace OCA\Files_external\Lib;
|
||||
|
||||
use OCA\Files_External\Lib\Auth\IUserProvided;
|
||||
use \OCA\Files_External\Lib\Backend\Backend;
|
||||
use \OCA\Files_External\Lib\Auth\AuthMechanism;
|
||||
|
||||
|
@ -406,6 +407,7 @@ class StorageConfig implements \JsonSerializable {
|
|||
if (!is_null($this->statusMessage)) {
|
||||
$result['statusMessage'] = $this->statusMessage;
|
||||
}
|
||||
$result['userProvided'] = $this->authMechanism instanceof IUserProvided;
|
||||
$result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAl) ? 'personal': 'system';
|
||||
return $result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue