include/sfx2/strings.hrc                      |    2 -
 sfx2/source/control/templatelocalview.cxx     |    2 -
 sw/qa/extras/ooxmlexport/data/tdf106843.fodt  |   43 ++++++++++++++++++++++++++
 sw/qa/extras/ooxmlexport/ooxmlexport5.cxx     |   10 ++++++
 sw/source/filter/ww8/docxexport.cxx           |   31 +++++++++++++++++-
 sw/source/uibase/uiview/view2.cxx             |   42 ++++++++++++++++++-------
 writerfilter/source/dmapper/SettingsTable.cxx |   35 +++++++++++++++------
 7 files changed, 139 insertions(+), 26 deletions(-)

New commits:
commit 2756ed9317e3474003c11ffe7d1e2f087c1412bf
Author:     László Németh <[email protected]>
AuthorDate: Mon Oct 14 17:50:47 2019 +0200
Commit:     László Németh <[email protected]>
CommitDate: Wed Oct 16 12:15:16 2019 +0200

    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 <[email protected]>
    Tested-by: László Németh <[email protected]>

diff --git a/include/sfx2/strings.hrc b/include/sfx2/strings.hrc
index 6a4702d5e0f0..d1196842d36c 100644
--- a/include/sfx2/strings.hrc
+++ b/include/sfx2/strings.hrc
@@ -32,7 +32,7 @@
 #define STR_DEFAULT_TEMPLATE                    NC_("STR_DEFAULT_TEMPLATE", 
"Set As Default")
 #define STR_RESET_DEFAULT                       NC_("STR_RESET_DEFAULT", 
"Reset Default")
 #define STR_DELETE                              NC_("STR_DELETE", "Delete")
-#define STR_RENAME                              NC_("STR_RENAME", "Rename")
+#define STR_SFX_RENAME                          NC_("STR_SFX_RENAME", "Rename")
 #define STR_CATEGORY_RENAME                     NC_("STR_CATEGORY_RENAME", 
"Rename Category")
 #define STR_RENAME_TEMPLATE                     NC_("STR_RENAME_TEMPLATE", 
"Enter New Name: ")
 #define STR_TEMPLATE_TOOLTIP                    NC_("STR_TEMPLATE_TOOLTIP", 
"Title: $1\nCategory: $2")
diff --git a/sfx2/source/control/templatelocalview.cxx 
b/sfx2/source/control/templatelocalview.cxx
index 6eb22537e004..2242170cb1f0 100644
--- a/sfx2/source/control/templatelocalview.cxx
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -605,7 +605,7 @@ void SfxTemplateLocalView::createContextMenu(const bool 
bIsDefault)
         mxContextMenu->append("default",SfxResId(STR_RESET_DEFAULT));
 
     mxContextMenu->append_separator("separator");
-    mxContextMenu->append("rename",SfxResId(STR_RENAME));
+    mxContextMenu->append("rename",SfxResId(STR_SFX_RENAME));
     mxContextMenu->append("delete",SfxResId(STR_DELETE));
     deselectItems();
     maSelectedItem->setSelection(true);
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:oas
 is: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;
+                        }
                     }
                 }
 
diff --git a/writerfilter/source/dmapper/SettingsTable.cxx 
b/writerfilter/source/dmapper/SettingsTable.cxx
index 5e14f3c1b7be..337b250ebc20 100644
--- a/writerfilter/source/dmapper/SettingsTable.cxx
+++ b/writerfilter/source/dmapper/SettingsTable.cxx
@@ -113,10 +113,6 @@ namespace dmapper
         }
 
         bool isNone()           const { return m_nEdit == 
NS_ooxml::LN_Value_doc_ST_DocProtect_none; };
-        // bool isReadOnly()       const { return m_nEdit == 
NS_ooxml::LN_Value_doc_ST_DocProtect_readOnly; };
-        // bool isComments()       const { return m_nEdit == 
NS_ooxml::LN_Value_doc_ST_DocProtect_comments; };
-        bool isTrackChanges()   const { return m_nEdit == 
NS_ooxml::LN_Value_doc_ST_DocProtect_trackedChanges; };
-        bool isForms()          const { return m_nEdit == 
NS_ooxml::LN_Value_doc_ST_DocProtect_forms; };
     };
 
     css::uno::Sequence<css::beans::PropertyValue> 
