Fix attachment spaces (#8200)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2025-03-11 17:14:07 +05:00 committed by Andrey Sobolev
parent 783d794d56
commit 0ba5e949f6
No known key found for this signature in database
GPG Key ID: BD80F68D68D8F7F2
2 changed files with 12 additions and 5 deletions

View File

@ -18,7 +18,7 @@
import { createQuery, getClient, getFileMetadata, uploadFile } from '@hcengineering/presentation'
import { ActionIcon, IconAdd, Label, Loading } from '@hcengineering/ui'
import type { Doc, WithLookup } from '@hcengineering/core'
import core, { Doc, Ref, Space, WithLookup } from '@hcengineering/core'
import { setPlatformStatus, unknownError } from '@hcengineering/platform'
import { AttachmentPresenter } from '..'
@ -59,8 +59,11 @@
try {
const uuid = await uploadFile(file)
const metadata = await getFileMetadata(file, uuid)
const space = client.getHierarchy().isDerived(object._class, core.class.Space)
? (object._id as Ref<Space>)
: object.space
await client.addCollection(attachment.class.Attachment, object.space, object._id, object._class, 'attachments', {
await client.addCollection(attachment.class.Attachment, space, object._id, object._class, 'attachments', {
name: file.name,
file: uuid,
type: file.type,

View File

@ -15,7 +15,7 @@
<script lang="ts">
import attachment, { Attachment, AttachmentsEvents } from '@hcengineering/attachment'
import contact from '@hcengineering/contact'
import { BlobMetadata, Doc, PersonId, Ref, generateId, type Blob } from '@hcengineering/core'
import core, { BlobMetadata, Doc, PersonId, Ref, generateId, type Blob } from '@hcengineering/core'
import { IntlString, getResource, setPlatformStatus, unknownError } from '@hcengineering/platform'
import {
FileOrBlob,
@ -173,13 +173,17 @@
try {
const _id: Ref<Attachment> = generateId()
const space = client.getHierarchy().isDerived(object._class, core.class.Space)
? (object._id as Ref<Space>)
: object.space
const attachmentDoc: Attachment = {
_id,
_class: attachment.class.Attachment,
collection: 'attachments',
modifiedOn: 0,
modifiedBy: '' as PersonId,
space: object.space,
space,
attachedTo: object._id,
attachedToClass: object._class,
name,
@ -192,7 +196,7 @@
await client.addCollection(
attachment.class.Attachment,
object.space,
space,
object._id,
object._class,
'attachments',