summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2018-10-18 11:44:11 +0300
committerJustin Luth <justin_luth@sil.org>2018-10-31 05:00:21 +0100
commit3955e5efc225b184b9507db94c226c031a602168 (patch)
tree7154c64e3f0518d583e01528fb55ff5acb62b289 /sw
parentdc2509bca4f503c11cdde16779363a5aae67185f (diff)
writerfilter: implement formprot
The document properly opens with all sections protected because document protection (forms view) is enabled. However, when that setting was toggled off, all sections wrongly became unprotected, and remained unprotected when round-tripped (including in Word - so loss of configuration). Word does protection differently. It opens up in a forms only mode, but upon enabling editing mode, the individual sections can still be protected. Only when global enforcement is disabled do all sections become editable. So, if global enforcement is enabled, map the section protection to LO native protection. On startup, the sections will all be protected because of the global compatibility flag. If the flag is turned off, then you enter a similar mode to Word's "Edit document" where the sections are still protected. In LO, *each* section's protection must be turned off individually to fully disable enforcement. This patch keeps the same three-step process to fully edit the entire document, but the meanings take on a different form. "Compatability: Protect Form" changes from "enforcement" to "edit document" in concept. BTW, that matches how export works, where PROTECT_FORM is auto-enabled if any sections are protected. Section protection in LO can be disabled through Format - Sections - Write Protection. Patch initially developed to support tdf#120499. It depends on an earlier commit in order to round-trip. Change-Id: I8a2399f79640115d689ae9093792eecef7dbaeec Reviewed-on: https://gerrit.libreoffice.org/61918 Tested-by: Jenkins Reviewed-by: Justin Luth <justin_luth@sil.org>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport5.cxx7
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport8.cxx15
2 files changed, 22 insertions, 0 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
index 401af06a6533..be20dd24b246 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
@@ -995,6 +995,13 @@ DECLARE_OOXMLEXPORT_TEST(testSectionProtection, "sectionprot.odt")
assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "enforcement", "true");
assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "edit", "forms");
}
+
+ uno::Reference<text::XTextSectionsSupplier> xTextSectionsSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xSections(xTextSectionsSupplier->getTextSections(), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xSect(xSections->getByIndex(0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("TextSection is protected", true, getProperty<bool>(xSect, "IsProtected"));
+ xSect.set(xSections->getByIndex(1), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Section1 is protected", false, getProperty<bool>(xSect, "IsProtected"));
}
DECLARE_OOXMLEXPORT_TEST(tdf66398_permissions, "tdf66398_permissions.docx")
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
index f460e384fd53..b42933eb3513 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
@@ -18,6 +18,7 @@
#include <swmodeltestbase.hxx>
+#include <IDocumentSettingAccess.hxx>
#include <com/sun/star/awt/XBitmap.hpp>
#include <com/sun/star/awt/FontUnderline.hpp>
#include <com/sun/star/awt/FontWeight.hpp>
@@ -798,6 +799,20 @@ DECLARE_OOXMLEXPORT_TEST(testFdo53985, "fdo53985.docx")
uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables( ), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xTables->getCount()); // Only 4 tables were imported.
+
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+ CPPUNIT_ASSERT_MESSAGE("Compatibility: Protect form", pDoc->getIDocumentSettingAccess().get( DocumentSettingId::PROTECT_FORM ) );
+
+ uno::Reference<text::XTextSectionsSupplier> xTextSectionsSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xSections(xTextSectionsSupplier->getTextSections(), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xSections->getCount()); // The first paragraph wasn't counted as a section.
+
+ uno::Reference<beans::XPropertySet> xSect(xSections->getByIndex(0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("TextSection is protected", true, getProperty<bool>(xSect, "IsProtected"));
+ xSect.set(xSections->getByIndex(3), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Section3 is protected", false, getProperty<bool>(xSect, "IsProtected"));
}
DECLARE_OOXMLEXPORT_TEST(testFdo59638, "fdo59638.docx")