DocumentProtection_Impl::toSequence() const
@@ -254,6 +250,7 @@ struct SettingsTable_Impl
     bool                m_bDoNotExpandShiftReturn;
     bool                m_bProtectForm;
     bool                m_bRedlineProtection;
+    OUString            m_sRedlineProtectionKey;
     bool                m_bDisplayBackgroundShape;
 
     uno::Sequence<beans::PropertyValue> m_pThemeFontLangProps;
@@ -286,6 +283,7 @@ struct SettingsTable_Impl
     , m_bDoNotExpandShiftReturn(false)
     , m_bProtectForm(false)
     , m_bRedlineProtection(false)
+    , m_sRedlineProtectionKey()
     , m_bDisplayBackgroundShape(false)
     , m_pThemeFontLangProps(3)
     , m_pCurrentCompatSetting(3)
@@ -349,13 +347,30 @@ void SettingsTable::lcl_attribute(Id nName, Value & val)
         break;
     case NS_ooxml::LN_CT_DocProtect_edit: // 92037
         m_pImpl->m_DocumentProtection.m_nEdit = nIntValue;
-        m_pImpl->m_bProtectForm = m_pImpl->m_DocumentProtection.isForms();
-        m_pImpl->m_bRedlineProtection = 
m_pImpl->m_DocumentProtection.isTrackChanges();
+        switch (nIntValue)
+        {
+        case NS_ooxml::LN_Value_doc_ST_DocProtect_trackedChanges:
+        {
+            m_pImpl->m_bRedlineProtection = true;
+            m_pImpl->m_sRedlineProtectionKey = 
m_pImpl->m_DocumentProtection.m_sHash;
+            break;
+        }
+        case NS_ooxml::LN_Value_doc_ST_DocProtect_forms:
+            m_pImpl->m_bProtectForm = true;
+            break;
+        }
         break;
     case NS_ooxml::LN_CT_DocProtect_enforcement: // 92039
         m_pImpl->m_DocumentProtection.m_bEnforcement = (nIntValue != 0);
-        m_pImpl->m_bProtectForm &= static_cast<bool>(nIntValue);
-        m_pImpl->m_bRedlineProtection &= static_cast<bool>(nIntValue);
+        switch (m_pImpl->m_DocumentProtection.m_nEdit)
+        {
+        case NS_ooxml::LN_Value_doc_ST_DocProtect_trackedChanges:
+            m_pImpl->m_bRedlineProtection = (nIntValue != 0);
+            break;
+        case NS_ooxml::LN_Value_doc_ST_DocProtect_forms:
+            m_pImpl->m_bProtectForm = (nIntValue != 0);
+            break;
+        }
         break;
     case NS_ooxml::LN_CT_DocProtect_formatting: // 92038
         m_pImpl->m_DocumentProtection.m_bFormatting = (nIntValue != 0);
@@ -669,8 +684,8 @@ void 
SettingsTable::ApplyProperties(uno::Reference<text::XTextDocument> const& x
         // Password protected Record changes
         if ( m_pImpl->m_bRecordChanges && m_pImpl->m_bRedlineProtection )
         {
-            // use dummy protection key to forbid disabling of Record changes 
(extending the recent GrabBag support)
-            // TODO support password verification and DOCX export of 
RedlineProtectionKey...
+            // use dummy protection key to forbid disabling of Record changes 
without a notice
+            // (extending the recent GrabBag support)    TODO support password 
verification...
             css::uno::Sequence<sal_Int8> aDummyKey(1);
             aDummyKey[0] = 1;
             xDocProps->setPropertyValue("RedlineProtectionKey", uno::makeAny( 
aDummyKey ));
_______________________________________________
Libreoffice-commits mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to