diff options
author | alex-z <blackslayer4@gmail.com> | 2022-10-13 11:24:16 +0300 |
---|---|---|
committer | allexzander <allexzander@users.noreply.github.com> | 2022-10-17 14:56:30 +0300 |
commit | 4e2ea9c00c4237521d99343167342969591760f9 (patch) | |
tree | 3906c6e588dc4c01f0c8fcc32d0e4f9bccaadaa1 | |
parent | 3c285b428aef1b8faaf878e07c6e6c43a01cfb00 (diff) |
Fix account not found when doing local file editing.
Signed-off-by: alex-z <blackslayer4@gmail.com>
-rw-r--r-- | src/gui/application.cpp | 4 | ||||
-rw-r--r-- | src/gui/folderman.cpp | 22 | ||||
-rw-r--r-- | src/gui/folderman.h | 2 |
3 files changed, 20 insertions, 8 deletions
diff --git a/src/gui/application.cpp b/src/gui/application.cpp index 6f891e022..a04ee2f13 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -763,7 +763,7 @@ void Application::handleEditLocally(const QUrl &url) const } // for a sample URL "nc://open/admin@nextcloud.lan:8080/Photos/lovely.jpg", QUrl::path would return "admin@nextcloud.lan:8080/Photos/lovely.jpg" - const auto accountDisplayName = pathSplit.takeFirst(); + const auto userId = pathSplit.takeFirst(); const auto fileRemotePath = pathSplit.join('/'); const auto urlQuery = QUrlQuery{url}; @@ -774,7 +774,7 @@ void Application::handleEditLocally(const QUrl &url) const qCWarning(lcApplication) << "Invalid URL for file local editing: missing token"; } - FolderMan::instance()->editFileLocally(accountDisplayName, fileRemotePath, token); + FolderMan::instance()->editFileLocally(userId, fileRemotePath, token); } QString substLang(const QString &lang) diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index d76a4fccd..cd4bac264 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -1422,7 +1422,7 @@ void FolderMan::setDirtyNetworkLimits() } } -void FolderMan::editFileLocally(const QString &accountDisplayName, const QString &relPath, const QString &token) +void FolderMan::editFileLocally(const QString &userId, const QString &relPath, const QString &token) { const auto showError = [this](const OCC::AccountStatePtr accountState, const QString &errorMessage, const QString &subject) { if (accountState && accountState->account()) { @@ -1449,15 +1449,27 @@ void FolderMan::editFileLocally(const QString &accountDisplayName, const QString if (token.isEmpty()) { qCWarning(lcFolderMan) << "Edit locally request is missing a valid token. Impossible to open the file."; - showError({}, tr("Edit locally request is not valid. Opening the file is forbidden."), accountDisplayName); + showError({}, tr("Edit locally request is not valid. Opening the file is forbidden."), userId); return; } - const auto accountFound = AccountManager::instance()->account(accountDisplayName); + const auto accountFound = [&userId]() { + for (const auto &account : AccountManager::instance()->accounts()) { + const auto isUserIdWithPort = userId.split(QLatin1Char(':')).size() > 1; + const auto port = isUserIdWithPort ? account->account()->url().port() : -1; + const auto portString = (port > 0 && port != 80 && port != 443) ? QStringLiteral(":%1").arg(port) : QStringLiteral(""); + const QString davUserId = QStringLiteral("%1@%2").arg(account->account()->davUser(), account->account()->url().host()) + portString; + + if (davUserId == userId) { + return account; + } + } + return AccountStatePtr{}; + }(); if (!accountFound) { - qCWarning(lcFolderMan) << "Could not find an account " << accountDisplayName << " to edit file " << relPath << " locally."; - showError(accountFound, tr("Could not find an account for local editing"), accountDisplayName); + qCWarning(lcFolderMan) << "Could not find an account " << userId << " to edit file " << relPath << " locally."; + showError(accountFound, tr("Could not find an account for local editing"), userId); return; } diff --git a/src/gui/folderman.h b/src/gui/folderman.h index 2c9b920e6..444eedff8 100644 --- a/src/gui/folderman.h +++ b/src/gui/folderman.h @@ -214,7 +214,7 @@ public: void setDirtyNetworkLimits(); /** opens a file with default app, if the file is present **/ - void editFileLocally(const QString &accountDisplayName, const QString &relPath, const QString &token); + void editFileLocally(const QString &userId, const QString &relPath, const QString &token); signals: /** |