summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--desktop/qa/desktop_lib/test_desktop_lib.cxx9
-rw-r--r--sw/source/uibase/shells/textfld.cxx45
2 files changed, 41 insertions, 13 deletions
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index cfacc5cc4086..d013de5cf20f 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -2677,10 +2677,11 @@ void DesktopLOKTest::testCommentsInReadOnlyMode()
// Comments callback are emitted only if tiled annotations are off
comphelper::LibreOfficeKit::setTiledAnnotations(false);
LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
- pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
+ OString aUserName("LOK User1"_ostr);
+ OString aArguments = "{\".uno:Author\":{\"type\":\"string\",\"value\":\"" + aUserName + "\"}}";
+ pDocument->m_pDocumentClass->initializeForRendering(pDocument, aArguments.getStr());
- int viewId = pDocument->m_pDocumentClass->createView(pDocument);
- pDocument->m_pDocumentClass->setView(pDocument, viewId);
+ int viewId = pDocument->m_pDocumentClass->getView(pDocument);
SfxLokHelper::setViewReadOnly(viewId, true);
SfxLokHelper::setAllowChangeComments(viewId, true);
@@ -2694,7 +2695,7 @@ void DesktopLOKTest::testCommentsInReadOnlyMode()
{
tools::JsonWriter aJson;
addParameter(aJson, "Text", "string", "Comment");
- addParameter(aJson, "Author", "string", "LOK User1");
+ addParameter(aJson, "Author", "string", aUserName);
aCommandArgs = aJson.finishAndGetAsOString();
}
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);