[Libreoffice-commits] core.git: Branch 'private/swe/libreoffice-5-2+backports' - sw/qa sw/source writerfilter/source

2017-10-18 Thread Serge Krot
Rebased ref, commits from common ancestor:
commit faa71d493a8c9ceab3a67ab7d5197d3b8ec020e2
Author: Serge Krot 
Date:   Fri Sep 29 18:01:54 2017 +0200

tdf#66398 Import/export docx document protection properties

This includes:
 - original fix, import/export of all doc protection properties
 - unit test
 - remove double initialization of the form protection
 - do not output document protection in docx twice
 - remove useless breaks
 - fix cid#1418980: Resource leak
 - parse and output permissions for DOCX using bookmarks
 - enhance unit test: check permissions at content level
 - fix copy-paste: call start() bookmark instead of end()

Conflicts:
sw/source/filter/ww8/docxexport.cxx
writerfilter/source/dmapper/DomainMapper.cxx
sw/source/filter/ww8/docxexport.cxx

Change-Id: I63bde881507dc3c5d123bbcf96b63027522ea569

diff --git a/sw/qa/extras/ooxmlexport/data/tdf66398_permissions.docx 
b/sw/qa/extras/ooxmlexport/data/tdf66398_permissions.docx
new file mode 100644
index ..d5c855994811
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf66398_permissions.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
index d4c99766b730..45f1aea29b82 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
@@ -963,6 +963,33 @@ DECLARE_OOXMLEXPORT_TEST(testSectionProtection, 
"sectionprot.odt")
 }
 }
 
+DECLARE_OOXMLEXPORT_TEST(tdf66398_permissions, "tdf66398_permissions.docx")
+{
+// check document permission settings for the whole document
+if (xmlDocPtr pXmlSettings = parseExport("word/settings.xml"))
+{
+assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "edit",  
 "readOnly");
+assertXPath(pXmlSettings, "/w:settings/w:documentProtection", 
"enforcement","1");
+assertXPath(pXmlSettings, "/w:settings/w:documentProtection", 
"cryptProviderType",  "rsaAES");
+assertXPath(pXmlSettings, "/w:settings/w:documentProtection", 
"cryptAlgorithmClass","hash");
+assertXPath(pXmlSettings, "/w:settings/w:documentProtection", 
"cryptAlgorithmType", "typeAny");
+assertXPath(pXmlSettings, "/w:settings/w:documentProtection", 
"cryptAlgorithmSid",  "14");
+assertXPath(pXmlSettings, "/w:settings/w:documentProtection", 
"cryptSpinCount", "10");
+assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "hash",  
 
"A0/Xy6KcXljJlZjP0TwJMPJuW2rc46UwXqn2ctxckc2nCECE5i89M85z2Noh3ZEA5NBQ9RJ5ycxiUH6nzmJaKw==");
+assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "salt",  
 "B8k6wb1pkjUs4Nv/8QBk/w==");
+}
+
+// get bookmark interface
+uno::Reference xBookmarksSupplier(mxComponent, 
uno::UNO_QUERY);
+uno::Reference 
xBookmarksByIdx(xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY);
+uno::Reference 
xBookmarksByName(xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY);
+
+// check: we have 2 bookmarks
+CPPUNIT_ASSERT_EQUAL(xBookmarksByIdx->getCount(), 
static_cast(2));
+CPPUNIT_ASSERT(xBookmarksByName->hasByName("_GoBack"));
+
CPPUNIT_ASSERT(xBookmarksByName->hasByName("permission-for-group:267014232:everyone"));
+}
+
 DECLARE_OOXMLEXPORT_TEST(testSectionHeader, "sectionprot.odt")
 {
 if (xmlDocPtr pXmlDoc = parseExport("word/document.xml"))
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index d37e9989a0e0..2b245545583c 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -1224,8 +1224,13 @@ void DocxAttributeOutput::EndRun()
 // if there is some redlining in the document, output it
 StartRedline( m_pRedlineData );
 
-DoWriteBookmarks( );
-DoWriteAnnotationMarks( );
+// XML_r node should be surrounded with bookmark-begin and bookmark-end 
nodes if it has bookmarks.
+// The same is applied for permission ranges.
+// But due to unit test "testFdo85542" let's output bookmark-begin with 
bookmark-end.
+DoWriteBookmarksStart();
+DoWriteBookmarksEnd();
+DoWritePermissionsStart();
+DoWriteAnnotationMarks();
 
 if( m_closeHyperlinkInThisRun && m_startedHyperlink && 
!m_hyperLinkAnchor.isEmpty() && m_hyperLinkAnchor.startsWith("_Toc"))
 {
@@ -1301,6 +1306,9 @@ void DocxAttributeOutput::EndRun()
 
 m_pSerializer->mergeTopMarks(Tag_StartRun_1);
 
+// XML_r node should be surrounded with permission-begin and 
permission-end nodes if it has permission.
+DoWritePermissionsEnd();
+
 for (std::vector::iterator it = 
m_aPostponedMaths.begin(); it != m_aPostponedMaths.end(); ++it)
 WritePostponedMath(*it);
 m_aPostponedMaths.clear();
@@ -1358,41 +1366,159 @@ void DocxAttributeOutput::EndRun()
 }
 }
 
