sw/qa/extras/odfexport/data/personalmetadata.odt |binary sw/qa/extras/odfexport/odfexport2.cxx | 39 ++++++++++++++++++++++ xmloff/source/meta/xmlmetae.cxx | 40 ++++++++++++----------- 3 files changed, 61 insertions(+), 18 deletions(-)
New commits: commit c479944eb4f9f5a22c7b248185f22c86ea85d12a Author: Samuel Mehrbrodt <[email protected]> AuthorDate: Tue Jan 23 15:53:28 2024 +0100 Commit: Samuel Mehrbrodt <[email protected]> CommitDate: Thu Jan 25 16:51:06 2024 +0100 Don't export personal metadata when user wishes not to Currently the metadata is only reset to default when the option to remove personal metadata is active. And some metadata was still exported which might contain personal data. Now the following elements won't be exported anymore when the RemovePersonalInfoOnSaving option is set to true: * meta:initial-creator * meta:creation-date * dc:date * dc:creator * meta:printed-by * meta:print-date * meta:editing-duration * meta:editing-cycles * meta:template Change-Id: Ibad57fdbff04bf285881826820ec3ddb01ffbb36 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162553 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <[email protected]> diff --git a/sw/qa/extras/odfexport/data/personalmetadata.odt b/sw/qa/extras/odfexport/data/personalmetadata.odt new file mode 100644 index 000000000000..9af4e0a3442f Binary files /dev/null and b/sw/qa/extras/odfexport/data/personalmetadata.odt differ diff --git a/sw/qa/extras/odfexport/odfexport2.cxx b/sw/qa/extras/odfexport/odfexport2.cxx index 708a4f94cba0..4160f48ab388 100644 --- a/sw/qa/extras/odfexport/odfexport2.cxx +++ b/sw/qa/extras/odfexport/odfexport2.cxx @@ -27,9 +27,11 @@ #include <com/sun/star/util/XRefreshable.hpp> #include <unotools/localedatawrapper.hxx> #include <unotools/streamwrap.hxx> +#include <comphelper/configuration.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/propertysequence.hxx> #include <comphelper/sequenceashashmap.hxx> +#include <officecfg/Office/Common.hxx> #include <unoprnms.hxx> #include <unotxdoc.hxx> #include <docsh.hxx> @@ -565,6 +567,43 @@ CPPUNIT_TEST_FIXTURE(Test, tdf150927) assertXPath(pXmlDoc, "/office:document-styles/office:automatic-styles/style:style[@style:family='table']"_ostr, 2); } +CPPUNIT_TEST_FIXTURE(Test, testPersonalMetaData) +{ + // 1. Remove personal info, keep user info + auto pBatch(comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::set(true, pBatch); + officecfg::Office::Common::Security::Scripting::KeepDocUserInfoOnSaving::set(true, pBatch); + pBatch->commit(); + + loadAndReload("personalmetadata.odt"); + xmlDocUniquePtr pXmlDoc = parseExport("meta.xml"); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:initial-creator"_ostr, 1); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:creation-date"_ostr, 1); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/dc:date"_ostr, 1); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/dc:creator"_ostr, 1); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:printed-by"_ostr, 1); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:print-date"_ostr, 1); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:editing-duration"_ostr, 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:editing-cycles"_ostr, 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:template"_ostr, 0); + + // 2. Remove user info too + officecfg::Office::Common::Security::Scripting::KeepDocUserInfoOnSaving::set(false, pBatch); + pBatch->commit(); + + loadAndReload("personalmetadata.odt"); + pXmlDoc = parseExport("meta.xml"); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:initial-creator"_ostr, 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:creation-date"_ostr, 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/dc:date"_ostr, 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/dc:creator"_ostr, 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:printed-by"_ostr, 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:print-date"_ostr, 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:editing-duration"_ostr, 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:editing-cycles"_ostr, 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:template"_ostr, 0); +} + CPPUNIT_TEST_FIXTURE(Test, tdf151100) { // Similar to tdf135942 diff --git a/xmloff/source/meta/xmlmetae.cxx b/xmloff/source/meta/xmlmetae.cxx index 395772ab2aca..608ba86de7da 100644 --- a/xmloff/source/meta/xmlmetae.cxx +++ b/xmloff/source/meta/xmlmetae.cxx @@ -95,6 +95,9 @@ void SvXMLMetaExport::SimpleDateTimeElement( const util::DateTime & rDate, void SvXMLMetaExport::MExport_() { + bool bRemovePersonalInfo = SvtSecurityOptions::IsOptionSet(SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo ); + bool bRemoveUserInfo = bRemovePersonalInfo && !SvtSecurityOptions::IsOptionSet(SvtSecurityOptions::EOption::DocWarnKeepDocUserInfo); + // generator { SvXMLElementExport aElem( mrExport, XML_NAMESPACE_META, XML_GENERATOR, @@ -115,22 +118,19 @@ void SvXMLMetaExport::MExport_() XML_NAMESPACE_DC, XML_SUBJECT ); // created... - SimpleStringElement ( mxDocProps->getAuthor(), - XML_NAMESPACE_META, XML_INITIAL_CREATOR ); - SimpleDateTimeElement( mxDocProps->getCreationDate(), - XML_NAMESPACE_META, XML_CREATION_DATE ); - - // modified... - SimpleStringElement ( mxDocProps->getModifiedBy(), - XML_NAMESPACE_DC, XML_CREATOR ); - SimpleDateTimeElement( mxDocProps->getModificationDate(), - XML_NAMESPACE_DC, XML_DATE ); - - // printed... - SimpleStringElement ( mxDocProps->getPrintedBy(), - XML_NAMESPACE_META, XML_PRINTED_BY ); - SimpleDateTimeElement( mxDocProps->getPrintDate(), - XML_NAMESPACE_META, XML_PRINT_DATE ); + if (!bRemoveUserInfo) + { + SimpleStringElement(mxDocProps->getAuthor(), XML_NAMESPACE_META, XML_INITIAL_CREATOR); + SimpleDateTimeElement(mxDocProps->getCreationDate(), XML_NAMESPACE_META, XML_CREATION_DATE); + + // modified... + SimpleStringElement(mxDocProps->getModifiedBy(), XML_NAMESPACE_DC, XML_CREATOR); + SimpleDateTimeElement(mxDocProps->getModificationDate(), XML_NAMESPACE_DC, XML_DATE); + + // printed... + SimpleStringElement(mxDocProps->getPrintedBy(), XML_NAMESPACE_META, XML_PRINTED_BY); + SimpleDateTimeElement(mxDocProps->getPrintDate(), XML_NAMESPACE_META, XML_PRINT_DATE); + } // keywords const uno::Sequence< OUString > keywords = mxDocProps->getKeywords(); @@ -151,6 +151,7 @@ void SvXMLMetaExport::MExport_() } // editing cycles + if (!bRemovePersonalInfo) { SvXMLElementExport aElem( mrExport, XML_NAMESPACE_META, XML_EDITING_CYCLES, @@ -161,6 +162,7 @@ void SvXMLMetaExport::MExport_() // editing duration // property is a int32 (seconds) + if (!bRemovePersonalInfo) { sal_Int32 secs = mxDocProps->getEditingDuration(); SvXMLElementExport aElem( mrExport, @@ -208,7 +210,7 @@ void SvXMLMetaExport::MExport_() // template const OUString sTplPath = mxDocProps->getTemplateURL(); - if ( !sTplPath.isEmpty() ) + if ( !bRemovePersonalInfo && !sTplPath.isEmpty() ) { mrExport.AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE ); mrExport.AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONREQUEST ); @@ -318,7 +320,9 @@ void SvXMLMetaExport::Export() { uno::Reference< xml::sax::XSAXSerializable> xSAXable(mxDocProps, uno::UNO_QUERY); - if (xSAXable.is()) { + bool bRemovePersonalInfo + = SvtSecurityOptions::IsOptionSet(SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo); + if (xSAXable.is() && !bRemovePersonalInfo) { ::std::vector< beans::StringPair > namespaces; const SvXMLNamespaceMap & rNsMap(mrExport.GetNamespaceMap()); for (sal_uInt16 key = rNsMap.GetFirstKey();
