Comment widget now supports 'only edit my own comments' access rule

This commit is contained in:
Rainer Simon 2020-09-14 12:13:47 +02:00
parent bf5da9d2d5
commit b02ad98dd5
1 changed files with 26 additions and 1 deletions

View File

@ -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) =>
<Comment
key={idx}
readOnly={props.readOnly}
readOnly={isReadOnly(body)}
body={body}
onUpdate={props.onUpdateBody}
onDelete={props.onRemoveBody}