]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Migrate http_user to webflow_user and dav_user.
authorCamila <hello@camila.codes>
Tue, 15 Aug 2023 16:20:18 +0000 (18:20 +0200)
committerCamila <hello@camila.codes>
Fri, 1 Sep 2023 13:09:28 +0000 (15:09 +0200)
- Add {} for single line condition, const auto and fix comments.
- Save the legacy account data first in _settingsMap, so the legacy config file
does not get changed in the migration process.
- Legacy dav_user should stay only as dav_user in the new config.
- Compare davUser and prettyName only when new user id needs to be retrieved.

Signed-off-by: Camila <hello@camila.codes>
src/gui/accountmanager.cpp
src/gui/creds/webflowcredentials.cpp
src/gui/userinfo.cpp

index 98b250b3f1f06288de690da5b303c2c3cd940433..520cd886edc17a62920b3585a5510d55868c0dcd 100644 (file)
@@ -107,8 +107,9 @@ AccountManager::AccountsRestoreResult AccountManager::restore(const bool alsoRes
                 if (auto accState = AccountState::loadFromSettings(acc, *settings)) {
                     auto jar = qobject_cast<CookieJar*>(acc->_am->cookieJar());
                     ASSERT(jar);
-                    if (jar)
+                    if (jar) {
                         jar->restore(acc->cookieJarPath());
+                    }
                     addAccountState(accState);
                 }
             }
@@ -303,6 +304,7 @@ void AccountManager::saveAccountState(AccountState *a)
 
 void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool saveCredentials)
 {
+    qCDebug(lcAccountManager) << "Saving settings to" << settings.fileName();
     settings.setValue(QLatin1String(versionC), maxAccountVersion);
     settings.setValue(QLatin1String(urlC), acc->_url.toString());
     settings.setValue(QLatin1String(davUserC), acc->_davUser);
@@ -332,8 +334,9 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s
         settings.setValue(QLatin1String(authTypeC), acc->_credentials->authType());
 
         // HACK: Save http_user also as user
-        if (acc->_settingsMap.contains(httpUserC))
+        if (acc->_settingsMap.contains(httpUserC)) {
             settings.setValue(userC, acc->_settingsMap.value(httpUserC));
+        }
     }
 
     // Save accepted certificates.
@@ -376,8 +379,8 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings)
     auto authType = settings.value(QLatin1String(authTypeC)).toString();
 
     // There was an account-type saving bug when 'skip folder config' was used
