From 260d8d95fd87b9b4919f11bc38583c47d071c1e0 Mon Sep 17 00:00:00 2001 From: Denis Bunakalya Date: Thu, 28 Apr 2022 21:15:24 +0300 Subject: [PATCH] Chunter: Remove attachments only for creator (#1552) Signed-off-by: Denis Bunakalya --- plugins/attachment-assets/lang/en.json | 5 +-- plugins/attachment-assets/lang/ru.json | 5 +-- .../components/AttachmentsGalleryView.svelte | 33 ++++++++++++++----- .../src/components/AttachmentsListView.svelte | 33 ++++++++++++++----- plugins/attachment/src/index.ts | 3 +- .../EditChannelDescriptionAttachments.svelte | 31 +++++++++++++---- 6 files changed, 82 insertions(+), 28 deletions(-) diff --git a/plugins/attachment-assets/lang/en.json b/plugins/attachment-assets/lang/en.json index 4d247b40f2..76fee8aff4 100644 --- a/plugins/attachment-assets/lang/en.json +++ b/plugins/attachment-assets/lang/en.json @@ -43,6 +43,7 @@ "FileBrowserTypeFilterVideos": "Videos", "FileBrowserTypeFilterPDFs": "PDFs", "AddAttachmentToSaved": "Add attachment to saved", - "RemoveAttachmentFromSaved": "Remove attachment from saved" + "RemoveAttachmentFromSaved": "Remove attachment from saved", + "DeleteFile": "Delete file" } -} \ No newline at end of file +} diff --git a/plugins/attachment-assets/lang/ru.json b/plugins/attachment-assets/lang/ru.json index 26cb12db98..61b976f6a1 100644 --- a/plugins/attachment-assets/lang/ru.json +++ b/plugins/attachment-assets/lang/ru.json @@ -43,6 +43,7 @@ "FileBrowserTypeFilterVideos": "Видео", "FileBrowserTypeFilterPDFs": "PDF-файлы", "AddAttachmentToSaved": "Добавить вложение в сохраненные", - "RemoveAttachmentFromSaved": "Удалить вложение из сохраненных" + "RemoveAttachmentFromSaved": "Удалить вложение из сохраненных", + "DeleteFile": "Удалить файл" } -} \ No newline at end of file +} diff --git a/plugins/attachment-resources/src/components/AttachmentsGalleryView.svelte b/plugins/attachment-resources/src/components/AttachmentsGalleryView.svelte index b8dfef82da..6216c5b07a 100644 --- a/plugins/attachment-resources/src/components/AttachmentsGalleryView.svelte +++ b/plugins/attachment-resources/src/components/AttachmentsGalleryView.svelte @@ -13,22 +13,39 @@ // limitations under the License. --> diff --git a/plugins/attachment-resources/src/components/AttachmentsListView.svelte b/plugins/attachment-resources/src/components/AttachmentsListView.svelte index cdfbe5df79..2607cd4d67 100644 --- a/plugins/attachment-resources/src/components/AttachmentsListView.svelte +++ b/plugins/attachment-resources/src/components/AttachmentsListView.svelte @@ -13,22 +13,39 @@ // limitations under the License. --> diff --git a/plugins/attachment/src/index.ts b/plugins/attachment/src/index.ts index ca1be55b11..23b030ec0e 100644 --- a/plugins/attachment/src/index.ts +++ b/plugins/attachment/src/index.ts @@ -83,6 +83,7 @@ export default plugin(attachmentId, { FileBrowserTypeFilterImages: '' as IntlString, FileBrowserTypeFilterAudio: '' as IntlString, FileBrowserTypeFilterVideos: '' as IntlString, - FileBrowserTypeFilterPDFs: '' as IntlString + FileBrowserTypeFilterPDFs: '' as IntlString, + DeleteFile: '' as IntlString } }) diff --git a/plugins/chunter-resources/src/components/EditChannelDescriptionAttachments.svelte b/plugins/chunter-resources/src/components/EditChannelDescriptionAttachments.svelte index 0dbed03731..8e36c43503 100644 --- a/plugins/chunter-resources/src/components/EditChannelDescriptionAttachments.svelte +++ b/plugins/chunter-resources/src/components/EditChannelDescriptionAttachments.svelte @@ -17,12 +17,13 @@ import attachment, { Attachment } from '@anticrm/attachment' import { AttachmentPresenter, FileDownload } from '@anticrm/attachment-resources' import { ChunterSpace } from '@anticrm/chunter' - import { Doc, SortingOrder } from '@anticrm/core' - import { createQuery, getFileUrl } from '@anticrm/presentation' - import { Menu } from '@anticrm/view-resources' - import { getCurrentLocation, showPopup, IconMoreV, Label, navigate, Icon } from '@anticrm/ui' + import { Doc, SortingOrder, getCurrentAccount } from '@anticrm/core' + import { createQuery, getFileUrl, getClient } from '@anticrm/presentation' + import { getCurrentLocation, showPopup, IconMoreV, Label, navigate, Icon, Menu } from '@anticrm/ui' export let channel: ChunterSpace | undefined + const myAccId = getCurrentAccount()._id + const client = getClient() const query = createQuery() let visibleAttachments: Attachment[] | undefined @@ -33,9 +34,25 @@ const showMenu = async (ev: MouseEvent, object: Doc, rowNumber: number): Promise => { selectedRowNumber = rowNumber - showPopup(Menu, { object }, ev.target as HTMLElement, () => { - selectedRowNumber = undefined - }) + showPopup( + Menu, + { + actions: [ + ...(myAccId === object.modifiedBy + ? [ + { + label: attachment.string.DeleteFile, + action: async () => await client.removeDoc(object._class, object.space, object._id) + } + ] + : []) + ] + }, + ev.target as HTMLElement, + () => { + selectedRowNumber = undefined + } + ) } $: channel &&