sc/qa/unit/data/xlsx/change-tracking.xlsx    |binary
 sc/qa/unit/subsequent_export_test4.cxx       |   26 ++++++++++++++++++++++++++
 sc/source/filter/inc/XclExpChangeTrack.hxx   |    5 +++++
 sc/source/filter/xcl97/XclExpChangeTrack.cxx |   13 ++++++++++++-
 4 files changed, 43 insertions(+), 1 deletion(-)

New commits:
commit 9d0d9d8aa0ba4bb465e376621b426fb9ff00507e
Author:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
AuthorDate: Mon Jun 24 11:11:15 2024 +0200
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
CommitDate: Thu Jun 27 13:45:05 2024 +0200

    xlsx: Don't export changes author/date when in privacy mode
    
    Change-Id: I1b1ef4dd75f02cc545721d5458617cfa92b26615
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169453
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
    Tested-by: Jenkins

diff --git a/sc/qa/unit/data/xlsx/change-tracking.xlsx 
b/sc/qa/unit/data/xlsx/change-tracking.xlsx
new file mode 100644
index 000000000000..cba56b971d64
Binary files /dev/null and b/sc/qa/unit/data/xlsx/change-tracking.xlsx differ
diff --git a/sc/qa/unit/subsequent_export_test4.cxx 
b/sc/qa/unit/subsequent_export_test4.cxx
index 0814c915d81b..a6e5802cf98f 100644
--- a/sc/qa/unit/subsequent_export_test4.cxx
+++ b/sc/qa/unit/subsequent_export_test4.cxx
@@ -1889,6 +1889,32 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, 
testChangesAuthorDate)
         pXmlDoc,
         
"/office:document-content/office:body/office:spreadsheet/table:tracked-changes/table:cell-content-change[1]/office:change-info/dc:date"_ostr,
         u"1970-01-01T12:00:00"_ustr);
+
+    // Reset config change
+    
officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::set(false,
 pBatch);
+    pBatch->commit();
+}
+
+CPPUNIT_TEST_FIXTURE(ScExportTest4, testChangesAuthorDateXLSX)
+{
+    createScDoc("xlsx/change-tracking.xlsx");
+
+    auto pBatch(comphelper::ConfigurationChanges::create());
+    // Remove all personal info
+    
officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::set(true,
 pBatch);
+    pBatch->commit();
+
+    save(u"Calc Office Open XML"_ustr);
+    xmlDocUniquePtr pXmlDoc = 
parseExport(u"xl/revisions/revisionHeaders.xml"_ustr);
+    CPPUNIT_ASSERT(pXmlDoc);
+
+    assertXPath(pXmlDoc, "/x:headers/x:header[1]"_ostr, "userName"_ostr, 
u"Author1"_ustr);
+    assertXPath(pXmlDoc, "/x:headers/x:header[1]"_ostr, "dateTime"_ostr,
+                u"1970-01-01T12:00:00.000000000Z"_ustr);
+
+    // Reset config change
+    
officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::set(false,
 pBatch);
+    pBatch->commit();
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/source/filter/inc/XclExpChangeTrack.hxx 
b/sc/source/filter/inc/XclExpChangeTrack.hxx
index b23b6f8cdcaf..746125e50ab1 100644
--- a/sc/source/filter/inc/XclExpChangeTrack.hxx
+++ b/sc/source/filter/inc/XclExpChangeTrack.hxx
@@ -22,6 +22,7 @@
 #include <memory>
 #include <stack>
 #include <tools/datetime.hxx>
+#include <unotools/securityoptions.hxx>
 #include <chgtrack.hxx>
 #include <document.hxx>
 #include "xelink.hxx"
@@ -262,6 +263,10 @@ public:
     virtual void SaveXml( XclExpXmlStream& rStrm ) override;
 
     void AppendAction( std::unique_ptr<XclExpChTrAction> pAction );
+
+private:
+    /// map authors to remove personal info
+    std::unique_ptr<SvtSecurityMapPersonalInfo> mpAuthorIDs;
 };
 
 // XclExpChTrInfo - header of action group of a user
diff --git a/sc/source/filter/xcl97/XclExpChangeTrack.cxx 
b/sc/source/filter/xcl97/XclExpChangeTrack.cxx
index 52d2150e9f75..30812d7bb9e2 100644
--- a/sc/source/filter/xcl97/XclExpChangeTrack.cxx
+++ b/sc/source/filter/xcl97/XclExpChangeTrack.cxx
@@ -37,6 +37,9 @@
 #include <oox/token/tokens.hxx>
 #include <rtl/uuid.h>
 #include <svl/sharedstring.hxx>
+#include <unotools/securityoptions.hxx>
+
+#include <com/sun/star/util/DateTime.hpp>
 
 using namespace oox;
 
@@ -395,7 +398,7 @@ XclExpXmlChTrHeader::XclExpXmlChTrHeader(
     OUString aUserName, const DateTime& rDateTime, const sal_uInt8* pGUID,
     sal_Int32 nLogNumber, const XclExpChTrTabIdBuffer& rBuf ) :
     maUserName(std::move(aUserName)), maDateTime(rDateTime), 
mnLogNumber(nLogNumber),
-    mnMinAction(0), mnMaxAction(0)
+    mnMinAction(0), mnMaxAction(0), mpAuthorIDs(new SvtSecurityMapPersonalInfo)
 {
     memcpy(maGUID, pGUID, 16);
     if (rBuf.GetBufferCount())
@@ -421,6 +424,14 @@ void XclExpXmlChTrHeader::SaveXml( XclExpXmlStream& rStrm )
             &aRelId);
 
     tools::Guid aGuid(maGUID);
+    bool bRemovePersonalInfo
+        = 
SvtSecurityOptions::IsOptionSet(SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo)
+          && 
!SvtSecurityOptions::IsOptionSet(SvtSecurityOptions::EOption::DocWarnKeepRedlineInfo);
+    if (bRemovePersonalInfo)
+    {
+        maDateTime = css::util::DateTime(0, 0, 0, 12, 1, 1, 1970, true);
+        maUserName = "Author" + 
OUString::number(mpAuthorIDs->GetInfoID(maUserName));
+    }
     rStrm.WriteAttributes(
         XML_guid, aGuid.getString(),
         XML_dateTime, lcl_DateTimeToOString(maDateTime),

Reply via email to