Fix tracker project actions

Signed-off-by: Artem Savchenko <armisav@gmail.com>
This commit is contained in:
Artem Savchenko
2026-04-20 08:20:22 +07:00
parent db97de7c63
commit 586c6562bd
+25 -10
View File
@@ -27,6 +27,16 @@ import { getClient } from '@hcengineering/presentation'
import { get } from 'svelte/store'
import { spaceSpace } from './utils'
function convertToSingleDoc (doc?: Doc | Doc[]): Doc | undefined {
if (doc === undefined) {
return undefined
}
if (Array.isArray(doc)) {
return doc.length === 1 ? doc[0] : undefined
}
return doc
}
function isTypedSpace (space: Space): space is TypedSpace {
return getClient().getHierarchy().isDerived(space._class, core.class.TypedSpace)
}
@@ -58,11 +68,12 @@ export async function canDeleteObject (doc?: Doc | Doc[]): Promise<boolean> {
}
export async function canEditSpace (doc?: Doc | Doc[]): Promise<boolean> {
if (doc === undefined || Array.isArray(doc)) {
const one = convertToSingleDoc(doc)
if (one === undefined) {
return false
}
const space = doc as Space
const space = one as Space
if (isSpaceOwner(space)) {
return true
@@ -84,11 +95,12 @@ export async function canEditSpace (doc?: Doc | Doc[]): Promise<boolean> {
}
export async function canArchiveSpace (doc?: Doc | Doc[]): Promise<boolean> {
if (doc === undefined || Array.isArray(doc)) {
const one = convertToSingleDoc(doc)
if (one === undefined) {
return false
}
const space = doc as Space
const space = one as Space
if (isSpaceOwner(space)) {
return true
@@ -110,11 +122,12 @@ export async function canArchiveSpace (doc?: Doc | Doc[]): Promise<boolean> {
}
export async function canDeleteSpace (doc?: Doc | Doc[]): Promise<boolean> {
if (doc === undefined || Array.isArray(doc)) {
const one = convertToSingleDoc(doc)
if (one === undefined) {
return false
}
const space = doc as Space
const space = one as Space
if (isSpaceOwner(space)) {
return true
@@ -132,21 +145,23 @@ export async function canDeleteSpace (doc?: Doc | Doc[]): Promise<boolean> {
}
export async function canJoinSpace (doc?: Doc | Doc[]): Promise<boolean> {
if (doc === undefined || Array.isArray(doc)) {
const one = convertToSingleDoc(doc)
if (one === undefined) {
return false
}
const space = doc as Space
const space = one as Space
return !(space.members ?? []).includes(getCurrentAccount().uuid)
}
export async function canLeaveSpace (doc?: Doc | Doc[]): Promise<boolean> {
if (doc === undefined || Array.isArray(doc)) {
const one = convertToSingleDoc(doc)
if (one === undefined) {
return false
}
const space = doc as Space
const space = one as Space
return (space.members ?? []).includes(getCurrentAccount().uuid)
}