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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Thu Jun 14 15:01:00 UTC 2018


 wsd/ClientSession.cpp  |   35 +++++++++++++++++++++++++++++++++++
 wsd/DocumentBroker.cpp |   13 ++++++++++++-
 wsd/DocumentBroker.hpp |    9 +++++++++
 wsd/Storage.cpp        |   20 +++++++++++++++++---
 wsd/Storage.hpp        |   24 ++++++++++++++++++++----
 5 files changed, 93 insertions(+), 8 deletions(-)

New commits:
commit b3bdd5786d48da4b4073d05b9eddba9d242ac6bf
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Tue Apr 24 12:09:37 2018 -0400

    wsd: support optional forcing tracking changes at load
    
    Since changing the tracking state is done by toggling,
    we need to wait to get the current state at load time
    before we can tell whether we need to toggle it or not.
    
    Change-Id: Ib5a2639b2acf3874c191971eedf9a3bebcefebad
    Reviewed-on: https://gerrit.libreoffice.org/53415
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 8203b2a34..70ee741fa 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -19,6 +19,7 @@
 
 #include "DocumentBroker.hpp"
 #include "LOOLWSD.hpp"
+#include "Storage.hpp"
 #include <common/Common.hpp>
 #include <common/Log.hpp>
 #include <common/Protocol.hpp>
@@ -738,6 +739,40 @@ bool ClientSession::handleKitToClientMessage(const char* buffer, const int lengt
         {
             docBroker->setModified(stateTokens[1] == "true");
         }
+        else
+        {
+            // Set the initial settings per the user's request.
+            const std::pair<std::string, std::string> unoStatePair = LOOLProtocol::split(tokens[1], '=');
+
+            if (!docBroker->isInitialSettingSet(unoStatePair.first))
+            {
+                docBroker->setInitialSetting(unoStatePair.first);
+                if (unoStatePair.first == ".uno:TrackChanges")
+                {
+                    if ((unoStatePair.second == "true" &&
+                         _wopiFileInfo->_disableChangeTrackingRecord == WopiStorage::WOPIFileInfo::TriState::True) ||
+                        (unoStatePair.second == "false" &&
+                         _wopiFileInfo->_disableChangeTrackingRecord == WopiStorage::WOPIFileInfo::TriState::False))
+                    {
+                        // Toggle the TrackChanges state.
+                        LOG_DBG("Forcing " << unoStatePair.first << " toggle per user settings.");
+                        forwardToChild("uno .uno:TrackChanges", docBroker);
+                    }
+                }
+                else if (unoStatePair.first == ".uno:ShowTrackedChanges")
+                {
+                    if ((unoStatePair.second == "true" &&
+                         _wopiFileInfo->_disableChangeTrackingShow == WopiStorage::WOPIFileInfo::TriState::True) ||
+                        (unoStatePair.second == "false" &&
+                         _wopiFileInfo->_disableChangeTrackingShow == WopiStorage::WOPIFileInfo::TriState::False))
+                    {
+                        // Toggle the ShowTrackChanges state.
+                        LOG_DBG("Forcing " << unoStatePair.first << " toggle per user settings.");
+                        forwardToChild("uno .uno:ShowTrackedChanges", docBroker);
+                    }
+                }
+            }
+        }
     }
 
     if (!_isDocPasswordProtected)
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 1006dc2dc..4d465a39d 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -502,12 +502,13 @@ bool DocumentBroker::load(const std::shared_ptr<ClientSession>& session, const s
         wopiInfo->set("HidePrintOption", wopifileinfo->_hidePrintOption);
         wopiInfo->set("HideSaveOption", wopifileinfo->_hideSaveOption);
         wopiInfo->set("HideExportOption", wopifileinfo->_hideExportOption);
-        wopiInfo->set("HideChangeTrackingControls", wopifileinfo->_hideChangeTrackingControls);
         wopiInfo->set("DisablePrint", wopifileinfo->_disablePrint);
         wopiInfo->set("DisableExport", wopifileinfo->_disableExport);
         wopiInfo->set("DisableCopy", wopifileinfo->_disableCopy);
         wopiInfo->set("DisableInactiveMessages", wopifileinfo->_disableInactiveMessages);
         wopiInfo->set("UserCanNotWriteRelative", wopifileinfo->_userCanNotWriteRelative);
+        if (wopifileinfo->_hideChangeTrackingControls != WopiStorage::WOPIFileInfo::TriState::Unset)
+            wopiInfo->set("HideChangeTrackingControls", wopifileinfo->_hideChangeTrackingControls == WopiStorage::WOPIFileInfo::TriState::True);
 
         std::ostringstream ossWopiInfo;
         wopiInfo->stringify(ossWopiInfo);
@@ -1447,6 +1448,16 @@ void DocumentBroker::setModified(const bool value)
     _tileCache->setUnsavedChanges(value);
 }
 
