tdf#166379 - Add export config option to remove "Total editing time"

separately from all private info files during save.

The new expert config option name is: RemoveEditingTimeOnSaving
(There wasn't any UI element added for this expert config option.)

Change-Id: Iab69d062d161ef6aee1c3eb87ada1c16f8b4fd41
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184789
Tested-by: Jenkins
Reviewed-by: Balazs Varga <balazs.varga.extern@allotropia.de>
This commit is contained in:
Balazs Varga 2025-04-29 18:55:51 +02:00
parent 4c14003542
commit e275a6e6a0
8 changed files with 83 additions and 6 deletions

View File

@ -40,6 +40,7 @@ namespace SvtSecurityOptions
DocWarnSigning,
DocWarnPrint,
DocWarnCreatePdf,
DocWarnRemoveEditingTimeInfo,
DocWarnRemovePersonalInfo,
DocWarnKeepRedlineInfo,
DocWarnKeepDocUserInfo,

View File

@ -2436,6 +2436,12 @@
</info>
<value>false</value>
</prop>
<prop oor:name="RemoveEditingTimeOnSaving" oor:type="xs:boolean" oor:nillable="false">
<info>
<desc>Specifies whether to remove editing duration on saving.</desc>
</info>
<value>false</value>
</prop>
<prop oor:name="RemovePersonalInfoOnSaving" oor:type="xs:boolean" oor:nillable="false">
<info>
<desc>Specifies whether to remove personal information on

View File

@ -770,7 +770,7 @@ writeAppProperties( XmlFilterBase& rSelf, const Reference< XDocumentProperties >
writeElement( pAppProps, XML_Notes, "notes" );
#endif /* def OOXTODO */
// EditingDuration is in seconds, TotalTime is in minutes.
if (!bRemovePersonalInfo)
if (!bRemovePersonalInfo && !SvtSecurityOptions::IsOptionSet(SvtSecurityOptions::EOption::DocWarnRemoveEditingTimeInfo))
writeElement(pAppProps, XML_TotalTime, xProperties->getEditingDuration() / 60);
#ifdef OOXTODO
writeElement( pAppProps, XML_HiddenSlides, "hidden slides" );

View File

@ -236,8 +236,18 @@ void SfxObjectShell::UpdateDocInfoForSave()
::DateTime now( ::DateTime::SYSTEM );
xDocProps->setModificationDate( now.GetUNODateTime() );
xDocProps->setModifiedBy( aUserName );
UpdateTime_Impl( xDocProps );
if (!SvtSecurityOptions::IsOptionSet(SvtSecurityOptions::EOption::DocWarnRemoveEditingTimeInfo))
UpdateTime_Impl( xDocProps );
}
// reset only editing time to zero if RemoveEditingTimeOnSaving is true
if (SvtSecurityOptions::IsOptionSet(SvtSecurityOptions::EOption::DocWarnRemoveEditingTimeInfo))
xDocProps->setEditingDuration(0);
}
else
{
// reset only editing time to zero if RemoveEditingTimeOnSaving is true
if (SvtSecurityOptions::IsOptionSet(SvtSecurityOptions::EOption::DocWarnRemoveEditingTimeInfo))
xDocProps->setEditingDuration(0);
}
}

View File

@ -129,6 +129,33 @@ CPPUNIT_TEST_FIXTURE(Test, testPersonalMetaData)
"/office:document-settings/office:settings/config:config-item-set[2]/"
"config:config-item[@config:name='PrinterSetup']",
0);
// Reset config change
officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::set(false, pBatch);
pBatch->commit();
}
CPPUNIT_TEST_FIXTURE(Test, testRemoveOnlyEditTimeMetaData)
{
// 1. Check we have the original edit time info
loadAndSave("personalmetadata.odt");
xmlDocUniquePtr pXmlDoc = parseExport(u"meta.xml"_ustr);
assertXPathContent(pXmlDoc, "/office:document-meta/office:meta/meta:editing-duration",
u"PT21M22S");
// Set config RemoveEditingTimeOnSaving to true
auto pBatch(comphelper::ConfigurationChanges::create());
officecfg::Office::Common::Security::Scripting::RemoveEditingTimeOnSaving::set(true, pBatch);
pBatch->commit();
// 2. Check edit time info is 0
loadAndSave("personalmetadata.odt");
pXmlDoc = parseExport(u"meta.xml"_ustr);
assertXPathContent(pXmlDoc, "/office:document-meta/office:meta/meta:editing-duration", u"P0D");
// Reset config change
officecfg::Office::Common::Security::Scripting::RemoveEditingTimeOnSaving::set(false, pBatch);
pBatch->commit();
}
CPPUNIT_TEST_FIXTURE(Test, tdf151100)

