@open-mercato/documents 0.9.1-develop.7575.1.8480826a9b → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/contentSecurityPolicy.js +23 -0
- package/dist/contentSecurityPolicy.js.map +7 -0
- package/dist/modules/documents/api/[id]/comments/access-check/route.js +13 -6
- package/dist/modules/documents/api/[id]/comments/access-check/route.js.map +2 -2
- package/dist/modules/documents/api/[id]/comments/route.js +2 -0
- package/dist/modules/documents/api/[id]/comments/route.js.map +2 -2
- package/dist/modules/documents/api/[id]/content/route.js +2 -0
- package/dist/modules/documents/api/[id]/content/route.js.map +2 -2
- package/dist/modules/documents/api/[id]/route.js +3 -0
- package/dist/modules/documents/api/[id]/route.js.map +2 -2
- package/dist/modules/documents/api/[id]/shares/route.js +2 -0
- package/dist/modules/documents/api/[id]/shares/route.js.map +2 -2
- package/dist/modules/documents/api/[id]/versions/route.js +2 -0
- package/dist/modules/documents/api/[id]/versions/route.js.map +2 -2
- package/dist/modules/documents/api/_shared.js +10 -27
- package/dist/modules/documents/api/_shared.js.map +3 -3
- package/dist/modules/documents/backend/documents/[id]/DocumentCanvas.js +3 -1
- package/dist/modules/documents/backend/documents/[id]/DocumentCanvas.js.map +2 -2
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorIsland.js +1 -1
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorIsland.js.map +2 -2
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorSurface.js +15 -1
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorSurface.js.map +2 -2
- package/dist/modules/documents/backend/documents/[id]/DocumentPageClient.js +15 -1
- package/dist/modules/documents/backend/documents/[id]/DocumentPageClient.js.map +2 -2
- package/dist/modules/documents/backend/documents/[id]/VersionHistoryPanel.js +20 -8
- package/dist/modules/documents/backend/documents/[id]/VersionHistoryPanel.js.map +2 -2
- package/dist/modules/documents/backend/documents/[id]/VersionPreviewDialog.js +3 -0
- package/dist/modules/documents/backend/documents/[id]/VersionPreviewDialog.js.map +2 -2
- package/dist/modules/documents/backend/documents/[id]/editorTypes.js.map +2 -2
- package/dist/modules/documents/backend/documents/[id]/saveCollaborativeContent.js +46 -0
- package/dist/modules/documents/backend/documents/[id]/saveCollaborativeContent.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentComments.js +14 -6
- package/dist/modules/documents/backend/documents/[id]/useDocumentComments.js.map +2 -2
- package/dist/modules/documents/backend/documents/[id]/useDocumentEditor.js +3 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentEditor.js.map +2 -2
- package/dist/modules/documents/backend/documents/components/TemplateBodyEditor.js +3 -0
- package/dist/modules/documents/backend/documents/components/TemplateBodyEditor.js.map +2 -2
- package/dist/modules/documents/backend/documents/components/TemplatePreview.js +3 -0
- package/dist/modules/documents/backend/documents/components/TemplatePreview.js.map +2 -2
- package/dist/modules/documents/commands/comments.js +2 -2
- package/dist/modules/documents/commands/comments.js.map +2 -2
- package/dist/modules/documents/commands/folders.js +1 -0
- package/dist/modules/documents/commands/folders.js.map +2 -2
- package/dist/modules/documents/commands/interceptors.js +11 -0
- package/dist/modules/documents/commands/interceptors.js.map +2 -2
- package/dist/modules/documents/data/attachment-access.js +84 -0
- package/dist/modules/documents/data/attachment-access.js.map +7 -0
- package/dist/modules/documents/data/validators.js +11 -0
- package/dist/modules/documents/data/validators.js.map +2 -2
- package/dist/modules/documents/lib/actor.js +32 -0
- package/dist/modules/documents/lib/actor.js.map +7 -0
- package/dist/modules/documents/lib/collabMaterializer.js +52 -9
- package/dist/modules/documents/lib/collabMaterializer.js.map +2 -2
- package/dist/modules/documents/lib/collabPersistence.js +13 -0
- package/dist/modules/documents/lib/collabPersistence.js.map +7 -0
- package/dist/modules/documents/lib/permissions.js +35 -2
- package/dist/modules/documents/lib/permissions.js.map +2 -2
- package/dist/modules/documents/widgets/injection/related-documents/widget.client.js +3 -2
- package/dist/modules/documents/widgets/injection/related-documents/widget.client.js.map +2 -2
- package/dist/modules/documents/widgets/injection-table.js +12 -3
- package/dist/modules/documents/widgets/injection-table.js.map +2 -2
- package/dist/server/documents-collab-server.js +74 -1
- package/dist/server/documents-collab-server.js.map +2 -2
- package/jest.config.cjs +1 -1
- package/package.json +37 -37
- package/server/documents-collab-server.ts +79 -0
- package/src/contentSecurityPolicy.ts +21 -0
- package/src/modules/documents/api/[id]/comments/access-check/route.ts +13 -6
- package/src/modules/documents/api/[id]/comments/route.ts +2 -0
- package/src/modules/documents/api/[id]/content/route.ts +2 -0
- package/src/modules/documents/api/[id]/route.ts +3 -0
- package/src/modules/documents/api/[id]/shares/route.ts +2 -0
- package/src/modules/documents/api/[id]/versions/route.ts +2 -0
- package/src/modules/documents/api/_shared.ts +10 -36
- package/src/modules/documents/backend/documents/[id]/DocumentCanvas.tsx +3 -1
- package/src/modules/documents/backend/documents/[id]/DocumentEditorIsland.tsx +4 -1
- package/src/modules/documents/backend/documents/[id]/DocumentEditorSurface.tsx +19 -1
- package/src/modules/documents/backend/documents/[id]/DocumentPageClient.tsx +14 -0
- package/src/modules/documents/backend/documents/[id]/VersionHistoryPanel.tsx +23 -8
- package/src/modules/documents/backend/documents/[id]/VersionPreviewDialog.tsx +3 -0
- package/src/modules/documents/backend/documents/[id]/editorTypes.ts +1 -0
- package/src/modules/documents/backend/documents/[id]/saveCollaborativeContent.ts +43 -0
- package/src/modules/documents/backend/documents/[id]/useDocumentComments.ts +17 -7
- package/src/modules/documents/backend/documents/[id]/useDocumentEditor.ts +3 -0
- package/src/modules/documents/backend/documents/components/TemplateBodyEditor.tsx +3 -0
- package/src/modules/documents/backend/documents/components/TemplatePreview.tsx +3 -0
- package/src/modules/documents/commands/comments.ts +2 -2
- package/src/modules/documents/commands/folders.ts +1 -3
- package/src/modules/documents/commands/interceptors.ts +11 -0
- package/src/modules/documents/data/attachment-access.ts +83 -0
- package/src/modules/documents/data/validators.ts +12 -0
- package/src/modules/documents/lib/actor.ts +39 -0
- package/src/modules/documents/lib/collabMaterializer.ts +62 -11
- package/src/modules/documents/lib/collabPersistence.ts +10 -0
- package/src/modules/documents/lib/permissions.ts +52 -0
- package/src/modules/documents/widgets/injection/related-documents/widget.client.tsx +3 -2
- package/src/modules/documents/widgets/injection-table.ts +17 -3
|
@@ -2,13 +2,16 @@ import type { EntityManager } from '@mikro-orm/postgresql'
|
|
|
2
2
|
import type { FilterQuery } from '@mikro-orm/core'
|
|
3
3
|
import type { AuthContext } from '@open-mercato/shared/lib/auth/server'
|
|
4
4
|
import { hasAllFeatures } from '@open-mercato/shared/lib/auth/featureMatch'
|
|
5
|
+
import { authorizeFeatures } from '@open-mercato/shared/security/featurePolicy'
|
|
5
6
|
import { forbidden } from '@open-mercato/shared/lib/crud/errors'
|
|
6
7
|
import { findOneWithDecryption, findWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
7
8
|
import { Document, DocumentShare } from '../data/entities'
|
|
9
|
+
import { hasResolvedDocumentsOrganizationAccess } from './organizationAccess'
|
|
8
10
|
import {
|
|
9
11
|
resolveApiKeyPrincipalService,
|
|
10
12
|
resolveAuthPrincipalService,
|
|
11
13
|
resolveDocumentsRbacService,
|
|
14
|
+
resolveOrganizationScopeService,
|
|
12
15
|
type DocumentsServiceContainer,
|
|
13
16
|
} from './platformServices'
|
|
14
17
|
|
|
@@ -188,6 +191,43 @@ export async function resolveLoadedDocumentUserAccess(
|
|
|
188
191
|
scope: { tenantId: string; organizationId: string },
|
|
189
192
|
userId: string,
|
|
190
193
|
container?: DocumentsServiceContainer | null,
|
|
194
|
+
): Promise<DocumentTier | null> {
|
|
195
|
+
if (!await hasUserDocumentViewPermission(scope, userId, container)) return null
|
|
196
|
+
return resolveLoadedDocumentUserTier(em, document, scope, userId, container)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export async function hasUserDocumentViewPermission(
|
|
200
|
+
scope: { tenantId: string; organizationId: string },
|
|
201
|
+
userId: string,
|
|
202
|
+
container?: DocumentsServiceContainer | null,
|
|
203
|
+
): Promise<boolean> {
|
|
204
|
+
const rbacService = resolveDocumentsRbacService(container)
|
|
205
|
+
if (!rbacService) return false
|
|
206
|
+
if (!await rbacService.userHasAllFeatures(userId, ['documents.view'], scope)) {
|
|
207
|
+
const organizationScopeService = resolveOrganizationScopeService(container)
|
|
208
|
+
if (!organizationScopeService) return false
|
|
209
|
+
const authorization = await organizationScopeService.resolveFresh({
|
|
210
|
+
auth: { sub: userId, userId, tenantId: scope.tenantId, orgId: scope.organizationId, isSuperAdmin: false },
|
|
211
|
+
selectedId: scope.organizationId,
|
|
212
|
+
tenantId: scope.tenantId,
|
|
213
|
+
})
|
|
214
|
+
if (!authorizeFeatures(['documents.view'], {
|
|
215
|
+
grantedFeatures: authorization.acl.features,
|
|
216
|
+
unrestricted: authorization.acl.isSuperAdmin,
|
|
217
|
+
scopeAllowed: authorization.scope.tenantId === scope.tenantId
|
|
218
|
+
&& !authorization.scope.selectionRejected
|
|
219
|
+
&& hasResolvedDocumentsOrganizationAccess(authorization.acl, scope.organizationId, authorization.scope),
|
|
220
|
+
})) return false
|
|
221
|
+
}
|
|
222
|
+
return true
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async function resolveLoadedDocumentUserTier(
|
|
226
|
+
em: EntityManager,
|
|
227
|
+
document: Document,
|
|
228
|
+
scope: { tenantId: string; organizationId: string },
|
|
229
|
+
userId: string,
|
|
230
|
+
container?: DocumentsServiceContainer | null,
|
|
191
231
|
): Promise<DocumentTier | null> {
|
|
192
232
|
if (document.ownerUserId === userId) return 'owner'
|
|
193
233
|
if (await resolveDocumentsRbacService(container)?.userHasAllFeatures(
|
|
@@ -222,6 +262,18 @@ export async function resolveLoadedDocumentUserAccess(
|
|
|
222
262
|
return maxShareTier(shares)
|
|
223
263
|
}
|
|
224
264
|
|
|
265
|
+
export async function resolveUserDocumentTier(
|
|
266
|
+
em: EntityManager,
|
|
267
|
+
documentId: string,
|
|
268
|
+
scope: { tenantId: string; organizationId: string },
|
|
269
|
+
userId: string,
|
|
270
|
+
container?: DocumentsServiceContainer | null,
|
|
271
|
+
): Promise<DocumentTier | null> {
|
|
272
|
+
const document = await loadScopedDocument(em, documentId, scope)
|
|
273
|
+
if (!document) return null
|
|
274
|
+
return resolveLoadedDocumentUserTier(em, document, scope, userId, container)
|
|
275
|
+
}
|
|
276
|
+
|
|
225
277
|
export async function resolveUserAccess(
|
|
226
278
|
em: EntityManager,
|
|
227
279
|
documentId: string,
|
|
@@ -51,12 +51,13 @@ export default function RelatedDocumentsWidget({ context, data, disabled }: Inje
|
|
|
51
51
|
return (
|
|
52
52
|
<section className="rounded-lg border border-border bg-card p-4">
|
|
53
53
|
<SectionHeader
|
|
54
|
+
className="flex-col items-start gap-3 sm:flex-row sm:items-center"
|
|
54
55
|
title={t('documents.relatedDocuments.title')}
|
|
55
56
|
count={related.items.length}
|
|
56
|
-
action={actions.canLink || actions.canCreate ?
|
|
57
|
+
action={actions.canLink || actions.canCreate ? <div className="flex flex-wrap gap-1" data-testid="related-documents-actions">
|
|
57
58
|
{actions.canLink ? <Button type="button" size="sm" variant="outline" onClick={() => setLinkOpen(true)}><Link2 />{t('documents.relatedDocuments.actions.link')}</Button> : null}
|
|
58
59
|
{actions.canCreate ? <Button type="button" size="sm" onClick={() => setCreateOpen(true)}><FilePlus2 />{t('documents.relatedDocuments.actions.create')}</Button> : null}
|
|
59
|
-
|
|
60
|
+
</div> : undefined}
|
|
60
61
|
/>
|
|
61
62
|
<div className="mt-4">
|
|
62
63
|
{related.status === 'loading' ? <LoadingMessage label={t('documents.relatedDocuments.loading')} /> : null}
|
|
@@ -6,12 +6,26 @@ const relatedDocuments = {
|
|
|
6
6
|
priority: 80,
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
// The three CRM detail pages (people-v2, companies-v2, deals) mount the panel
|
|
10
|
+
// as a tab of their related-content workspace (#7488). Their tab loaders
|
|
11
|
+
// ignore `kind: 'stack'`, hence a separate descriptor; the legacy CRM, sales
|
|
12
|
+
// and catalog hosts keep the inline stack below.
|
|
13
|
+
const relatedDocumentsTab = {
|
|
14
|
+
widgetId: 'documents.injection.related-documents',
|
|
15
|
+
kind: 'tab' as const,
|
|
16
|
+
groupId: 'related-documents',
|
|
17
|
+
groupLabel: 'documents.relatedDocuments.title',
|
|
18
|
+
icon: 'file-text',
|
|
19
|
+
// Negative: after the host's built-in tabs (#8020 ordering contract).
|
|
20
|
+
priority: -20,
|
|
21
|
+
}
|
|
22
|
+
|
|
9
23
|
export const injectionTable: ModuleInjectionTable = {
|
|
10
|
-
'detail:customers.person:
|
|
24
|
+
'detail:customers.person:tabs': [relatedDocumentsTab],
|
|
11
25
|
'customers.person.detail:details': [relatedDocuments],
|
|
12
|
-
'detail:customers.company:
|
|
26
|
+
'detail:customers.company:tabs': [relatedDocumentsTab],
|
|
13
27
|
'customers.company.detail:details': [relatedDocuments],
|
|
14
|
-
'detail:customers.deal:
|
|
28
|
+
'detail:customers.deal:tabs': [relatedDocumentsTab],
|
|
15
29
|
'sales.document.detail.quote:details': [relatedDocuments],
|
|
16
30
|
'sales.document.detail.order:details': [relatedDocuments],
|
|
17
31
|
'crud-form:catalog.product': [relatedDocuments],
|