From: Claudio Cambra Date: Fri, 9 Dec 2022 17:19:21 +0000 (+0100) Subject: Don't allow encryption if account is not correctly configured for it X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~11^2~70^2~6 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=bf1f718a6561a496f7de259269fa9663d241b3f4;p=nextcloud-desktop.git Don't allow encryption if account is not correctly configured for it Signed-off-by: Claudio Cambra --- diff --git a/src/gui/socketapi/socketapi.cpp b/src/gui/socketapi/socketapi.cpp index 48f66f4cc..541063c8f 100644 --- a/src/gui/socketapi/socketapi.cpp +++ b/src/gui/socketapi/socketapi.cpp @@ -512,15 +512,35 @@ void SocketApi::processEncryptRequest(const QString &localFile) Q_ASSERT(QFileInfo(localFile).isDir()); const auto fileData = FileData::get(localFile); - const auto folder = fileData.folder; - const auto account = folder->accountState()->account(); - const auto rec = fileData.journalRecord(); + const auto folder = fileData.folder; Q_ASSERT(folder); + + const auto account = folder->accountState()->account(); Q_ASSERT(account); + + const auto rec = fileData.journalRecord(); Q_ASSERT(rec.isValid()); - auto choppedPath = rec._path.chopped(1); + if (!account->e2e() || account->e2e()->_mnemonic.isEmpty()) { + const int ret = QMessageBox::critical(nullptr, + tr("Failed to encrypt folder at \"%1\"").arg(fileData.folderRelativePath), + tr("The account %1 does not have end-to-end encryption configured. " + "Please configure this in your account settings to enable folder encryption.").arg(account->prettyName())); + Q_UNUSED(ret) + return; + } + + auto path = rec._path; + // Folder records have directory paths in Foo/Bar/ convention... + // But EncryptFolderJob expects directory path Foo/Bar convention + auto choppedPath = path; + if (choppedPath.endsWith('/') && choppedPath != QStringLiteral("/")) { + choppedPath.chop(1); + } + if (choppedPath.startsWith('/') && choppedPath != QStringLiteral("/")) { + choppedPath = choppedPath.mid(1); + } auto job = new OCC::EncryptFolderJob(account, folder->journalDb(), choppedPath, rec.numericFileId(), this); connect(job, &OCC::EncryptFolderJob::finished, this, [fileData, job](const int status) { @@ -532,7 +552,7 @@ void SocketApi::processEncryptRequest(const QString &localFile) } }); job->setProperty(encryptJobPropertyFolder, QVariant::fromValue(folder)); - job->setProperty(encryptJobPropertyPath, QVariant::fromValue(rec._path)); + job->setProperty(encryptJobPropertyPath, QVariant::fromValue(path)); job->start(); }