sc/qa/extras/macros-test.cxx             |   21 +++++++++++++++++++++
 sc/source/ui/docshell/externalrefmgr.cxx |    2 +-
 2 files changed, 22 insertions(+), 1 deletion(-)

New commits:
commit 7f58df88771767962fc4e98f2b6bed445ab18994
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Mar 17 00:28:07 2022 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Thu Mar 17 16:19:32 2022 +0100

    tdf#148040: allow external link update for css.sheet.FunctionAccess
    
    Change-Id: I2608c10fd3354e90049d1c7315895922c865a648
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131682
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx
index 0d1be3d710c7..e69feea0e8ac 100644
--- a/sc/qa/extras/macros-test.cxx
+++ b/sc/qa/extras/macros-test.cxx
@@ -13,12 +13,14 @@
 #include <unotools/tempfile.hxx>
 #include <svx/svdpage.hxx>
 #include <unotools/mediadescriptor.hxx>
+#include <comphelper/processfactory.hxx>
 #include <comphelper/propertyvalue.hxx>
 
 #include <docsh.hxx>
 #include <document.hxx>
 #include <sortparam.hxx>
 
+#include <com/sun/star/sheet/XFunctionAccess.hpp>
 #include <com/sun/star/sheet/XSpreadsheet.hpp>
 
 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
@@ -68,6 +70,7 @@ public:
     void testMacroButtonFormControlXlsxExport();
     void testShapeLayerId();
     void testVbaRangeSort();
+    void testFunctionAccessIndirect();
 
     CPPUNIT_TEST_SUITE(ScMacrosTest);
     CPPUNIT_TEST(testStarBasic);
@@ -99,6 +102,7 @@ public:
     CPPUNIT_TEST(testMacroButtonFormControlXlsxExport);
     CPPUNIT_TEST(testShapeLayerId);
     CPPUNIT_TEST(testVbaRangeSort);
+    CPPUNIT_TEST(testFunctionAccessIndirect);
 
     CPPUNIT_TEST_SUITE_END();
 };
@@ -1158,6 +1162,23 @@ void ScMacrosTest::testVbaRangeSort()
     pDocSh->DoClose();
 }
 
+void ScMacrosTest::testFunctionAccessIndirect()
+{
+    OUString aFileName;
+    createFileURL(u"tdf120161.ods", aFileName); // just some document with 
known values in cells
+    const OUString aReference = "'" + aFileName + "'#$Sheet1.A1";
+
+    css::uno::Reference<css::sheet::XFunctionAccess> xFunc(
+        
comphelper::getProcessServiceFactory()->createInstance("com.sun.star.sheet.FunctionAccess"),
+        UNO_QUERY_THROW);
+
+    // tdf#148040: without the fix in plcae, this would have failed with:
+    //   An uncaught exception of type 
com.sun.star.lang.IllegalArgumentException
+    // because of disallowed external link update (needed to obtain the cell 
value).
+    css::uno::Any aResult = xFunc->callFunction("INDIRECT", 
{css::uno::Any(aReference)});
+    CPPUNIT_ASSERT_EQUAL(css::uno::Any(OUString("a1")), aResult);
+}
+
 ScMacrosTest::ScMacrosTest()
       : UnoApiTest("/sc/qa/extras/testdocuments")
 {
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx 
b/sc/source/ui/docshell/externalrefmgr.cxx
index c25a79f1f919..3d1845cbeacb 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -1655,7 +1655,7 @@ bool isLinkUpdateAllowedInDoc(const ScDocument& rDoc)
 {
     SfxObjectShell* pDocShell = rDoc.GetDocumentShell();
     if (!pDocShell)
-        return false;
+        return rDoc.IsFunctionAccess();
 
     return pDocShell->GetEmbeddedObjectContainer().getUserAllowsLinkUpdate();
 }

Reply via email to