-void 

[Libreoffice-commits] core.git: Branch 'private/swe/libreoffice-5-2+backports' - sw/qa sw/source writerfilter/source

2017-10-18 Thread Serge Krot
 sw/qa/extras/ooxmlexport/data/tdf66398_permissions.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport5.cxx   |   27 +
 sw/source/filter/ww8/docxattributeoutput.cxx|  211 ---
 sw/source/filter/ww8/docxattributeoutput.hxx|   15 +
 sw/source/filter/ww8/docxexport.cxx |   68 
 writerfilter/source/dmapper/DomainMapper.cxx|   24 +
 writerfilter/source/dmapper/DomainMapper_Impl.cxx   |  117 
 writerfilter/source/dmapper/DomainMapper_Impl.hxx   |   53 +++
 writerfilter/source/dmapper/SettingsTable.cxx   |  219 +++-
 writerfilter/source/dmapper/SettingsTable.hxx   |2 
 writerfilter/source/ooxml/factoryimpl.py|5 
 writerfilter/source/ooxml/factoryimpl_ns.py |6 
 writerfilter/source/ooxml/model.xml |   70 ++---
 13 files changed, 719 insertions(+), 98 deletions(-)

New commits:
commit 73046446ea6bae9a134092964505087f753663d7
Author: Serge Krot 
Date:   Fri Sep 29 18:01:54 2017 +0200

tdf#66398 Import/export docx document protection properties

This includes:
 - original fix, import/export of all doc protection properties
 - unit test
 - remove double initialization of the form protection
 - do not output document protection in docx twice
 - remove useless breaks
 - fix cid#1418980: Resource leak
 - parse and output permissions for DOCX using bookmarks
 - enhance unit test: check permissions at content level
 - fix copy-paste: call start() bookmark instead of end()

Conflicts:
sw/source/filter/ww8/docxexport.cxx
writerfilter/source/dmapper/DomainMapper.cxx
sw/source/filter/ww8/docxexport.cxx

Change-Id: I9a6fd248c58c10f4818779c1ceb81d60ffcea6c4

diff --git a/sw/qa/extras/ooxmlexport/data/tdf66398_permissions.docx 
b/sw/qa/extras/ooxmlexport/data/tdf66398_permissions.docx
new file mode 100644
index ..d5c855994811
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf66398_permissions.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
index d4c99766b730..45f1aea29b82 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
@@ -963,6 +963,33 @@ DECLARE_OOXMLEXPORT_TEST(testSectionProtection, 
"sectionprot.odt")
 }
 }
 
+DECLARE_OOXMLEXPORT_TEST(tdf66398_permissions, "tdf66398_permissions.docx")
+{
+// check document permission settings for the whole document
+if (xmlDocPtr pXmlSettings = parseExport("word/settings.xml"))
+{
+assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "edit",  
 "readOnly");
+assertXPath(pXmlSettings, "/w:settings/w:documentProtection", 
"enforcement","1");
+assertXPath(pXmlSettings, "/w:settings/w:documentProtection", 
"cryptProviderType",  "rsaAES");
+assertXPath(pXmlSettings, "/w:settings/w:documentProtection", 
"cryptAlgorithmClass","hash");
+assertXPath(pXmlSettings, "/w:settings/w:documentProtection", 
"cryptAlgorithmType", "typeAny");
+assertXPath(pXmlSettings, "/w:settings/w:documentProtection", 
"cryptAlgorithmSid",  "14");
+assertXPath(pXmlSettings, "/w:settings/w:documentProtection", 
"cryptSpinCount", "10");
+assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "hash",  
 
"A0/Xy6KcXljJlZjP0TwJMPJuW2rc46UwXqn2ctxckc2nCECE5i89M85z2Noh3ZEA5NBQ9RJ5ycxiUH6nzmJaKw==");
+assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "salt",  
 "B8k6wb1pkjUs4Nv/8QBk/w==");
+}
+
+// get bookmark interface
+uno::Reference xBookmarksSupplier(mxComponent, 
uno::UNO_QUERY);
+uno::Reference 
xBookmarksByIdx(xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY);
+uno::Reference 
xBookmarksByName(xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY);
+
+// check: we have 2 bookmarks
+CPPUNIT_ASSERT_EQUAL(xBookmarksByIdx->getCount(), 
static_cast(2));
+CPPUNIT_ASSERT(xBookmarksByName->hasByName("_GoBack"));
+
CPPUNIT_ASSERT(xBookmarksByName->hasByName("permission-for-group:267014232:everyone"));
+}
+
 DECLARE_OOXMLEXPORT_TEST(testSectionHeader, "sectionprot.odt")
 {
 if (xmlDocPtr pXmlDoc = parseExport("word/document.xml"))
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index d37e9989a0e0..2b245545583c 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -1224,8 +1224,13 @@ void DocxAttributeOutput::EndRun()
 // if there is some redlining in the document, output it
 StartRedline( m_pRedlineData );
 
-DoWriteBookmarks( );
-DoWriteAnnotationMarks( );
+// XML_r node should be surrounded with bookmark-begin and bookmark-end 
nodes if it has