summaryrefslogtreecommitdiff
path: root/sw/source/uibase
diff options
context:
space:
mode:
authorJaume Pujantell <jaume.pujantell@collabora.com>2024-08-29 15:32:01 +0200
committerMike Kaganski <mike.kaganski@collabora.com>2024-09-03 06:40:41 +0200
commitf93d46429c68770dd432fa6e7edcfc876891f8e1 (patch)
treeccc6a90dfb047b0a198e331344854b3ef7eb8372 /sw/source/uibase
parent832eee15118babf772f19a820ef88603fb6e5ccd (diff)
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 <jenkinscollaboraoffice@gmail.com> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sw/source/uibase')
-rw-r--r--sw/source/uibase/shells/textfld.cxx45
1 files changed, 36 insertions, 9 deletions
diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx
index 6e3ff742cf20..20f21bb92355 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();
@@ -385,12 +402,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;
}
@@ -399,12 +421,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;
}
@@ -440,8 +466,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:
@@ -512,7 +539,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);