sw/source/uibase/shells/textfld.cxx |   45 ++++++++++++++++++++++++++++--------
 1 file changed, 36 insertions(+), 9 deletions(-)

New commits:
commit 26754f3c8577ce65c73b896b56456b5121941a62
Author:     Jaume Pujantell <jaume.pujant...@collabora.com>
AuthorDate: Thu Aug 29 15:32:01 2024 +0200
Commit:     Jaume Pujantell <jaume.pujant...@collabora.com>
CommitDate: Wed Sep 11 19:18:44 2024 +0200

    lok: sw: restrict deletions on comment only mode
    
    On Writer, when in readonly mode with comments activated restrict
    the hability to delete comments to only those made by the same user.
    
    Change-Id: Iaefb1166c680726c9c73a305ef67be812d3b97d2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172596
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit f93d46429c68770dd432fa6e7edcfc876891f8e1)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172890
    Reviewed-by: Andreas Mantke <andreas.man...@googlemail.com>
    Tested-by: Jenkins
    Reviewed-by: Jaume Pujantell <jaume.pujant...@collabora.com>

diff --git a/sw/source/uibase/shells/textfld.cxx 
b/sw/source/uibase/shells/textfld.cxx
index 1335958232eb..653b4a93df2a 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -114,6 +114,23 @@ static OUString lcl_BuildTitleWithRedline( const 
SwRangeRedline *pRedline )
     return sTitle + SwResId(pResId);
 }
 
+static bool lcl_canUserModifyAnnotation(const SwView& rView, 
std::u16string_view sAuthor)
+{
+    return !comphelper::LibreOfficeKit::isActive() || 
!rView.IsLokReadOnlyView()
+           || sAuthor == rView.GetRedlineAuthor();
+}
+
+static bool lcl_canUserModifyAnnotation(const SwView& rView,
+                                        const sw::annotation::SwAnnotationWin* 
pAnnotationWin)
+{
+    return lcl_canUserModifyAnnotation(rView, pAnnotationWin->GetAuthor());
+}
+
+static bool lcl_canUserModifyAnnotation(const SwView& rView, sal_uInt32 
nPostItId)
+{
+    return lcl_canUserModifyAnnotation(rView, 
rView.GetPostItMgr()->GetAnnotationWin(nPostItId));
+}
+
 void SwTextShell::ExecField(SfxRequest &rReq)
 {
     SwWrtShell& rSh = GetShell();
@@ -397,12 +414,17 @@ void SwTextShell::ExecField(SfxRequest &rReq)
             const SvxPostItIdItem* pIdItem = 
rReq.GetArg<SvxPostItIdItem>(SID_ATTR_POSTIT_ID);
             if (pIdItem && !pIdItem->GetValue().isEmpty() && 
GetView().GetPostItMgr())
             {
-                
GetView().GetPostItMgr()->Delete(pIdItem->GetValue().toUInt32());
+                sal_uInt32 nPostItId = pIdItem->GetValue().toUInt32();
+                if (lcl_canUserModifyAnnotation(GetView(), nPostItId))
+                    GetView().GetPostItMgr()->Delete(nPostItId);
             }
             else if ( GetView().GetPostItMgr() &&
                       GetView().GetPostItMgr()->HasActiveSidebarWin() )
             {
-                GetView().GetPostItMgr()->DeleteActiveSidebarWin();
+                sw::annotation::SwAnnotationWin* pAnnotationWin
+                    = GetView().GetPostItMgr()->GetActiveSidebarWin();
+                if (lcl_canUserModifyAnnotation(GetView(), pAnnotationWin))
+                    GetView().GetPostItMgr()->DeleteActiveSidebarWin();
             }
             break;
         }
@@ -411,12 +433,16 @@ void SwTextShell::ExecField(SfxRequest &rReq)
             const SvxPostItIdItem* pIdItem = 
rReq.GetArg<SvxPostItIdItem>(SID_ATTR_POSTIT_ID);
             if (pIdItem && !pIdItem->GetValue().isEmpty() && 
GetView().GetPostItMgr())
             {
-                
GetView().GetPostItMgr()->DeleteCommentThread(pIdItem->GetValue().toUInt32());
+                sal_uInt32 nPostItId = pIdItem->GetValue().toUInt32();
+                if (lcl_canUserModifyAnnotation(GetView(), nPostItId))
+                    GetView().GetPostItMgr()->DeleteCommentThread(nPostItId);
             }
-            else if ( GetView().GetPostItMgr() &&
-                        GetView().GetPostItMgr()->HasActiveSidebarWin() )
+            else if (GetView().GetPostItMgr() && 
GetView().GetPostItMgr()->HasActiveSidebarWin())
             {
-                GetView().GetPostItMgr()->DeleteActiveSidebarWin();
+                sw::annotation::SwAnnotationWin* pAnnotationWin
+                    = GetView().GetPostItMgr()->GetActiveSidebarWin();
+                if (lcl_canUserModifyAnnotation(GetView(), pAnnotationWin))
+                    GetView().GetPostItMgr()->DeleteActiveSidebarWin();
             }
             break;
         }
@@ -452,8 +478,9 @@ void SwTextShell::ExecField(SfxRequest &rReq)
         case FN_DELETE_NOTE_AUTHOR:
         {
             const SfxStringItem* pNoteItem = rReq.GetArg<SfxStringItem>(nSlot);
-            if ( pNoteItem && GetView().GetPostItMgr() )
-                GetView().GetPostItMgr()->Delete( pNoteItem->GetValue() );
+            if (pNoteItem && GetView().GetPostItMgr()
+                && lcl_canUserModifyAnnotation(GetView(), 
pNoteItem->GetValue()))
+                GetView().GetPostItMgr()->Delete(pNoteItem->GetValue());
         }
         break;
         case FN_HIDE_NOTE:
@@ -524,7 +551,7 @@ void SwTextShell::ExecField(SfxRequest &rReq)
                     sText = pTextItem->GetValue();
 
                 sw::annotation::SwAnnotationWin* pAnnotationWin = 
GetView().GetPostItMgr()->GetAnnotationWin(pIdItem->GetValue().toUInt32());
-                if (pAnnotationWin)
+                if (pAnnotationWin && lcl_canUserModifyAnnotation(GetView(), 
pAnnotationWin))
                 {
                     pAnnotationWin->UpdateText(sText);
 

Reply via email to