mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-06 17:57:42 +02:00
UBERF-6486 Lock document content (#5799)
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
@@ -50,7 +50,7 @@
|
||||
} from '@hcengineering/view-resources'
|
||||
import { createEventDispatcher, onDestroy, onMount } from 'svelte'
|
||||
|
||||
import { starDocument, unstarDocument } from '..'
|
||||
import { starDocument, unstarDocument, unlockContent } from '..'
|
||||
import document from '../plugin'
|
||||
import { getDocumentUrl } from '../utils'
|
||||
import DocumentEditor from './DocumentEditor.svelte'
|
||||
@@ -64,7 +64,8 @@
|
||||
export let embedded: boolean = false
|
||||
export let kind: 'default' | 'modern' = 'default'
|
||||
|
||||
$: readonly = $restrictionStore.readonly
|
||||
$: locked = doc?.lockedBy != null
|
||||
$: readonly = $restrictionStore.readonly || locked
|
||||
|
||||
export function canClose (): boolean {
|
||||
return false
|
||||
@@ -248,6 +249,23 @@
|
||||
<svelte:fragment slot="title">
|
||||
<ParentsNavigator element={doc} />
|
||||
<DocumentPresenter value={doc} breadcrumb noUnderline />
|
||||
{#if locked}
|
||||
<div class="ml-2">
|
||||
<Button
|
||||
icon={document.icon.Lock}
|
||||
iconProps={{ size: 'x-small' }}
|
||||
label={document.string.Locked}
|
||||
kind={'link-bordered'}
|
||||
size={'small'}
|
||||
noFocus
|
||||
on:click={async () => {
|
||||
if (doc !== undefined) {
|
||||
await unlockContent(doc)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
|
||||
<svelte:fragment slot="utils">
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -71,6 +71,10 @@ export default mergeIds(documentId, document, {
|
||||
Unstar: '' as IntlString,
|
||||
CopyDocumentUrl: '' as IntlString,
|
||||
|
||||
Lock: '' as IntlString,
|
||||
Unlock: '' as IntlString,
|
||||
Locked: '' as IntlString,
|
||||
|
||||
ViewMode: '' as IntlString,
|
||||
EditMode: '' as IntlString,
|
||||
SuggestMode: '' as IntlString,
|
||||
|
||||
Reference in New Issue
Block a user