mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-19 23:00:13 +00:00
ezqms-1185: fix delete document availability (#6485)
Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
parent
286b7e29f9
commit
3eb7d6e965
@ -684,7 +684,7 @@ export function createModel (builder: Builder): void {
|
|||||||
input: 'any',
|
input: 'any',
|
||||||
category: view.category.General,
|
category: view.category.General,
|
||||||
target: documents.class.Document,
|
target: documents.class.Document,
|
||||||
visibilityTester: documents.function.IsLatestDraftDoc,
|
visibilityTester: documents.function.CanDeleteDocument,
|
||||||
query: {
|
query: {
|
||||||
state: DocumentState.Draft
|
state: DocumentState.Draft
|
||||||
},
|
},
|
||||||
|
@ -20,7 +20,8 @@ import {
|
|||||||
type RelatedDocument,
|
type RelatedDocument,
|
||||||
SortingOrder,
|
SortingOrder,
|
||||||
type WithLookup,
|
type WithLookup,
|
||||||
type Doc
|
type Doc,
|
||||||
|
getCurrentAccount
|
||||||
} from '@hcengineering/core'
|
} from '@hcengineering/core'
|
||||||
import {
|
import {
|
||||||
type Document,
|
type Document,
|
||||||
@ -31,6 +32,7 @@ import {
|
|||||||
import { type Resources } from '@hcengineering/platform'
|
import { type Resources } from '@hcengineering/platform'
|
||||||
import { type ObjectSearchResult, getClient, MessageBox } from '@hcengineering/presentation'
|
import { type ObjectSearchResult, getClient, MessageBox } from '@hcengineering/presentation'
|
||||||
import { showPopup } from '@hcengineering/ui'
|
import { showPopup } from '@hcengineering/ui'
|
||||||
|
import { type PersonAccount } from '@hcengineering/contact'
|
||||||
|
|
||||||
import CreateDocument from './components/CreateDocument.svelte'
|
import CreateDocument from './components/CreateDocument.svelte'
|
||||||
import QmsDocumentWizard from './components/create-doc/QmsDocumentWizard.svelte'
|
import QmsDocumentWizard from './components/create-doc/QmsDocumentWizard.svelte'
|
||||||
@ -148,6 +150,22 @@ async function deleteDocuments (obj: Document | Document[]): Promise<void> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function canDeleteDocument (obj?: Doc | Doc[]): Promise<boolean> {
|
||||||
|
if (obj == null) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const objs = (Array.isArray(obj) ? obj : [obj]) as Document[]
|
||||||
|
const currentUser = getCurrentAccount() as PersonAccount
|
||||||
|
const isOwner = objs.every((doc) => doc.owner === currentUser.person)
|
||||||
|
|
||||||
|
if (!isOwner) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return await isLatestDraftDoc(obj)
|
||||||
|
}
|
||||||
|
|
||||||
async function isLatestDraftDoc (obj?: Doc | Doc[]): Promise<boolean> {
|
async function isLatestDraftDoc (obj?: Doc | Doc[]): Promise<boolean> {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false
|
return false
|
||||||
@ -261,7 +279,7 @@ export default async (): Promise<Resources> => ({
|
|||||||
DocumentStateSort: sortDocumentStates,
|
DocumentStateSort: sortDocumentStates,
|
||||||
GetAllDocumentStates: getAllDocumentStates,
|
GetAllDocumentStates: getAllDocumentStates,
|
||||||
GetDocumentMetaLinkFragment: getDocumentMetaLinkFragment,
|
GetDocumentMetaLinkFragment: getDocumentMetaLinkFragment,
|
||||||
IsLatestDraftDoc: isLatestDraftDoc,
|
CanDeleteDocument: canDeleteDocument,
|
||||||
DocumentIdentifierProvider: documentIdentifierProvider,
|
DocumentIdentifierProvider: documentIdentifierProvider,
|
||||||
ControlledDocumentTitleProvider: getControlledDocumentTitle,
|
ControlledDocumentTitleProvider: getControlledDocumentTitle,
|
||||||
Comment: comment,
|
Comment: comment,
|
||||||
|
@ -231,7 +231,7 @@ export default mergeIds(documentsId, documents, {
|
|||||||
GetAllDocumentStates: '' as Resource<() => Promise<DocumentState[]>>,
|
GetAllDocumentStates: '' as Resource<() => Promise<DocumentState[]>>,
|
||||||
GetVisibleFilters: '' as Resource<(filters: KeyFilter[], space?: Ref<Space>) => Promise<KeyFilter[]>>,
|
GetVisibleFilters: '' as Resource<(filters: KeyFilter[], space?: Ref<Space>) => Promise<KeyFilter[]>>,
|
||||||
GetDocumentMetaLinkFragment: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<Location>>,
|
GetDocumentMetaLinkFragment: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<Location>>,
|
||||||
IsLatestDraftDoc: '' as Resource<(doc?: Doc | Doc[]) => Promise<boolean>>,
|
CanDeleteDocument: '' as Resource<(doc?: Doc | Doc[]) => Promise<boolean>>,
|
||||||
ControlledDocumentTitleProvider: '' as Resource<(client: Client, ref: Ref<Doc>, doc?: Doc) => Promise<string>>
|
ControlledDocumentTitleProvider: '' as Resource<(client: Client, ref: Ref<Doc>, doc?: Doc) => Promise<string>>
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user