Resolves: tdf#126928 allow link updates in an intermediate linked document
authorEike Rathke <erack@redhat.com>
Fri, 16 Aug 2019 13:36:15 +0000 (15:36 +0200)
committerBastien Roucariès <rouca@debian.org>
Sat, 12 Aug 2023 19:58:29 +0000 (20:58 +0100)
... if link updates are allowed in the current document and that
intermediate document resides in a trusted location.

This works with both, the "Always (from trusted locations)" and
the "On request" settings under Tools -> Options -> Calc ->
General. It can't work with documents residing in a non-trusted
location as there is no way to allow updates on demand for a such
loaded document (hidden via formulas).

Reviewed-on: https://gerrit.libreoffice.org/77588
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
(cherry picked from commit 54bf84746a2a9a2e2aaf0df9e429b0cfd538f640)

 Conflicts:
sc/source/ui/docshell/docsh4.cxx
sc/source/ui/docshell/externalrefmgr.cxx

Backported. Also includes

    commit 1663b1e8233db6c6d1c2b35639ad984961084009
    CommitDate: Tue Feb 26 21:15:57 2019 +0100

        tdf#120736: For Calc shared documents also check the original document URL

Change-Id: Ie483f7743db7c6d5cf947dc16a9c3660855f3423
Reviewed-on: https://gerrit.libreoffice.org/77613
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Gbp-Pq: Name allow-link-updates-in-an-intermediate-linked-document.diff

sc/source/ui/docshell/docsh.cxx
sc/source/ui/docshell/docsh4.cxx
sc/source/ui/docshell/externalrefmgr.cxx
sc/source/ui/inc/docsh.hxx

