Skip to content

Commit

Permalink
Merge pull request #7019 from nextcloud/backport/7016/stable-3.12
Browse files Browse the repository at this point in the history
[stable-3.12] Bugfix/hide encrypt from context menu
  • Loading branch information
mgallien authored Aug 22, 2024
2 parents c7dca92 + b79794b commit 3741012
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/gui/socketapi/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ void SocketApi::slotReadSocket()
return out;
}();

const auto argument = argPos != -1 ? line.midRef(argPos + 1) : QStringRef();
const auto argument = QString{argPos != -1 ? line.mid(argPos + 1) : QString()};
if (command.startsWith("ASYNC_")) {
auto arguments = argument.split('|');
const auto arguments = argument.split('|');
if (arguments.size() != 2) {
listener->sendError(QStringLiteral("argument count is wrong"));
return;
Expand All @@ -400,7 +400,7 @@ void SocketApi::slotReadSocket()
auto jobId = arguments[0];

auto socketApiJob = QSharedPointer<SocketApiJob>(
new SocketApiJob(jobId.toString(), listener, json), &QObject::deleteLater);
new SocketApiJob(jobId, listener, json), &QObject::deleteLater);
if (indexOfMethod != -1) {
staticMetaObject.method(indexOfMethod)
.invoke(this, Qt::QueuedConnection,
Expand All @@ -414,7 +414,7 @@ void SocketApi::slotReadSocket()
QJsonParseError error{};
const auto json = QJsonDocument::fromJson(argument.toUtf8(), &error).object();
if (error.error != QJsonParseError::NoError) {
qCWarning(lcSocketApi()) << "Invalid json" << argument.toString() << error.errorString();
qCWarning(lcSocketApi()) << "Invalid json" << argument << error.errorString();
listener->sendError(error.errorString());
return;
}
Expand All @@ -432,15 +432,15 @@ void SocketApi::slotReadSocket()
if (indexOfMethod != -1) {
ASSERT(thread() == QThread::currentThread())
staticMetaObject.method(indexOfMethod)
.invoke(this, Qt::QueuedConnection, Q_ARG(QString, argument.toString()),
.invoke(this, Qt::QueuedConnection, Q_ARG(QString, argument),
Q_ARG(SocketListener *, listener.data()));
}
} else {
if (indexOfMethod != -1) {
// to ensure that listener is still valid we need to call it with Qt::DirectConnection
ASSERT(thread() == QThread::currentThread())
staticMetaObject.method(indexOfMethod)
.invoke(this, Qt::DirectConnection, Q_ARG(QString, argument.toString()),
.invoke(this, Qt::DirectConnection, Q_ARG(QString, argument),
Q_ARG(SocketListener *, listener.data()));
}
}
Expand Down Expand Up @@ -1226,7 +1226,8 @@ void SocketApi::sendEncryptFolderCommandMenuEntries(const QFileInfo &fileInfo,
!fileData.folder->accountState()->account() ||
!fileData.folder->accountState()->account()->capabilities().clientSideEncryptionAvailable() ||
!fileInfo.isDir() ||
isE2eEncryptedPath) {
isE2eEncryptedPath ||
!fileData.isFolderEmpty(fileInfo)) {
return;
}

Expand All @@ -1241,7 +1242,7 @@ void SocketApi::sendEncryptFolderCommandMenuEntries(const QFileInfo &fileInfo,
ancestor = ancestor.parentFolder();
}

if (!anyAncestorEncrypted) {
if (!anyAncestorEncrypted && !fileData.parentFolder().journalRecord().isValid()) {
const auto isOnTheServer = fileData.journalRecord().isValid();
const auto flagString = isOnTheServer ? QLatin1String("::") : QLatin1String(":d:");
listener->sendMessage(QStringLiteral("MENU_ITEM:ENCRYPT") + flagString + tr("Encrypt"));
Expand Down Expand Up @@ -1312,6 +1313,15 @@ QString SocketApi::FileData::folderRelativePathNoVfsSuffix() const
return result;
}

bool SocketApi::FileData::isFolderEmpty(const QFileInfo &fileInfo) const
{
if (fileInfo.isDir()) {
const auto nativeFolder = QDir{localPath};
return nativeFolder.isEmpty();
}
return false;
}

SyncFileStatus SocketApi::FileData::syncFileStatus() const
{
if (!folder)
Expand Down
2 changes: 2 additions & 0 deletions src/gui/socketapi/socketapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ private slots:
// Relative path of the file locally, without any vfs suffix
[[nodiscard]] QString folderRelativePathNoVfsSuffix() const;

[[nodiscard]] bool isFolderEmpty(const QFileInfo &fileInfo) const;

Folder *folder = nullptr;
// Absolute path of the file locally. (May be a virtual file)
QString localPath;
Expand Down

0 comments on commit 3741012

Please sign in to comment.