mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-29 13:05:08 +02:00
Fix tracker project actions
Signed-off-by: Artem Savchenko <armisav@gmail.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user