summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2020-03-11 10:09:29 +0300
committerMiklos Vajna <vmiklos@collabora.com>2020-04-01 10:15:29 +0200
commit3af7be613526404276210a698f77e0187831b9b1 (patch)
treece9c850bb6f77b9084e8d39c7d3d94859103cd3c /sw/source
parent957092a29ff0626ead52ae776f004c08e93116b0 (diff)
tdf#120852 writerfilter: support read-only docProtection
Setting the document to LoadReadonly nicely does not prompt the user to "press this button to edit". That is what we would generally want when Read-Only is enforced, so lets use that. The user can easily enter edit mode via the edit menu, if they want to temporarily override the protection, which seems natural and discoverable enough. There is a File menu - Properties - Security option that manages the LoadReadonly setting in LO. If the user turns that off, then export will also cancel enforcement of the readOnly grabbag item. The situation where read-only was not enforced before, but now is enforced by LO, is handled by _MarkAsFinal, so that case is ignored. In other words, there was no point in adding a WriterWantsToProtectReadOnly flag. See tdf#107690 for _MarkAsFinal fix. I had started going down the wrong patch of being innovative with boolean &=, not realizing that it now always evaluated the right side. Remove that bad example for other cut-and-pasters. In the end, this logic is much easier to understand anyway. Change-Id: Id26b283078a5fd62d662a26a96cfc461e0ba8459 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90323 Tested-by: Jenkins Reviewed-by: Justin Luth <justin_luth@sil.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/filter/ww8/docxexport.cxx31
1 files changed, 23 insertions, 8 deletions
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index ae63a3e13a2c..f9af8d2937cf 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -1083,12 +1083,13 @@ void DocxExport::WriteSettings()
// Has themeFontLang information
uno::Reference< beans::XPropertySet > xPropSet( m_pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
- bool hasProtectionProperties = false;
+ bool bUseGrabBagProtection = false;
bool bWriterWantsToProtect = false;
bool bWriterWantsToProtectForm = false;
bool bWriterWantsToProtectRedline = false;
bool bHasRedlineProtectionKey = false;
bool bHasDummyRedlineProtectionKey = false;
+ bool bReadOnlyStatusUnchanged = true;
uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
if ( m_pDoc->getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_FORM) ||
m_pSections->DocumentIsProtected() )
@@ -1236,18 +1237,32 @@ void DocxExport::WriteSettings()
pAttributeList->add(FSNS(XML_w, nToken), sValue.toUtf8());
if ( nToken == XML_edit && sValue == "trackedChanges" )
bIsProtectionTrackChanges = true;
+ else if ( nToken == XML_edit && sValue == "readOnly" )
+ {
+ // Ignore the case where read-only was not enforced, but now is. That is handled by _MarkAsFinal
+ bReadOnlyStatusUnchanged = m_pDoc->GetDocShell()->IsSecurityOptOpenReadOnly();
+ }
else if ( nToken == XML_enforcement )
bEnforced = sValue.toBoolean();
}
}
// we have document protection from input DOCX file
- // and in the case of change tracking protection, we didn't modify it
- hasProtectionProperties = !bIsProtectionTrackChanges || bHasDummyRedlineProtectionKey;
- // use grabbag if still valid/enforced
- // or leave as an un-enforced suggestion if Writer doesn't want to set any enforcement
- hasProtectionProperties &= bEnforced || !bWriterWantsToProtect;
- if ( hasProtectionProperties )
+ if ( !bEnforced )
+ {
+ // Leave as an un-enforced suggestion if Writer doesn't want to set any enforcement
+ bUseGrabBagProtection = !bWriterWantsToProtect;
+ }
+ else
+ {
+ // Check if the grabbag protection is still valid
+ // In the case of change tracking protection, we didn't modify it
+ // and in the case of read-only, we didn't modify it.
+ bUseGrabBagProtection = (!bIsProtectionTrackChanges || bHasDummyRedlineProtectionKey)
+ && bReadOnlyStatusUnchanged;
+ }
+
+ if ( bUseGrabBagProtection )
{
sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
pFS->singleElementNS(XML_w, XML_documentProtection, xAttributeList);
@@ -1276,7 +1291,7 @@ void DocxExport::WriteSettings()
WriteDocVars(pFS);
- if (! hasProtectionProperties)
+ if ( !bUseGrabBagProtection )
{
// Protect form - highest priority
// Section-specific write protection