diff options
author | László Németh <nemeth@numbertext.org> | 2021-06-18 13:03:17 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2021-07-03 12:54:39 +0200 |
commit | ded2452a52d21131347a0dc2e25c8161f20fcfad (patch) | |
tree | ab5aa76d91aaffdb0de9e302e8789c91e44f4783 /sw/source | |
parent | 56ae948b08010ed1b61be9857c8c6ae4e97e86b2 (diff) |
tdf#142902 DOCX export: remove personal info of comments and changes
If Options → LibreOffice → Security → Security Options
and Warnings → Options... → Security Options → Remove personal
information on saving" is enabled.
Use the same time (Unix epoch) for mandatory time stamps, and
replace authors with "Author1", "Author2", ... and creator-initials
with "1", "2", "3" etc., also to avoid of joining adjacent redline
ranges.
Note: to see the work of the unit test in Linux command line:
(cd sw && make UITest_writer_tests7 UITEST_TEST_NAME="tdf90401.tdf90401.test_tdf142902_remove_personal_info_in_DOCX" SAL_USE_VCLPLUGIN=gen)
Follow-up to commit 12da70f88517bf3c053afe1c504bb70bd27573f2
"tdf#90401 xmloff: remove personal info of comments and changes".
Change-Id: Ice996f171f5d82d13ce0ea2e4833696af0aab90c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117444
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 79 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexport.cxx | 3 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexport.hxx | 7 |
3 files changed, 74 insertions, 15 deletions
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 19dc42aa119c..bbf4994a1d05 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -100,6 +100,8 @@ #include <svx/unobrushitemhelper.hxx> #include <svl/grabbagitem.hxx> #include <sfx2/sfxbasemodel.hxx> +#include <tools/date.hxx> +#include <tools/datetime.hxx> #include <tools/datetimeutils.hxx> #include <tools/UnitConversion.hxx> #include <svl/whiter.hxx> @@ -3145,9 +3147,15 @@ void DocxAttributeOutput::Redline( const SwRedlineData* pRedlineData) if ( !pRedlineData ) return; + SvtSecurityOptions aSecOpt; + bool bRemovePersonalInfo = aSecOpt.IsOptionSet( + SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo ); + OString aId( OString::number( pRedlineData->GetSeqNo() ) ); const OUString &rAuthor( SW_MOD()->GetRedlineAuthor( pRedlineData->GetAuthor() ) ); - OString aDate( DateTimeToOString( pRedlineData->GetTimeStamp() ) ); + OString aDate( DateTimeToOString( bRemovePersonalInfo + ? DateTime(Date( 1, 1, 1970 )) // Epoch time + : pRedlineData->GetTimeStamp() ) ); switch( pRedlineData->GetType() ) { @@ -3160,7 +3168,9 @@ void DocxAttributeOutput::Redline( const SwRedlineData* pRedlineData) case RedlineType::Format: m_pSerializer->startElementNS( XML_w, XML_rPrChange, FSNS( XML_w, XML_id ), aId, - FSNS( XML_w, XML_author ), rAuthor, + FSNS( XML_w, XML_author ), bRemovePersonalInfo + ? "Author" + OUString::number( GetExport().GetInfoID(rAuthor) ) + : rAuthor, FSNS( XML_w, XML_date ), aDate ); m_pSerializer->endElementNS( XML_w, XML_rPrChange ); @@ -3169,7 +3179,9 @@ void DocxAttributeOutput::Redline( const SwRedlineData* pRedlineData) case RedlineType::ParagraphFormat: m_pSerializer->startElementNS( XML_w, XML_pPrChange, FSNS( XML_w, XML_id ), aId, - FSNS( XML_w, XML_author ), rAuthor, + FSNS( XML_w, XML_author ), bRemovePersonalInfo + ? "Author" + OUString::number( GetExport().GetInfoID(rAuthor) ) + : rAuthor, FSNS( XML_w, XML_date ), aDate ); // Check if there is any extra data stored in the redline object @@ -3243,10 +3255,18 @@ void DocxAttributeOutput::StartRedline( const SwRedlineData * pRedlineData ) OString aId( OString::number( m_nRedlineId++ ) ); + SvtSecurityOptions aSecOpt; + bool bRemovePersonalInfo = aSecOpt.IsOptionSet( + SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo ); + const OUString &rAuthor( SW_MOD()->GetRedlineAuthor( pRedlineData->GetAuthor() ) ); - OString aAuthor( OUStringToOString( rAuthor, RTL_TEXTENCODING_UTF8 ) ); + OString aAuthor( OUStringToOString( bRemovePersonalInfo + ? "Author" + OUString::number( GetExport().GetInfoID(rAuthor) ) + : rAuthor, RTL_TEXTENCODING_UTF8 ) ); - OString aDate( DateTimeToOString( pRedlineData->GetTimeStamp() ) ); + OString aDate( DateTimeToOString( bRemovePersonalInfo + ? DateTime(Date( 1, 1, 1970 )) // Epoch time + : pRedlineData->GetTimeStamp() ) ); switch ( pRedlineData->GetType() ) { @@ -4357,6 +4377,11 @@ void DocxAttributeOutput::TableRowRedline( ww8::WW8TableNodeInfoInner::Pointer_t const SwRedlineTable& aRedlineTable = m_rExport.m_rDoc.getIDocumentRedlineAccess().GetRedlineTable(); const SvxPrintItem *pHasTextChangesOnlyProp = pTabLine->GetFrameFormat()->GetAttrSet().GetItem<SvxPrintItem>(RES_PRINT); + + SvtSecurityOptions aSecOpt; + bool bRemovePersonalInfo = aSecOpt.IsOptionSet( + SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo ); + if ( !aRedlineTable.empty() && pHasTextChangesOnlyProp && !pHasTextChangesOnlyProp->GetValue() ) { // Tracked row deletion is associated to the newest redline range in the row. @@ -4397,9 +4422,13 @@ void DocxAttributeOutput::TableRowRedline( ww8::WW8TableNodeInfoInner::Pointer_t // (different IDs for different ranges, also row changes) is also portable. OString aId( OString::number( m_nRedlineId++ ) ); const OUString &rAuthor( SW_MOD()->GetRedlineAuthor( aRedlineData.GetAuthor() ) ); - OString aAuthor( OUStringToOString( rAuthor, RTL_TEXTENCODING_UTF8 ) ); + OString aAuthor( OUStringToOString( bRemovePersonalInfo + ? "Author" + OUString::number( GetExport().GetInfoID(rAuthor) ) + : rAuthor, RTL_TEXTENCODING_UTF8 ) ); - OString aDate( DateTimeToOString( aRedlineData.GetTimeStamp() ) ); + OString aDate( DateTimeToOString( bRemovePersonalInfo + ? DateTime(Date( 1, 1, 1970 )) // Epoch time + : aRedlineData.GetTimeStamp() ) ); m_pSerializer->singleElementNS( XML_w, XML_del, FSNS( XML_w, XML_id ), aId, @@ -4427,9 +4456,13 @@ void DocxAttributeOutput::TableRowRedline( ww8::WW8TableNodeInfoInner::Pointer_t { OString aId( OString::number( m_nRedlineId++ ) ); const OUString &rAuthor( SW_MOD()->GetRedlineAuthor( aRedlineData.GetAuthor() ) ); - OString aAuthor( OUStringToOString( rAuthor, RTL_TEXTENCODING_UTF8 ) ); + OString aAuthor( OUStringToOString( bRemovePersonalInfo + ? "Author" + OUString::number( GetExport().GetInfoID(rAuthor) ) + : rAuthor, RTL_TEXTENCODING_UTF8 ) ); - OString aDate( DateTimeToOString( aRedlineData.GetTimeStamp() ) ); + OString aDate( DateTimeToOString( bRemovePersonalInfo + ? DateTime(Date( 1, 1, 1970 )) // Epoch time + : aRedlineData.GetTimeStamp() ) ); if (nRedlineType == RedlineType::TableRowInsert) m_pSerializer->singleElementNS( XML_w, XML_ins, @@ -4453,6 +4486,10 @@ void DocxAttributeOutput::TableCellRedline( ww8::WW8TableNodeInfoInner::Pointer_ { const SwTableBox * pTabBox = pTableTextNodeInfoInner->getTableBox(); + SvtSecurityOptions aSecOpt; + bool bRemovePersonalInfo = aSecOpt.IsOptionSet( + SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo ); + // search next Redline const SwExtraRedlineTable& aExtraRedlineTable = m_rExport.m_rDoc.getIDocumentRedlineAccess().GetExtraRedlineTable(); for(sal_uInt16 nCurRedlinePos = 0; nCurRedlinePos < aExtraRedlineTable.GetSize(); ++nCurRedlinePos ) @@ -4471,9 +4508,13 @@ void DocxAttributeOutput::TableCellRedline( ww8::WW8TableNodeInfoInner::Pointer_ { OString aId( OString::number( m_nRedlineId++ ) ); const OUString &rAuthor( SW_MOD()->GetRedlineAuthor( aRedlineData.GetAuthor() ) ); - OString aAuthor( OUStringToOString( rAuthor, RTL_TEXTENCODING_UTF8 ) ); + OString aAuthor( OUStringToOString( bRemovePersonalInfo + ? "Author" + OUString::number( GetExport().GetInfoID(rAuthor) ) + : rAuthor, RTL_TEXTENCODING_UTF8 ) ); - OString aDate( DateTimeToOString( aRedlineData.GetTimeStamp() ) ); + OString aDate( DateTimeToOString( bRemovePersonalInfo + ? DateTime(Date( 1, 1, 1970 )) // Epoch time + : aRedlineData.GetTimeStamp() ) ); if (nRedlineType == RedlineType::TableCellInsert) m_pSerializer->singleElementNS( XML_w, XML_cellIns, @@ -8137,14 +8178,24 @@ void DocxAttributeOutput::WritePostitFieldReference() DocxAttributeOutput::hasResolved DocxAttributeOutput::WritePostitFields() { + SvtSecurityOptions aSecOpt; + bool bRemovePersonalInfo = aSecOpt.IsOptionSet( + SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo ); + hasResolved eResult = hasResolved::no; for (auto& [f, data] : m_postitFields) { OString idstr = OString::number(data.id); m_pSerializer->startElementNS( XML_w, XML_comment, FSNS( XML_w, XML_id ), idstr, - FSNS( XML_w, XML_author ), f->GetPar1(), - FSNS( XML_w, XML_date ), DateTimeToOString(f->GetDateTime()), - FSNS( XML_w, XML_initials ), f->GetInitials() ); + FSNS( XML_w, XML_author ), bRemovePersonalInfo + ? "Author" + OUString::number( GetExport().GetInfoID(f->GetPar1()) ) + : f->GetPar1(), + FSNS( XML_w, XML_date ), DateTimeToOString( bRemovePersonalInfo + ? util::DateTime() // "no date" time + : f->GetDateTime() ), + FSNS( XML_w, XML_initials ), bRemovePersonalInfo + ? OUString::number( GetExport().GetInfoID(f->GetInitials()) ) + : f->GetInitials() ); const bool bNeedParaId = f->GetResolved(); if (bNeedParaId) diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index 0590fea71d35..3eefc919eed8 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -1798,7 +1798,8 @@ DocxExport::DocxExport(DocxExportFilter& rFilter, SwDoc& rDocument, m_nActiveXControls( 0 ), m_nHeadersFootersInSection(0), m_bDocm(bDocm), - m_bTemplate(bTemplate) + m_bTemplate(bTemplate), + m_pAuthorIDs(new SvtSecurityMapPersonalInfo) { // Write the document properties WriteProperties( ); diff --git a/sw/source/filter/ww8/docxexport.hxx b/sw/source/filter/ww8/docxexport.hxx index bc96ba187100..4bbd2ea9cb0c 100644 --- a/sw/source/filter/ww8/docxexport.hxx +++ b/sw/source/filter/ww8/docxexport.hxx @@ -28,6 +28,7 @@ #include <memory> #include <ndole.hxx> +#include <unotools/securityoptions.hxx> class DocxAttributeOutput; class DocxExportFilter; @@ -114,6 +115,9 @@ class DocxExport : public MSWordExportBase /// Pointer to the Frame of a floating table it is nested in const ww8::Frame *m_pFloatingTableFrame = nullptr; + /// Map authors to remove personal info + std::unique_ptr<SvtSecurityMapPersonalInfo> m_pAuthorIDs; + public: DocxExportFilter& GetFilter() { return m_rFilter; }; @@ -296,6 +300,9 @@ public: void SetFloatingTableFrame(const ww8::Frame* pF) { m_pFloatingTableFrame = pF; } + // Get author id to remove personal info + size_t GetInfoID( const OUString sPersonalInfo ) const { return m_pAuthorIDs->GetInfoID(sPersonalInfo); } + private: DocxExport( const DocxExport& ) = delete; |