[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp

Ashod Nakashian (via logerrit) logerrit at kemper.freedesktop.org
Sat Aug 17 02:45:10 UTC 2019


 wsd/ClientSession.cpp  |   24 +++++++++++++++---------
 wsd/DocumentBroker.cpp |    1 -
 2 files changed, 15 insertions(+), 10 deletions(-)

New commits:
commit 6d94b35c35bd30e10963bc64bea9ca4e1e253a81
Author:     Ashod Nakashian <ashod.nakashian at collabora.co.uk>
AuthorDate: Tue Aug 13 20:03:40 2019 -0400
Commit:     Ashod Nakashian <ashnakash at gmail.com>
CommitDate: Sat Aug 17 04:44:51 2019 +0200

    wsd: block save of read-only documents
    
    WSD is responsible for checking permissions,
    as we do with DisableCopy and DisablePrint,
    but until now we allowed saving even on
    read-only documents.
    
    The reason, it seems, was that when we failed
    to save a document due to disk space, we
    set documents as read-only. So presumably
    we still had to allow saving, so users
    preserve their latest changes when the disk
    has some free space. Meanwhile, we didn't
    let users make further changes. At least
    this seems to be a reasonable explanation.
    
    Unfortunately this meant that we allowed
    saving when the user had no permission,
    or the document was loaded as read-only.
    
    Now we no longer mark documents that fail
    to save due to disk-space limitation as
    read-only, and instead expect the client
    to notify the user and (possibly) block
    further edits. And read-only documents,
    or users without write permission, are
    no longer allowed to get saved.
    
    This change makes sure that the ctrl+s
    shortcut respects the read-only flag,
    while we allow clients to disable
    the default handler and decide what to
    do (although now they cannot force saving
    when the user has no permission, something
    they could do previously).
    
    Change-Id: I16c3b75fd3e54435d750948a25afd6f71c9f963b
    Reviewed-on: https://gerrit.libreoffice.org/77594
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 5dbcaa7d0..56f2a3443 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -499,16 +499,23 @@ bool ClientSession::_handleInput(const char *buffer, int length)
     }
     else if (tokens[0] == "save")
     {
-        int dontTerminateEdit = 1;
-        if (tokens.size() > 1)
-            getTokenInteger(tokens[1], "dontTerminateEdit", dontTerminateEdit);
+        if (isReadOnly())
+        {
+            LOG_WRN("The document is read-only, cannot save.");
+        }
+        else
+        {
+            int dontTerminateEdit = 1;
+            if (tokens.size() > 1)
+                getTokenInteger(tokens[1], "dontTerminateEdit", dontTerminateEdit);
 
-        // Don't save unmodified docs by default, or when read-only.
-        int dontSaveIfUnmodified = 1;
-        if (!isReadOnly() && tokens.size() > 2)
-            getTokenInteger(tokens[2], "dontSaveIfUnmodified", dontSaveIfUnmodified);
+            // Don't save unmodified docs by default.
+            int dontSaveIfUnmodified = 1;
+            if (tokens.size() > 2)
+                getTokenInteger(tokens[2], "dontSaveIfUnmodified", dontSaveIfUnmodified);
 
-        docBroker->sendUnoSave(getId(), dontTerminateEdit != 0, dontSaveIfUnmodified != 0);
+            docBroker->sendUnoSave(getId(), dontTerminateEdit != 0, dontSaveIfUnmodified != 0);
+        }
     }
     else if (tokens[0] == "savetostorage")
     {
@@ -1003,7 +1010,6 @@ bool ClientSession::handleKitToClientMessage(const char* buffer, const int lengt
 #endif
 
     const auto& tokens = payload->tokens();
-
     if (tokens[0] == "unocommandresult:")
     {
         const std::string stringMsg(buffer, length);
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 5105e426d..026bdda08 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -975,7 +975,6 @@ bool DocumentBroker::saveToStorageInternal(const std::string& sessionId,
         // Make everyone readonly and tell everyone that storage is low on diskspace.
         for (const auto& sessionIt : _sessions)
         {
-            sessionIt.second->setReadOnly();
             sessionIt.second->sendTextFrame("error: cmd=storage kind=savediskfull");
         }
     }


More information about the Libreoffice-commits mailing list