Bug 122201

Summary: FILESAVE DOCX Unable edit of unprotected areas in protected doc
Product: LibreOffice Reporter: Serge Krot (CIB) <serge.krot>
Component: WriterAssignee: Serge Krot (CIB) <serge.krot>
Status: RESOLVED FIXED    
Severity: normal CC: aron.budea, jluth, xiscofauli
Priority: medium Keywords: filter:docx
Version: unspecified   
Hardware: All   
OS: All   
See Also: https://bugs.documentfoundation.org/show_bug.cgi?id=121304
https://bugs.documentfoundation.org/show_bug.cgi?id=124451
https://bugs.documentfoundation.org/show_bug.cgi?id=125151
Whiteboard: target:6.2.0.2
Crash report or crash signature: Regression By:
Bug Depends on: 121304    
Bug Blocks: 120763    
Attachments: Original ODT document with text and one additional protected section

Description Serge Krot (CIB) 2018-12-19 15:32:15 UTC
Created attachment 147672 [details]
Original ODT document with text and one additional protected section

How to reproduce:
* resave of the attached ODT document (with one protected sections inside) into DOCX
* all content became protected including protected section.
Comment 1 Serge Krot (CIB) 2018-12-20 09:38:44 UTC
Patch development is here:
https://gerrit.libreoffice.org/#/c/65278/
Comment 2 Serge Krot (CIB) 2018-12-20 09:45:43 UTC
Question:

In unit test scenario, I would like to try to edit text inside protected section and outside it, to prove that LO prevents editing if area is protected. Unfortunately my code always allows to modify the text inside the DOM:

Code-1:
        uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
        uno::Reference<text::XText> xText(textDocument->getText(), uno::UNO_QUERY);
        uno::Reference<text::XTextRange> xParagraphInProtectedSection = getParagraphOfText( 1, xText ); 
        xParagraphInProtectedSection->setString(OUString( "New text" ));
        CPPUNIT_ASSERT_EQUAL( OUString( "Old text" ), xText->getString());

Code-2:
    // try to insert some text into protected area
    {
        SwNodeIndex aDocEnd(pDoc->GetNodes().GetEndOfContent());
        SwNodeIndex aDocStart(*aDocEnd.GetNode().StartOfSectionNode(), 3);
        SwPaM aPaM(aDocStart);
        pDoc->getIDocumentContentOperations().InsertString(aPaM, "New text");
    }

    // check if content was not changed
    {
        SwNodeIndex aDocEnd(pDoc->GetNodes().GetEndOfContent());
        SwNodeIndex aDocStart(*aDocEnd.GetNode().StartOfSectionNode(), 3);
        SwNode& rNode = aDocStart.GetNode();
        SwTextNode* pTextNode = rNode.GetTextNode();
        CPPUNIT_ASSERT(pTextNode);
        CPPUNIT_ASSERT_EQUAL(OUString("Old text"), pTextNode->GetText()); 
    }


Any ideas? Is it really possible to use protected areas in UNO interface to prevent modification of the content?
Comment 3 Commit Notification 2018-12-20 18:26:23 UTC
Serge Krot committed a patch related to this issue.
It has been pushed to "libreoffice-6-2":

https://git.libreoffice.org/core/+/63ec2e8d07dff652a68c9dc96859c4c61f26b9df%5E%21

tdf#122201 sw: DOCX: allow editing of unprotected areas in protected doc

It will be available in 6.2.0.2.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 4 Commit Notification 2019-01-18 18:12:10 UTC
Serge Krot committed a patch related to this issue.
It has been pushed to "libreoffice-6-1":

https://git.libreoffice.org/core/+/46c6c414a6df79575517f5df67510d6f4e3d0128%5E%21

tdf#122201 sw: DOCX: allow editing of unprotected areas in protected doc

It will be available in 6.1.6.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 5 Commit Notification 2019-01-21 14:28:25 UTC
Thorsten Behrens committed a patch related to this issue.
It has been pushed to "libreoffice-6-1":

https://git.libreoffice.org/core/+/a7fd527ece87a1c25fe0d8a9811fe2b230eeea88%5E%21

Revert "tdf#122201 sw: DOCX: allow editing of unprotected areas in protected doc"

It will be available in 6.1.6.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.