feat: only allow editing of a user's own comments

This commit is contained in:
kolaente 2022-06-16 17:45:23 +02:00
parent 3710735856
commit a3192c30e9
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -67,7 +67,7 @@
</div> </div>
<editor <editor
:hasPreview="true" :hasPreview="true"
:is-edit-enabled="canWrite" :is-edit-enabled="canWrite && c.author.id === currentUserId"
:upload-callback="attachmentUpload" :upload-callback="attachmentUpload"
:upload-enabled="true" :upload-enabled="true"
@change=" @change="
@ -190,6 +190,7 @@ const saved = ref(null)
const saving = ref(null) const saving = ref(null)
const userAvatar = computed(() => store.state.auth.info.getAvatarUrl(48)) const userAvatar = computed(() => store.state.auth.info.getAvatarUrl(48))
const currentUserId = computed(() => store.state.auth.info.id)
const enabled = computed(() => store.state.config.taskCommentsEnabled) const enabled = computed(() => store.state.config.taskCommentsEnabled)
const actions = computed(() => { const actions = computed(() => {
if (!props.canWrite) { if (!props.canWrite) {
@ -197,10 +198,12 @@ const actions = computed(() => {
} }
return Object.fromEntries(comments.value.map((comment) => ([ return Object.fromEntries(comments.value.map((comment) => ([
comment.id, comment.id,
[{ comment.author.id === currentUserId.value
? [{
action: () => toggleDelete(comment.id), action: () => toggleDelete(comment.id),
title: t('misc.delete'), title: t('misc.delete'),
}], }]
: [],
]))) ])))
}) })
@ -209,6 +212,7 @@ function attachmentUpload(...args) {
} }
const taskCommentService = shallowReactive(new TaskCommentService()) const taskCommentService = shallowReactive(new TaskCommentService())
async function loadComments(taskId) { async function loadComments(taskId) {
if (!enabled.value) { if (!enabled.value) {
return return
@ -228,6 +232,7 @@ watch(
const editorActive = ref(true) const editorActive = ref(true)
const creating = ref(false) const creating = ref(false)
async function addComment() { async function addComment() {
if (newComment.comment === '') { if (newComment.comment === '') {
return return
@ -301,7 +306,7 @@ async function deleteComment(commentToDelete: TaskCommentModel) {
<style lang="scss" scoped> <style lang="scss" scoped>
.media-left { .media-left {
margin: 0 1rem; margin: 0 1rem !important;
} }
.comment-info { .comment-info {