From b02ad98dd5ca4262c4ca0f87d03a98ba9eb6cd3a Mon Sep 17 00:00:00 2001 From: Rainer Simon Date: Mon, 14 Sep 2020 12:13:47 +0200 Subject: [PATCH] Comment widget now supports 'only edit my own comments' access rule --- src/editor/widgets/comment/CommentWidget.jsx | 27 +++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/editor/widgets/comment/CommentWidget.jsx b/src/editor/widgets/comment/CommentWidget.jsx index 8fc5c84..d312023 100644 --- a/src/editor/widgets/comment/CommentWidget.jsx +++ b/src/editor/widgets/comment/CommentWidget.jsx @@ -49,12 +49,37 @@ const CommentWidget = props => { } } + // A comment should be read-only if: + // - the global read-only flag is set + // - the current rule is 'MINE_ONLY' and the creator ID differs + // The 'editable' config flag overrides the global setting, if any + const isReadOnly = body => { + if (props.editable === true) + return false; + + if (props.editable === false) + return true; + + if (props.editable === 'MINE_ONLY') { + // The original creator of the body + const creator = body.creator?.id; + + // The current user + const me = Environment.user; + + return !(me === creator); + } + + // Global setting as last possible option + return props.readOnly; + } + return ( <> { comments.map((body, idx) =>