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:
Alexander Onnikov 2024-06-25 14:46:43 +07:00 committed by GitHub
parent 6295b1fb42
commit 0b67f831da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 9 deletions

View File

@ -116,7 +116,7 @@
}
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 {

View File

@ -15,6 +15,7 @@ import core, {
type AttachedData,
type Class,
type Doc,
type DocumentQuery,
type Hierarchy,
type Ref,
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()
return await client.findOne(
documents.class.Project,
{ space },
{ limit: 1, sort: { createdOn: SortingOrder.Descending } }
)
// TODO we should use better approach on selecting the latest available project
// consider assigning sequential numbers to projects
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 space = await client.findOne(
documents.class.DocumentSpace,
@ -714,7 +721,7 @@ export async function getLatestProjectId (spaceRef: Ref<DocumentSpace>): Promise
if (space !== undefined) {
if (space.$lookup?.type?.projects ?? false) {
const project = await getLatestProject(spaceRef)
const project = await getLatestProject(spaceRef, includeReadonly)
return project?._id
} else {
return documents.ids.NoProject