diff options
author | László Németh <nemeth@numbertext.org> | 2019-10-14 17:50:47 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2019-10-16 12:15:16 +0200 |
commit | 2756ed9317e3474003c11ffe7d1e2f087c1412bf (patch) | |
tree | 3c8952f94809a5bf8a4ad660935c46bba8bcfec8 /sw | |
parent | 4a96fb8ec0130e1036913093836bcf28bc37a49b (diff) |
tdf#106843 DOCX: export/import change tracking protection
Now change tracking protection from Writer or from ODT files
is exported to DOCX.
In Writer it's always possible to disable change tracking
protection without password in File->Properties->Security page->
Record Changes after confirmation.
Now Writer uses the same confirmation to remove change
tracking protection imported from DOCX, for example clicking
on Record Track Changes. Disabled protection removes the
export of the grab-bagged change tracking protection, too,
to avoid of creating bad DOCX with enabled change tracking
protection and disabled Record change tracking.
See also commit d416250f4f1766e2d596ea3feef6a94b7adf29f4
"tdf#106843 DOCX: forbid disabling protected Record Changes"
Change-Id: Ida4d72c57dbe5450ea22028bbed69d413f5a786d
Reviewed-on: https://gerrit.libreoffice.org/80784
Reviewed-by: László Németh <nemeth@numbertext.org>
Tested-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf106843.fodt | 43 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport5.cxx | 10 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexport.cxx | 31 | ||||
-rw-r--r-- | sw/source/uibase/uiview/view2.cxx | 42 |
4 files changed, 112 insertions, 14 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf106843.fodt b/sw/qa/extras/ooxmlexport/data/tdf106843.fodt new file mode 100644 index 000000000000..37a97489a3d5 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf106843.fodt @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:settings> + <config:config-item-set config:name="ooo:configuration-settings"> + <config:config-item config:name="RedlineProtectionKey" config:type="base64Binary">h/jtkVcSX/xNqeBqe4ARrYClP+E=</config:config-item> + </config:config-item-set> + </office:settings> + <office:body> + <office:text> + <text:tracked-changes text:track-changes="false"> + <text:changed-region xml:id="ct101395712" text:id="ct101395712"> + <text:deletion> + <office:change-info> + <dc:creator>Ismeretlen szerző</dc:creator> + <dc:date>2018-12-03T20:35:00</dc:date> + </office:change-info> + </text:deletion> + </text:changed-region> + <text:changed-region xml:id="ct101395264" text:id="ct101395264"> + <text:deletion> + <office:change-info> + <dc:creator>Ismeretlen szerző</dc:creator> + <dc:date>2018-12-03T20:34:58</dc:date> + </office:change-info> + </text:deletion> + </text:changed-region> + </text:tracked-changes> + <text:sequence-decls> + <text:sequence-decl text:display-outline-level="0" text:name="Illustration"/> + <text:sequence-decl text:display-outline-level="0" text:name="Table"/> + <text:sequence-decl text:display-outline-level="0" text:name="Text"/> + <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/> + <text:sequence-decl text:display-outline-level="0" text:name="Figure"/> + </text:sequence-decls> + <text:p text:style-name="P1">Par1<text:change-start text:change-id="ct101395712"/>Par2<text:change-end text:change-id="ct101395712"/><text:change-start text:change-id="ct101395264"/></text:p> + <text:p text:style-name="P1"/> + <text:p text:style-name="P1"><text:change-end text:change-id="ct101395264"/><text:span text:style-name="T1">Format this...</text:span></text:p> + <text:p text:style-name="P1">Par3</text:p> + <text:p text:style-name="P1"/> + </office:text> + </office:body> +</office:document> diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx index 7647c02142de..99044821e1ee 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx @@ -1012,6 +1012,16 @@ DECLARE_OOXMLEXPORT_TEST(tdf66398_permissions, "tdf66398_permissions.docx") CPPUNIT_ASSERT(xBookmarksByName->hasByName("permission-for-group:267014232:everyone")); } +DECLARE_OOXMLEXPORT_TEST(tdf106843, "tdf106843.fodt") +{ + // check Track Changes permission set in Writer/OpenDocument (password: "test", encoded by default encoding of Writer) + if (xmlDocPtr pXmlSettings = parseExport("word/settings.xml")) + { + assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "edit", "trackedChanges"); + assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "enforcement", "1"); + } +} + DECLARE_OOXMLEXPORT_TEST(tdf89991_revisionView, "tdf89991.docx") { // check revisionView (Show Changes) import and export diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index 1ff5f4bb25e6..91a962490314 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -1034,7 +1034,16 @@ void DocxExport::WriteSettings() uno::Reference< beans::XPropertySet > xPropSet( m_pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW ); bool hasProtectionProperties = false; + bool bHasRedlineProtectionKey = false; + bool bHasDummyRedlineProtectionKey = false; uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo(); + if ( xPropSetInfo->hasPropertyByName( "RedlineProtectionKey" ) ) + { + uno::Sequence<sal_Int8> aKey; + xPropSet->getPropertyValue( "RedlineProtectionKey" ) >>= aKey; + bHasRedlineProtectionKey = aKey.hasElements(); + bHasDummyRedlineProtectionKey = aKey.getLength() == 1 && aKey[0] == 1; + } const OUString aGrabBagName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG; if ( xPropSetInfo->hasPropertyByName( aGrabBagName ) ) { @@ -1103,6 +1112,7 @@ void DocxExport::WriteSettings() if (rAttributeList.hasElements()) { sax_fastparser::FastAttributeList* pAttributeList = sax_fastparser::FastSerializerHelper::createAttrList(); + bool bIsProtectionTrackChanges = false; for (const auto& rAttribute : std::as_const(rAttributeList)) { static DocxStringTokenMap const aTokens[] = @@ -1121,13 +1131,20 @@ void DocxExport::WriteSettings() }; if (sal_Int32 nToken = DocxStringGetToken(aTokens, rAttribute.Name)) - pAttributeList->add(FSNS(XML_w, nToken), rAttribute.Value.get<OUString>().toUtf8()); + { + OUString sValue = rAttribute.Value.get<OUString>(); + pAttributeList->add(FSNS(XML_w, nToken), sValue.toUtf8()); + if ( nToken == XML_edit && sValue == "trackedChanges" ) + bIsProtectionTrackChanges = true; + } } // we have document protection from input DOCX file + // and in the case of change tracking protection, we didn't modify it sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList); - pFS->singleElementNS(XML_w, XML_documentProtection, xAttributeList); + if (!bIsProtectionTrackChanges || bHasDummyRedlineProtectionKey) + pFS->singleElementNS(XML_w, XML_documentProtection, xAttributeList); hasProtectionProperties = true; } @@ -1150,6 +1167,16 @@ void DocxExport::WriteSettings() } } + // Protect Change Tracking + if ( bHasRedlineProtectionKey && !bHasDummyRedlineProtectionKey ) + { + // we have change tracking protection from Writer or from input ODT file + + pFS->singleElementNS(XML_w, XML_documentProtection, + FSNS(XML_w, XML_edit), "trackedChanges", + FSNS(XML_w, XML_enforcement), "1"); + } + // finish settings.xml pFS->endElementNS( XML_w, XML_settings ); } diff --git a/sw/source/uibase/uiview/view2.cxx b/sw/source/uibase/uiview/view2.cxx index 15644c016ce9..c198a95dac8a 100644 --- a/sw/source/uibase/uiview/view2.cxx +++ b/sw/source/uibase/uiview/view2.cxx @@ -113,6 +113,8 @@ #include <tabsh.hxx> #include <listsh.hxx> #include <cmdid.h> +#include <sfx2/strings.hrc> +#include <sfx2/sfxresid.hxx> #include <strings.hrc> #include <swerror.h> #include <globals.hrc> @@ -595,19 +597,35 @@ void SwView::Execute(SfxRequest &rReq) if( aPasswd.hasElements() ) { OSL_ENSURE( !static_cast<const SfxBoolItem*>(pItem)->GetValue(), "SwView::Execute(): password set and redlining off doesn't match!" ); - // xmlsec05: new password dialog - SfxPasswordDialog aPasswdDlg(GetFrameWeld()); - aPasswdDlg.SetMinLen(1); - //#i69751# the result of Execute() can be ignored - (void)aPasswdDlg.run(); - OUString sNewPasswd(aPasswdDlg.GetPassword()); - Sequence <sal_Int8> aNewPasswd = rIDRA.GetRedlinePassword(); - SvPasswordHelper::GetHashPassword( aNewPasswd, sNewPasswd ); - if(SvPasswordHelper::CompareHashPassword(aPasswd, sNewPasswd)) - rIDRA.SetRedlinePassword(Sequence <sal_Int8> ()); + + // dummy password from OOXML import: only confirmation dialog + if (aPasswd.getLength() == 1 && aPasswd[0] == 1) + { + std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(m_pWrtShell->GetView().GetFrameWeld(), + VclMessageType::Warning, VclButtonsType::YesNo, + SfxResId(RID_SVXSTR_END_REDLINING_WARNING))); + xWarn->set_default_response(RET_NO); + if (xWarn->run() == RET_YES) + rIDRA.SetRedlinePassword(Sequence <sal_Int8> ()); + else + break; + } else - { // xmlsec05: message box for wrong password - break; + { + // xmlsec05: new password dialog + SfxPasswordDialog aPasswdDlg(GetFrameWeld()); + aPasswdDlg.SetMinLen(1); + //#i69751# the result of Execute() can be ignored + (void)aPasswdDlg.run(); + OUString sNewPasswd(aPasswdDlg.GetPassword()); + Sequence <sal_Int8> aNewPasswd = rIDRA.GetRedlinePassword(); + SvPasswordHelper::GetHashPassword( aNewPasswd, sNewPasswd ); + if(SvPasswordHelper::CompareHashPassword(aPasswd, sNewPasswd)) + rIDRA.SetRedlinePassword(Sequence <sal_Int8> ()); + else + { // xmlsec05: message box for wrong password + break; + } } } |