Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/hide encrypt from context menu #7016

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/gui/socketapi/socketapi.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/gui/socketapi/socketapi.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/socketapi/socketapi.cpp

File src/gui/socketapi/socketapi.cpp does not conform to Custom style guidelines. (lines 451, 459, 1245)
* Copyright (C) by Dominik Schmidt <dev@dominik-schmidt.de>
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
* Copyright (C) by Roeland Jago Douma <roeland@famdouma.nl>
Expand Down Expand Up @@ -403,9 +403,9 @@
return out;
}();

const auto argument = argPos != -1 ? line.mid(argPos + 1) : QStringView();
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 @@ -416,7 +416,7 @@
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 @@ -430,7 +430,7 @@
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 @@ -448,15 +448,15 @@
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 @@ -1242,7 +1242,8 @@
!fileData.folder->accountState()->account() ||
!fileData.folder->accountState()->account()->capabilities().clientSideEncryptionAvailable() ||
!FileSystem::isDir(fileInfo.absoluteFilePath()) ||
isE2eEncryptedPath) {
isE2eEncryptedPath ||
!fileData.isFolderEmpty()) {
return;
}

Expand All @@ -1257,7 +1258,7 @@
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 @@ -1328,6 +1329,15 @@
return result;
}

bool SocketApi::FileData::isFolderEmpty() const
{
if (FileSystem::isDir(localPath)) {
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 @@ -15,7 +15,7 @@
#ifndef SOCKETAPI_H
#define SOCKETAPI_H

#include "common/syncfilestatus.h"

Check failure on line 18 in src/gui/socketapi/socketapi.h

View workflow job for this annotation

GitHub Actions / build

src/gui/socketapi/socketapi.h:18:10 [clang-diagnostic-error]

'common/syncfilestatus.h' file not found
#include "common/syncjournalfilerecord.h"
#include "syncfileitem.h"

Expand Down Expand Up @@ -98,6 +98,8 @@
// Relative path of the file locally, without any vfs suffix
[[nodiscard]] QString folderRelativePathNoVfsSuffix() const;

[[nodiscard]] bool isFolderEmpty() const;

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