-    // See #5408. This attempts to fix up the "dummy" authType
-    if (authType == QLatin1String(dummyAuthTypeC)) {
+    // See owncloud#5408. This attempts to fix up the "dummy" or empty authType
+    if (authType == QLatin1String(dummyAuthTypeC) || authType.isEmpty()) {
         if (settings.contains(QLatin1String(httpUserC))) {
             authType = httpAuthTypeC;
         } else if (settings.contains(QLatin1String(shibbolethUserC))) {
@@ -401,15 +404,16 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings)
     // Migrate to webflow
     if (authType == QLatin1String(httpAuthTypeC)) {
         authType = webflowAuthTypeC;
-        settings.setValue(QLatin1String(authTypeC), authType);
+        acc->_settingsMap.insert(QLatin1String(authTypeC), authType);
 
         const auto settingsChildKeys = settings.childKeys();
         for (const auto &key : settingsChildKeys) {
-            if (!key.startsWith(httpAuthPrefix))
+            if (!key.startsWith(httpAuthPrefix)) {
                 continue;
+            }
+
             const auto newkey = QString::fromLatin1(webflowAuthPrefix).append(key.mid(5));
-            settings.setValue(newkey, settings.value((key)));
-            settings.remove(key);
+            acc->_settingsMap.insert(newkey, settings.value(key));
         }
     }
 
@@ -419,16 +423,16 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings)
     acc->_serverColor = settings.value(QLatin1String(serverColorC)).value<QColor>();
     acc->_serverTextColor = settings.value(QLatin1String(serverTextColorC)).value<QColor>();
     acc->_skipE2eeMetadataChecksumValidation = settings.value(QLatin1String(skipE2eeMetadataChecksumValidationC), {}).toBool();
-    acc->_davUser = settings.value(QLatin1String(davUserC), "").toString();
+    acc->_davUser = settings.value(QLatin1String(davUserC)).toString();
 
-    // We want to only restore settings for that auth type and the user value
     acc->_settingsMap.insert(QLatin1String(userC), settings.value(userC));
     acc->_displayName = settings.value(QLatin1String(displayNameC), "").toString();
-    QString authTypePrefix = authType + "_";
+    const QString authTypePrefix = authType + "_";
     const auto settingsChildKeys = settings.childKeys();
     for (const auto &key : settingsChildKeys) {
-        if (!key.startsWith(authTypePrefix))
+        if (!key.startsWith(authTypePrefix)) {
             continue;
+        }
         acc->_settingsMap.insert(key, settings.value(key));
     }
 
index 9958d1b7d55a75d622dc47b3731a8eba5101b699..f878a9bab78ae244ffb0a991ecc64333f98ee5dc 100644 (file)
@@ -180,29 +180,9 @@ void WebFlowCredentials::askFromUser() {
 void WebFlowCredentials::slotAskFromUserCredentialsProvided(const QString &user, const QString &pass, const QString &host) {
     Q_UNUSED(host)
 
-    // Compare the re-entered username case-insensitive and save the new value (avoid breaking the account)
-    // See issue: https://github.com/nextcloud/desktop/issues/1741
-    if (QString::compare(_user, user, Qt::CaseInsensitive) == 0) {
-        _user = user;
-    } else {
-        qCInfo(lcWebFlowCredentials()) << "Authed with the wrong user!";
-
-        QString msg = tr("Please login with the account: %1")
-                .arg(_account->prettyName());
-        _askDialog->setError(msg);
-
-        if (!_askDialog->isUsingFlow2()) {
-            QUrl url = _account->url();
-            QString path = url.path() + "/index.php/login/flow";
-            url.setPath(path);
-            _askDialog->setUrl(url);
-        }
-
-        return;
-    }
-
     qCInfo(lcWebFlowCredentials()) << "Obtained a new password";
 
+    _user = user;
     _password = pass;
     _ready = true;
     _credentialsValid = true;
index 1c111d7360a7e90259570ea366e1c59fa95bfa9f..15106b119030e8bb39f75c149830d924ad0b41a5 100644 (file)
@@ -110,17 +110,23 @@ void UserInfo::slotUpdateLastInfo(const QJsonDocument &json)
 
     AccountPtr account = _accountState->account();
 
-    // User Info
-    QString user = objData.value("id").toString();
-    if (!user.isEmpty()) {
-        account->setDavUser(user);
+    if (const auto newUserId = objData.value("id").toString();!newUserId.isEmpty()) {
+        if (QString::compare(account->davUser(), newUserId, Qt::CaseInsensitive) != 0) {
+            // TODO: the error message should be in the UI
+            qInfo() << "Authed with the wrong user! Please login with the account:" << account->prettyName();
+            if (const auto cred = account->credentials()) {
+                account->credentials()->askFromUser();
+            }
+            return;
+        }
+        account->setDavUser(newUserId);
     }
+
     QString displayName = objData.value("display-name").toString();
     if (!displayName.isEmpty()) {
         account->setDavDisplayName(displayName);
     }
 
-    // Quota
     auto objQuota = objData.value("quota").toObject();
     qint64 used = objQuota.value("used").toDouble();
     qint64 total = objQuota.value("quota").toDouble();
@@ -134,15 +140,15 @@ void UserInfo::slotUpdateLastInfo(const QJsonDocument &json)
     _jobRestartTimer.start(defaultIntervalT);
     _lastInfoReceived = QDateTime::currentDateTime();
 
-    // Avatar Image
     if(_fetchAvatarImage) {
         auto *job = new AvatarJob(account, account->davUser(), 128, this);
         job->setTimeout(20 * 1000);
         QObject::connect(job, &AvatarJob::avatarPixmap, this, &UserInfo::slotAvatarImage);
         job->start();
+        return;
     }
-    else
-        emit fetchedLastInfo(this);
+
+    emit fetchedLastInfo(this);
 }
 
 void UserInfo::slotAvatarImage(const QImage &img)