mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-23 03:22:19 +03:00
EQMS-1033 Filter out readonly projects when creating new controlled document (#5912)
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
parent
6295b1fb42
commit
0b67f831da
@ -116,7 +116,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function selectProject (space: DocumentSpace): Promise<void> {
|
async function selectProject (space: DocumentSpace): Promise<void> {
|
||||||
project = getCurrentProject(space._id) ?? (await getLatestProjectId(space._id)) ?? documents.ids.NoProject
|
project = getCurrentProject(space._id) ?? (await getLatestProjectId(space._id, true)) ?? documents.ids.NoProject
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleDocumentSelected (doc: WithLookup<ProjectDocument>): void {
|
function handleDocumentSelected (doc: WithLookup<ProjectDocument>): void {
|
||||||
|
@ -15,6 +15,7 @@ import core, {
|
|||||||
type AttachedData,
|
type AttachedData,
|
||||||
type Class,
|
type Class,
|
||||||
type Doc,
|
type Doc,
|
||||||
|
type DocumentQuery,
|
||||||
type Hierarchy,
|
type Hierarchy,
|
||||||
type Ref,
|
type Ref,
|
||||||
type Tx,
|
type Tx,
|
||||||
@ -689,16 +690,22 @@ export function setCurrentProject (space: Ref<DocumentSpace>, project: Ref<Proje
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getLatestProject (space: Ref<DocumentSpace>): Promise<Project | undefined> {
|
async function getLatestProject (space: Ref<DocumentSpace>, includeReadonly = false): Promise<Project | undefined> {
|
||||||
const client = getClient()
|
const client = getClient()
|
||||||
return await client.findOne(
|
|
||||||
documents.class.Project,
|
// TODO we should use better approach on selecting the latest available project
|
||||||
{ space },
|
// consider assigning sequential numbers to projects
|
||||||
{ limit: 1, sort: { createdOn: SortingOrder.Descending } }
|
const query: DocumentQuery<Project> = includeReadonly ? { space } : { space, readonly: false }
|
||||||
)
|
return await client.findOne(documents.class.Project, query, {
|
||||||
|
limit: 1,
|
||||||
|
sort: { createdOn: SortingOrder.Descending }
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getLatestProjectId (spaceRef: Ref<DocumentSpace>): Promise<Ref<Project> | undefined> {
|
export async function getLatestProjectId (
|
||||||
|
spaceRef: Ref<DocumentSpace>,
|
||||||
|
includeReadonly = false
|
||||||
|
): Promise<Ref<Project> | undefined> {
|
||||||
const client = getClient()
|
const client = getClient()
|
||||||
const space = await client.findOne(
|
const space = await client.findOne(
|
||||||
documents.class.DocumentSpace,
|
documents.class.DocumentSpace,
|
||||||
@ -714,7 +721,7 @@ export async function getLatestProjectId (spaceRef: Ref<DocumentSpace>): Promise
|
|||||||
|
|
||||||
if (space !== undefined) {
|
if (space !== undefined) {
|
||||||
if (space.$lookup?.type?.projects ?? false) {
|
if (space.$lookup?.type?.projects ?? false) {
|
||||||
const project = await getLatestProject(spaceRef)
|
const project = await getLatestProject(spaceRef, includeReadonly)
|
||||||
return project?._id
|
return project?._id
|
||||||
} else {
|
} else {
|
||||||
return documents.ids.NoProject
|
return documents.ids.NoProject
|
||||||
|
Loading…
Reference in New Issue
Block a user