diff --git a/changelog/unreleased/11467 b/changelog/unreleased/11467 new file mode 100644 index 00000000000..f8b4dcb97a8 --- /dev/null +++ b/changelog/unreleased/11467 @@ -0,0 +1,6 @@ +Bugfix: Client stuck in `reconnecting` + +Properly handle errors during the update of the server settings. +Due to an unhandled result, the client could get stuck in a ` reconnecting` state. + +https://github.com/owncloud/client/pull/11467 diff --git a/src/gui/connectionvalidator.cpp b/src/gui/connectionvalidator.cpp index 610e2fb5363..9468f2ad0f5 100644 --- a/src/gui/connectionvalidator.cpp +++ b/src/gui/connectionvalidator.cpp @@ -238,13 +238,30 @@ void ConnectionValidator::slotAuthSuccess() const auto unsupportedServerError = [this] { _errors.append({tr("The configured server for this client is too old."), tr("Please update to the latest server and restart the client.")}); }; - connect(fetchSetting, &FetchServerSettingsJob::unknownServerDetected, unsupportedServerError); - connect(fetchSetting, &FetchServerSettingsJob::unsupportedServerDetected, [unsupportedServerError, this] { - unsupportedServerError(); - reportResult(ServerVersionMismatch); - }); - - connect(fetchSetting, &FetchServerSettingsJob::finishedSignal, this, [this] { reportResult(Connected); }); + connect( + fetchSetting, &FetchServerSettingsJob::finishedSignal, this, [fetchSetting, unsupportedServerError, this](FetchServerSettingsJob::Result result) { + switch (result) { + case FetchServerSettingsJob::Result::UnsupportedServer: + unsupportedServerError(); + reportResult(ServerVersionMismatch); + break; + case FetchServerSettingsJob::Result::InvalidCredentials: + reportResult(CredentialsWrong); + break; + case FetchServerSettingsJob::Result::TimeOut: + reportResult(Timeout); + break; + case FetchServerSettingsJob::Result::Success: + if (_account->serverSupportLevel() == Account::ServerSupportLevel::Unknown) { + unsupportedServerError(); + } + reportResult(Connected); + break; + case FetchServerSettingsJob::Result::Undefined: + reportResult(Undefined); + break; + } + }); fetchSetting->start(); return; diff --git a/src/gui/fetchserversettings.cpp b/src/gui/fetchserversettings.cpp index 656cdc57167..b7daa465f87 100644 --- a/src/gui/fetchserversettings.cpp +++ b/src/gui/fetchserversettings.cpp @@ -57,11 +57,25 @@ void FetchServerSettingsJob::start() _account->setHttp2Supported(reply->attribute(QNetworkRequest::Http2WasUsedAttribute).toBool()); } _account->setCapabilities({_account->url(), caps.toVariantMap()}); - if (checkServerInfo()) { - auto *userJob = new JsonApiJob(_account, QStringLiteral("ocs/v2.php/cloud/user"), SimpleNetworkJob::UrlQuery{}, QNetworkRequest{}, this); - userJob->setAuthenticationJob(isAuthJob()); - userJob->setTimeout(timeoutC); - connect(userJob, &JsonApiJob::finishedSignal, this, [userJob, this] { + // We cannot deal with servers < 10.0.0 + switch (_account->serverSupportLevel()) { + case Account::ServerSupportLevel::Unknown: + [[fallthrough]]; + case Account::ServerSupportLevel::Supported: + break; + case Account::ServerSupportLevel::Unsupported: + Q_EMIT finishedSignal(Result::UnsupportedServer); + return; + } + auto *userJob = new JsonApiJob(_account, QStringLiteral("ocs/v2.php/cloud/user"), SimpleNetworkJob::UrlQuery{}, QNetworkRequest{}, this); + userJob->setAuthenticationJob(isAuthJob()); + userJob->setTimeout(timeoutC); + connect(userJob, &JsonApiJob::finishedSignal, this, [userJob, this] { + if (userJob->timedOut()) { + Q_EMIT finishedSignal(Result::TimeOut); + } else if (userJob->httpStatusCode() == 401) { + Q_EMIT finishedSignal(Result::InvalidCredentials); + } else if (userJob->ocsSuccess()) { const auto userData = userJob->data().value(QStringLiteral("ocs")).toObject().value(QStringLiteral("data")).toObject(); const QString user = userData.value(QStringLiteral("id")).toString(); if (!user.isEmpty()) { @@ -72,9 +86,19 @@ void FetchServerSettingsJob::start() _account->setDavDisplayName(displayName); } runAsyncUpdates(); - Q_EMIT finishedSignal(); - }); - userJob->start(); + Q_EMIT finishedSignal(Result::Success); + } else { + Q_EMIT finishedSignal(Result::Undefined); + } + }); + userJob->start(); + } else { + if (job->timedOut()) { + Q_EMIT finishedSignal(Result::TimeOut); + } else if (job->httpStatusCode() == 401) { + Q_EMIT finishedSignal(Result::InvalidCredentials); + } else { + Q_EMIT finishedSignal(Result::Undefined); } } }); @@ -103,21 +127,6 @@ void FetchServerSettingsJob::runAsyncUpdates() jsonJob->start(); } } -bool FetchServerSettingsJob::checkServerInfo() -{ - // We cannot deal with servers < 10.0.0 - switch (_account->serverSupportLevel()) { - case Account::ServerSupportLevel::Supported: - break; - case Account::ServerSupportLevel::Unknown: - Q_EMIT unknownServerDetected(); - break; - case Account::ServerSupportLevel::Unsupported: - Q_EMIT unsupportedServerDetected(); - return false; - } - return true; -} bool FetchServerSettingsJob::isAuthJob() const { diff --git a/src/gui/fetchserversettings.h b/src/gui/fetchserversettings.h index 6b664498dbe..672dbc30f5f 100644 --- a/src/gui/fetchserversettings.h +++ b/src/gui/fetchserversettings.h @@ -25,32 +25,21 @@ class FetchServerSettingsJob : public QObject { Q_OBJECT public: + enum class Result { Success, TimeOut, InvalidCredentials, UnsupportedServer, Undefined }; + Q_ENUM(Result); FetchServerSettingsJob(const AccountPtr &account, QObject *parent); void start(); Q_SIGNALS: - /*** - * The version of the server is unsupported - */ - void unsupportedServerDetected(); - - /*** - * We failed to detect the server version - */ - void unknownServerDetected(); - - void finishedSignal(); + void finishedSignal(Result); private: void runAsyncUpdates(); - bool checkServerInfo(); - // returns whether the started jobs should be excluded from the retry queue bool isAuthJob() const; - const AccountPtr _account; };