Disable context menu actions for E2EE files and folders
authorKevin Ottens <kevin.ottens@nextcloud.com>
Thu, 20 Aug 2020 12:13:56 +0000 (14:13 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Thu, 20 Aug 2020 12:13:56 +0000 (14:13 +0200)
Those files and folders are not shareable and the "Edit" or "Open in
browser" actions will lead to showing an error in the web GUI. No need
to lead users there so just disable them.

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/gui/socketapi.cpp
src/gui/socketapi.h

index 47f03425a63abe86f620185d7c0d59fcd853cd83..f58c38e4e4be532035f9d0781c5d709baf1288ff 100644 (file)
@@ -718,11 +718,11 @@ void SocketApi::command_GET_STRINGS(const QString &argument, SocketListener *lis
     listener->sendMessage(QString("GET_STRINGS:END"));
 }
 
-void SocketApi::sendSharingContextMenuOptions(const FileData &fileData, SocketListener *listener)
+void SocketApi::sendSharingContextMenuOptions(const FileData &fileData, SocketListener *listener, bool enabled)
 {
     auto record = fileData.journalRecord();
     bool isOnTheServer = record.isValid();
-    auto flagString = isOnTheServer ? QLatin1String("::") : QLatin1String(":d:");
+    auto flagString = isOnTheServer && enabled ? QLatin1String("::") : QLatin1String(":d:");
 
     auto capabilities = fileData.folder->accountState()->account()->capabilities();
     auto theme = Theme::instance();
@@ -798,7 +798,8 @@ void SocketApi::command_GET_MENU_ITEMS(const QString &argument, OCC::SocketListe
     bool hasSeveralFiles = argument.contains(QLatin1Char('\x1e')); // Record Separator
     FileData fileData = hasSeveralFiles ? FileData{} : FileData::get(argument);
     bool isOnTheServer = fileData.journalRecord().isValid();
-    auto flagString = isOnTheServer ? QLatin1String("::") : QLatin1String(":d:");
+    const auto isE2eEncryptedPath = fileData.journalRecord()._isE2eEncrypted || !fileData.journalRecord()._e2eMangledName.isEmpty();
+    auto flagString = isOnTheServer && !isE2eEncryptedPath ? QLatin1String("::") : QLatin1String(":d:");
 
     if (fileData.folder && fileData.folder->accountState()->isConnected()) {
         DirectEditor* editor = getDirectEditorForLocalFile(fileData.localPath);
@@ -809,7 +810,7 @@ void SocketApi::command_GET_MENU_ITEMS(const QString &argument, OCC::SocketListe
             listener->sendMessage(QLatin1String("MENU_ITEM:OPEN_PRIVATE_LINK") + flagString + tr("Open in browser"));
         }
 
-        sendSharingContextMenuOptions(fileData, listener);
+        sendSharingContextMenuOptions(fileData, listener, !isE2eEncryptedPath);
     }
     listener->sendMessage(QString("GET_MENU_ITEMS:END"));
 }
index 4822629d5bdb516561cef2fc238f50d4267c5712..ddacc562092d14bff6e297934d6946c708968d31 100644 (file)
@@ -120,7 +120,7 @@ private:
     Q_INVOKABLE void command_GET_STRINGS(const QString &argument, SocketListener *listener);
 
     // Sends the context menu options relating to sharing to listener
-    void sendSharingContextMenuOptions(const FileData &fileData, SocketListener *listener);
+    void sendSharingContextMenuOptions(const FileData &fileData, SocketListener *listener, bool enabled);
 
     /** Send the list of menu item. (added in version 1.1)
      * argument is a list of files for which the menu should be shown, separated by '\x1e'