Skip to content

Commit

Permalink
Fix handle local editing by searching for a proper account by userId.
Browse files Browse the repository at this point in the history
Signed-off-by: allexzander <blackslayer4@gmail.com>
  • Loading branch information
allexzander committed Oct 14, 2022
1 parent 8b4b916 commit 4286099
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,10 +762,10 @@ 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('/');

FolderMan::instance()->editFileLocally(accountDisplayName, fileRemotePath);
FolderMan::instance()->editFileLocally(userId, fileRemotePath);
}

QString substLang(const QString &lang)
Expand Down
17 changes: 13 additions & 4 deletions src/gui/folderman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ void FolderMan::setDirtyNetworkLimits()
}
}

void FolderMan::editFileLocally(const QString &accountDisplayName, const QString &relPath)
void FolderMan::editFileLocally(const QString &userId, const QString &relPath)
{
const auto showError = [this](const OCC::AccountStatePtr accountState, const QString &errorMessage, const QString &subject) {
if (accountState && accountState->account()) {
Expand All @@ -1447,11 +1447,20 @@ void FolderMan::editFileLocally(const QString &accountDisplayName, const QString
messageBox->raise();
};

const auto accountFound = AccountManager::instance()->account(accountDisplayName);
const auto accountFound = [&userId]() {
for (const auto &account : AccountManager::instance()->accounts()) {
const auto userId = QStringLiteral("%1@%2").arg(account->account()->davUser(), account->account()->url().host());

if (userId == 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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/folderman.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class FolderMan : public QObject
void setDirtyNetworkLimits();

/** opens a file with default app, if the file is present **/
void editFileLocally(const QString &accountDisplayName, const QString &relPath);
void editFileLocally(const QString &userId, const QString &relPath);

signals:
/**
Expand Down
16 changes: 1 addition & 15 deletions src/libsync/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,7 @@ void Account::setAvatar(const QImage &img)

QString Account::displayName() const
{
const auto userName = [this]() {
if (!_davUser.isEmpty()) {
return _davUser;
}

const auto credentialsUserSplit = credentials()->user().split(QLatin1Char('@'), Qt::SkipEmptyParts);

if (credentialsUserSplit.size() > 1) {
return credentialsUserSplit.first();
}

return credentials()->user();
};

QString dn = QString("%1@%2").arg(userName(), _url.host());
QString dn = QString("%1@%2").arg(credentials()->user(), _url.host());
int port = url().port();
if (port > 0 && port != 80 && port != 443) {
dn.append(QLatin1Char(':'));
Expand Down

0 comments on commit 4286099

Please sign in to comment.