+bool DocumentBroker::isInitialSettingSet(const std::string& name) const
+{
+    return _isInitialStateSet.find(name) != _isInitialStateSet.end();
+}
+
+void DocumentBroker::setInitialSetting(const std::string& name)
+{
+    _isInitialStateSet.emplace(name);
+}
+
 bool DocumentBroker::forwardToChild(const std::string& viewId, const std::string& message)
 {
     assertCorrectThread();
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index fc3cb095d..92c39b2e5 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -344,6 +344,12 @@ public:
     /// Sends a message to all sessions
     void broadcastMessage(const std::string& message);
 
+    /// Returns true iff an initial setting by the given name is already initialized.
+    bool isInitialSettingSet(const std::string& name) const;
+
+    /// Sets the initialization flag of a given initial setting.
+    void setInitialSetting(const std::string& name);
+
 private:
 
     /// Shutdown all client connections with the given reason.
@@ -423,6 +429,9 @@ private:
     /// All session of this DocBroker by ID.
     std::map<std::string, std::shared_ptr<ClientSession> > _sessions;
 
+    /// If we set the user-requested inital (on load) settings to be forced.
+    std::set<std::string> _isInitialStateSet;
+
     std::unique_ptr<StorageBase> _storage;
     std::unique_ptr<TileCache> _tileCache;
     std::atomic<bool> _markToDestroy;
diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index ca306a340..0b3ed3545 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -446,13 +446,15 @@ std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(const Au
     bool hidePrintOption = false;
     bool hideSaveOption = false;
     bool hideExportOption = false;
-    bool hideChangeTrackingControls = false;
     bool disablePrint = false;
     bool disableExport = false;
     bool disableCopy = false;
     bool disableInactiveMessages = false;
     std::string lastModifiedTime;
     bool userCanNotWriteRelative = true;
+    WOPIFileInfo::TriState disableChangeTrackingRecord = WOPIFileInfo::TriState::Unset;
+    WOPIFileInfo::TriState disableChangeTrackingShow = WOPIFileInfo::TriState::Unset;
+    WOPIFileInfo::TriState hideChangeTrackingControls = WOPIFileInfo::TriState::Unset;
 
     LOG_DBG("WOPI::CheckFileInfo returned: " << resMsg << ". Call duration: " << callDuration.count() << "s");
     Poco::JSON::Object::Ptr object;
@@ -470,7 +472,6 @@ std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(const Au
         JsonUtil::findJSONValue(object, "HidePrintOption", hidePrintOption);
         JsonUtil::findJSONValue(object, "HideSaveOption", hideSaveOption);
         JsonUtil::findJSONValue(object, "HideExportOption", hideExportOption);
-        JsonUtil::findJSONValue(object, "hideChangeTrackingControls", hideChangeTrackingControls);
         JsonUtil::findJSONValue(object, "EnableOwnerTermination", enableOwnerTermination);
         JsonUtil::findJSONValue(object, "DisablePrint", disablePrint);
         JsonUtil::findJSONValue(object, "DisableExport", disableExport);
@@ -478,6 +479,13 @@ std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(const Au
         JsonUtil::findJSONValue(object, "DisableInactiveMessages", disableInactiveMessages);
         JsonUtil::findJSONValue(object, "LastModifiedTime", lastModifiedTime);
         JsonUtil::findJSONValue(object, "UserCanNotWriteRelative", userCanNotWriteRelative);
+        bool booleanFlag = false;
+        if (JsonUtil::findJSONValue(object, "DisableChangeTrackingRecord", booleanFlag))
+            disableChangeTrackingRecord = (booleanFlag ? WOPIFileInfo::TriState::True : WOPIFileInfo::TriState::False);
+        if (JsonUtil::findJSONValue(object, "DisableChangeTrackingShow", booleanFlag))
+            disableChangeTrackingShow = (booleanFlag ? WOPIFileInfo::TriState::True : WOPIFileInfo::TriState::False);
+        if (JsonUtil::findJSONValue(object, "HideChangeTrackingControls", booleanFlag))
+            hideChangeTrackingControls = (booleanFlag ? WOPIFileInfo::TriState::True : WOPIFileInfo::TriState::False);
     }
     else
     {
@@ -488,7 +496,13 @@ std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(const Au
     const Poco::Timestamp modifiedTime = iso8601ToTimestamp(lastModifiedTime, "LastModifiedTime");
     _fileInfo = FileInfo({filename, ownerId, modifiedTime, size});
 
-    return std::unique_ptr<WopiStorage::WOPIFileInfo>(new WOPIFileInfo({userId, userName, userExtraInfo, watermarkText, canWrite, postMessageOrigin, hidePrintOption, hideSaveOption, hideExportOption, hideChangeTrackingControls, enableOwnerTermination, disablePrint, disableExport, disableCopy, disableInactiveMessages, userCanNotWriteRelative, callDuration}));
+    return std::unique_ptr<WopiStorage::WOPIFileInfo>(new WOPIFileInfo(
+        {userId, userName, userExtraInfo, watermarkText, canWrite,
+         postMessageOrigin, hidePrintOption, hideSaveOption, hideExportOption,
+         enableOwnerTermination, disablePrint, disableExport, disableCopy,
+         disableInactiveMessages, userCanNotWriteRelative,
+         disableChangeTrackingShow, disableChangeTrackingRecord,
+         hideChangeTrackingControls, callDuration}));
 }
 
 /// uri format: http://server/<...>/wopi*/files/<id>/content
diff --git a/wsd/Storage.hpp b/wsd/Storage.hpp
index 1d96afd36..d033a846b 100644
--- a/wsd/Storage.hpp
+++ b/wsd/Storage.hpp
@@ -259,6 +259,13 @@ public:
     class WOPIFileInfo
     {
     public:
+        enum class TriState
+        {
+            False,
+            True,
+            Unset
+        };
+
         WOPIFileInfo(const std::string& userid,
                      const std::string& username,
                      const std::string& userExtraInfo,
@@ -268,13 +275,15 @@ public:
                      const bool hidePrintOption,
                      const bool hideSaveOption,
                      const bool hideExportOption,
-                     const bool hideChangeTrackingControls,
                      const bool enableOwnerTermination,
                      const bool disablePrint,
                      const bool disableExport,
                      const bool disableCopy,
                      const bool disableInactiveMessages,
                      const bool userCanNotWriteRelative,
+                     const TriState disableChangeTrackingShow,
+                     const TriState disableChangeTrackingRecord,
+                     const TriState hideChangeTrackingControls,
                      const std::chrono::duration<double> callDuration)
             : _userid(userid),
               _username(username),
@@ -284,13 +293,15 @@ public:
               _hidePrintOption(hidePrintOption),
               _hideSaveOption(hideSaveOption),
               _hideExportOption(hideExportOption),
-              _hideChangeTrackingControls(hideChangeTrackingControls),
               _enableOwnerTermination(enableOwnerTermination),
               _disablePrint(disablePrint),
               _disableExport(disableExport),
               _disableCopy(disableCopy),
               _disableInactiveMessages(disableInactiveMessages),
               _userCanNotWriteRelative(userCanNotWriteRelative),
+              _disableChangeTrackingShow(disableChangeTrackingShow),
+              _disableChangeTrackingRecord(disableChangeTrackingRecord),
+              _hideChangeTrackingControls(hideChangeTrackingControls),
               _callDuration(callDuration)
             {
                 _userExtraInfo = userExtraInfo;
@@ -314,8 +325,6 @@ public:
         bool _hideSaveOption;
         /// Hide 'Download as' button/menubar item from UI
         bool _hideExportOption;
-        /// Hide change tacking menu from UI
-        bool _hideChangeTrackingControls;
         /// If WOPI host has enabled owner termination feature on
         bool _enableOwnerTermination;
         /// If WOPI host has allowed the user to print the document
@@ -328,6 +337,13 @@ public:
         bool _disableInactiveMessages;
         /// If set to false, users can access the save-as functionality
         bool _userCanNotWriteRelative;
+        /// If we should disable change-tracking visibility by default (meaningful at loading).
+        TriState _disableChangeTrackingShow;
+        /// If we should disable change-tracking ability by default (meaningful at loading).
+        TriState _disableChangeTrackingRecord;
+        /// If we should hide change-tracking commands for this user.
+        TriState _hideChangeTrackingControls;
+
         /// Time it took to call WOPI's CheckFileInfo
         std::chrono::duration<double> _callDuration;
     };


More information about the Libreoffice-commits mailing list