UBERF-6486 Lock document content (#5799)

Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
Alexander Onnikov
2024-06-13 13:27:59 +07:00
committed by GitHub
parent bf969fb27d
commit a409cfafb3
13 changed files with 142 additions and 9 deletions
+36 -2
View File
@@ -15,6 +15,7 @@
import {
generateId,
getCurrentAccount,
type Class,
type Client,
type DocumentQuery,
@@ -122,6 +123,35 @@ export async function unstarDocument (doc: Document): Promise<void> {
}
}
export async function lockContent (doc: Document | Document[]): Promise<void> {
const client = getClient()
const me = getCurrentAccount()
const arr = Array.isArray(doc) ? doc : [doc]
for (const doc of arr) {
await client.diffUpdate(doc, { lockedBy: me._id })
}
}
export async function unlockContent (doc: Document | Document[]): Promise<void> {
const client = getClient()
const arr = Array.isArray(doc) ? doc : [doc]
for (const doc of arr) {
await client.diffUpdate(doc, { lockedBy: null })
}
}
export async function canLockDocument (doc: Document | Document[]): Promise<boolean> {
const arr = Array.isArray(doc) ? doc : [doc]
return arr.some((p) => p.lockedBy == null)
}
export async function canUnlockDocument (doc: Document | Document[]): Promise<boolean> {
const arr = Array.isArray(doc) ? doc : [doc]
return arr.some((p) => p.lockedBy != null)
}
export default async (): Promise<Resources> => ({
component: {
CreateDocument,
@@ -148,12 +178,16 @@ export default async (): Promise<Resources> => ({
actionImpl: {
CreateChildDocument: createChildDocument,
CreateDocument: createDocument,
EditTeamspace: editTeamspace
EditTeamspace: editTeamspace,
LockContent: lockContent,
UnlockContent: unlockContent
},
function: {
GetDocumentLink: getDocumentUrl,
GetObjectLinkFragment: getDocumentLink,
DocumentTitleProvider: documentTitleProvider
DocumentTitleProvider: documentTitleProvider,
CanLockDocument: canLockDocument,
CanUnlockDocument: canUnlockDocument
},
resolver: {
Location: resolveLocation