allow setting user provided global credentials trough credentials popup

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2019-09-09 17:14:21 +02:00
parent 1d51b297a9
commit 603655341e
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
3 changed files with 15 additions and 4 deletions

View File

@ -93,7 +93,8 @@ OCA.Files_External.StatusManager = {
status: statusCode, status: statusCode,
id: mountData.id, id: mountData.id,
error: statusMessage, error: statusMessage,
userProvided: response.userProvided userProvided: response.userProvided,
authMechanism: response.authMechanism
}; };
} }
afterCallback(mountData, self.mountStatus[mountData.mount_point]); afterCallback(mountData, self.mountStatus[mountData.mount_point]);
@ -178,7 +179,7 @@ OCA.Files_External.StatusManager = {
if (allMountStatus.hasOwnProperty(name) && allMountStatus[name].status > 0 && allMountStatus[name].status < 7) { if (allMountStatus.hasOwnProperty(name) && allMountStatus[name].status > 0 && allMountStatus[name].status < 7) {
var mountData = allMountStatus[name]; var mountData = allMountStatus[name];
if (mountData.type === "system") { if (mountData.type === "system") {
if (mountData.userProvided) { if (mountData.userProvided || mountData.authMechanism === 'password::global::user') {
// personal mount whit credentials problems // personal mount whit credentials problems
this.showCredentialsDialog(name, mountData); this.showCredentialsDialog(name, mountData);
} else { } else {

View File

@ -27,6 +27,7 @@ namespace OCA\Files_External\Controller;
use OCA\Files_External\Lib\Auth\AuthMechanism; use OCA\Files_External\Lib\Auth\AuthMechanism;
use OCA\Files_External\Lib\Auth\IUserProvided; use OCA\Files_External\Lib\Auth\IUserProvided;
use OCA\Files_External\Lib\Auth\Password\UserGlobalAuth;
use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
use OCP\ILogger; use OCP\ILogger;
use \OCP\IRequest; use \OCP\IRequest;
@ -156,7 +157,7 @@ class UserGlobalStoragesController extends StoragesController {
try { try {
$storage = $this->service->getStorage($id); $storage = $this->service->getStorage($id);
$authMechanism = $storage->getAuthMechanism(); $authMechanism = $storage->getAuthMechanism();
if ($authMechanism instanceof IUserProvided) { if ($authMechanism instanceof IUserProvided || $authMechanism instanceof UserGlobalAuth) {
$authMechanism->saveBackendOptions($this->userSession->getUser(), $id, $backendOptions); $authMechanism->saveBackendOptions($this->userSession->getUser(), $id, $backendOptions);
$authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser()); $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
} else { } else {

View File

@ -44,11 +44,20 @@ class UserGlobalAuth extends AuthMechanism {
$this $this
->setIdentifier('password::global::user') ->setIdentifier('password::global::user')
->setVisibility(BackendService::VISIBILITY_ADMIN) ->setVisibility(BackendService::VISIBILITY_DEFAULT)
->setScheme(self::SCHEME_PASSWORD) ->setScheme(self::SCHEME_PASSWORD)
->setText($l->t('Global credentials, user entered')); ->setText($l->t('Global credentials, user entered'));
} }
public function saveBackendOptions(IUser $user, $id, $backendOptions) {
// make sure we're not setting any unexpected keys
$credentials = [
'user' => $backendOptions['user'],
'password' => $backendOptions['password'],
];
$this->credentialsManager->store($user->getUID(), self::CREDENTIALS_IDENTIFIER, $credentials);
}
public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
if ($user === null) { if ($user === null) {
throw new InsufficientDataForMeaningfulAnswerException('No credentials saved'); throw new InsufficientDataForMeaningfulAnswerException('No credentials saved');