View File

@ -810,6 +810,33 @@ CPPUNIT_TEST_FIXTURE(Test, testPersonalMetaData)
assertXPath(pCoreDoc, "/cp:coreProperties/cp:lastModifiedBy", 1);
assertXPath(pCoreDoc, "/cp:coreProperties/cp:lastPrinted", 1);
assertXPath(pCoreDoc, "/cp:coreProperties/cp:revision", 0);
// Reset config change
officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::set(false, pBatch);
officecfg::Office::Common::Security::Scripting::KeepDocUserInfoOnSaving::set(false, pBatch);
pBatch->commit();
}
CPPUNIT_TEST_FIXTURE(Test, testRemoveOnlyEditTimeMetaData)
{
// 1. Check we have the original edit time info
loadAndSave("personalmetadata.docx");
xmlDocUniquePtr pAppDoc = parseExport(u"docProps/app.xml"_ustr);
assertXPath(pAppDoc, "/extended-properties:Properties/extended-properties:TotalTime", 1);
// Set config RemoveEditingTimeOnSaving to true
auto pBatch(comphelper::ConfigurationChanges::create());
officecfg::Office::Common::Security::Scripting::RemoveEditingTimeOnSaving::set(true, pBatch);
pBatch->commit();
// 2. Check edit time info is removed
loadAndSave("personalmetadata.docx");
pAppDoc = parseExport(u"docProps/app.xml"_ustr);
assertXPath(pAppDoc, "/extended-properties:Properties/extended-properties:TotalTime", 0);
// Reset config change
officecfg::Office::Common::Security::Scripting::RemoveEditingTimeOnSaving::set(false, pBatch);
pBatch->commit();
}
DECLARE_OOXMLEXPORT_TEST(testTdf126533_noPageBitmap, "tdf126533_noPageBitmap.docx")

View File

@ -317,6 +317,9 @@ bool IsOptionSet( EOption eOption )
case SvtSecurityOptions::EOption::DocWarnCreatePdf:
bSet = officecfg::Office::Common::Security::Scripting::WarnCreatePDF::get();
break;
case SvtSecurityOptions::EOption::DocWarnRemoveEditingTimeInfo:
bSet = officecfg::Office::Common::Security::Scripting::RemoveEditingTimeOnSaving::get();
break;
case SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo:
bSet = officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::get();
break;
@ -373,6 +376,9 @@ void SetOption( EOption eOption, bool bValue )
case SvtSecurityOptions::EOption::DocWarnCreatePdf:
officecfg::Office::Common::Security::Scripting::WarnCreatePDF::set(bValue, xChanges);
break;
case SvtSecurityOptions::EOption::DocWarnRemoveEditingTimeInfo:
officecfg::Office::Common::Security::Scripting::RemoveEditingTimeOnSaving::set(bValue, xChanges);
break;
case SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo:
officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::set(bValue, xChanges);
break;

View File

@ -162,15 +162,15 @@ void SvXMLMetaExport::MExport_()
// editing duration
// property is a int32 (seconds)
if (!bRemovePersonalInfo)
if (!bRemovePersonalInfo && !SvtSecurityOptions::IsOptionSet(SvtSecurityOptions::EOption::DocWarnRemoveEditingTimeInfo))
{
sal_Int32 secs = mxDocProps->getEditingDuration();
SvXMLElementExport aElem( mrExport,
XML_NAMESPACE_META, XML_EDITING_DURATION,
true, false );
XML_NAMESPACE_META, XML_EDITING_DURATION,
true, false );
OUStringBuffer buf;
::sax::Converter::convertDuration(buf, util::Duration(
false, 0, 0, 0, secs/3600, (secs%3600)/60, secs%60, 0));
false, 0, 0, 0, secs/3600, (secs%3600)/60, secs%60, 0));
mrExport.Characters(buf.makeStringAndClear());
}