index 3d3e6473cd43e8855517c0882bdd6dae0bdbaf09..cb7b1d89368b499d3373e7657acfb676a1930ff8 100644 (file)
@@ -618,15 +618,22 @@ bool ScDocShell::Load( SfxMedium& rMedium )
     bool bRet = SfxObjectShell::Load(rMedium);
     if (bRet)
     {
-        comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = getEmbeddedObjectContainer();
-        rEmbeddedObjectContainer.setUserAllowsLinkUpdate(false);
-
         if (GetMedium())
         {
             const SfxUInt16Item* pUpdateDocItem = SfxItemSet::GetItem<SfxUInt16Item>(rMedium.GetItemSet(), SID_UPDATEDOCMODE, false);
             m_nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : css::document::UpdateDocMode::NO_UPDATE;
         }
 
+        // GetLinkUpdateModeState() evaluates m_nCanUpdate so that must have
+        // been set first. Do not override an already forbidden LinkUpdate (the
+        // default is allow).
+        comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = getEmbeddedObjectContainer();
+        if (rEmbeddedObjectContainer.getUserAllowsLinkUpdate())
+        {
+            // For anything else than LM_ALWAYS we need user confirmation.
+            rEmbeddedObjectContainer.setUserAllowsLinkUpdate( GetLinkUpdateModeState() == LM_ALWAYS);
+        }
+
         {
             //  prepare a valid document for XML filter
             //  (for ConvertFrom, InitNew is called before)
index 47992f8ea28d491362189472d33f5a2d09accf86..c6f4c0fbfcf0a158ade0ea3bbb8c6751d255078a 100644 (file)
@@ -149,6 +149,41 @@ IMPL_LINK_NOARG( ScDocShell, ReloadAllLinksHdl, Button*, void )
     SAL_WARN_IF(!pViewFrame, "sc", "expected there to be a ViewFrame");
 }
 
+ScLkUpdMode ScDocShell::GetLinkUpdateModeState() const
+{
+    const ScDocument& rDoc = GetDocument();
+
+    ScLkUpdMode nSet = rDoc.GetLinkMode();
+
+    if (nSet == LM_UNKNOWN)
+    {
+        ScAppOptions aAppOptions = SC_MOD()->GetAppOptions();
+        nSet = aAppOptions.GetLinkMode();
+    }
+
+    if (m_nCanUpdate == css::document::UpdateDocMode::NO_UPDATE)
+        nSet = LM_NEVER;
+    else if (m_nCanUpdate == css::document::UpdateDocMode::FULL_UPDATE)
+        nSet = LM_ALWAYS;
+
+    if (nSet == LM_ALWAYS
+            && !(SvtSecurityOptions().isTrustedLocationUriForUpdatingLinks(
+                    GetMedium() == nullptr ? OUString() : GetMedium()->GetName())
+                || (IsDocShared()
+                    && SvtSecurityOptions().isTrustedLocationUriForUpdatingLinks(
+                        GetSharedFileURL()))))
+    {
+        nSet = LM_ON_DEMAND;
+    }
+    if (m_nCanUpdate == css::document::UpdateDocMode::QUIET_UPDATE
+            && nSet == LM_ON_DEMAND)
+    {
+        nSet = LM_NEVER;
+    }
+
+    return nSet;
+}
+
 void ScDocShell::Execute( SfxRequest& rReq )
 {
     const SfxItemSet* pReqArgs = rReq.GetArgs();
@@ -448,34 +483,7 @@ void ScDocShell::Execute( SfxRequest& rReq )
             break;
         case SID_UPDATETABLINKS:
             {
-                ScDocument& rDoc = GetDocument();
-
-                ScLkUpdMode nSet = rDoc.GetLinkMode();
-
-                if(nSet==LM_UNKNOWN)
-                {
-                    ScAppOptions aAppOptions=SC_MOD()->GetAppOptions();
-                    nSet=aAppOptions.GetLinkMode();
-                }
-
-                if (m_nCanUpdate == css::document::UpdateDocMode::NO_UPDATE)
-                    nSet = LM_NEVER;
-                else if (m_nCanUpdate == css::document::UpdateDocMode::FULL_UPDATE)
-                    nSet = LM_ALWAYS;
-
-                if (nSet == LM_ALWAYS
-                    && !(SvtSecurityOptions()
-                         .isTrustedLocationUriForUpdatingLinks(
-                             GetMedium() == nullptr
-                             ? OUString() : GetMedium()->GetName())))
-                {
-                    nSet = LM_ON_DEMAND;
-                }
-                if (m_nCanUpdate == css::document::UpdateDocMode::QUIET_UPDATE
-                    && nSet == LM_ON_DEMAND)
-                {
-                    nSet = LM_NEVER;
-                }
+                ScLkUpdMode nSet = GetLinkUpdateModeState();
 
                 if (nSet == LM_ALWAYS)
                 {
index 48ae556cf4853d69988990449ebfbea54802e200..5f7cabbc5a57980f363fe19e3b8f890803785a4e 100644 (file)
@@ -59,6 +59,7 @@
 #include <columnspanset.hxx>
 #include <column.hxx>
 #include <com/sun/star/document/MacroExecMode.hpp>
+#include <com/sun/star/document/UpdateDocMode.hpp>
 
 #include <memory>
 #include <algorithm>
index d5b05cb96e31771e4e9dff19eb531f55a9a883cc..5b990f24e6a6160b3c27f4e9a5bcd0b57e8b862d 100644 (file)
@@ -221,6 +221,7 @@ public:
 
     void    GetDocStat( ScDocStat& rDocStat );
 
+    const ScDocument& GetDocument() const { return m_aDocument; }
     ScDocument&     GetDocument()   { return m_aDocument; }
     ScDocFunc&      GetDocFunc()    { return *m_pDocFunc; }
 
@@ -303,6 +304,7 @@ public:
     void            UpdateLinks() override;
     void            ReloadAllLinks();
     void            ReloadTabLinks();
+    ScLkUpdMode     GetLinkUpdateModeState() const;
 
     void            SetFormulaOptions( const ScFormulaOptions& rOpt, bool bForLoading = false );
     /**