mirror of
https://github.com/docmost/docmost.git
synced 2026-08-30 02:25:01 +08:00
fix mention permissions
This commit is contained in:
@@ -144,7 +144,14 @@ export class ExportService {
|
|||||||
const tree = buildTree(pages as Page[]);
|
const tree = buildTree(pages as Page[]);
|
||||||
|
|
||||||
const zip = new JSZip();
|
const zip = new JSZip();
|
||||||
await this.zipPages(tree, format, zip, includeAttachments);
|
await this.zipPages(
|
||||||
|
tree,
|
||||||
|
format,
|
||||||
|
zip,
|
||||||
|
includeAttachments,
|
||||||
|
userId,
|
||||||
|
ignorePermissions,
|
||||||
|
);
|
||||||
|
|
||||||
const zipFile = zip.generateNodeStream({
|
const zipFile = zip.generateNodeStream({
|
||||||
type: 'nodebuffer',
|
type: 'nodebuffer',
|
||||||
@@ -203,7 +210,14 @@ export class ExportService {
|
|||||||
|
|
||||||
const zip = new JSZip();
|
const zip = new JSZip();
|
||||||
|
|
||||||
await this.zipPages(tree, format, zip, includeAttachments);
|
await this.zipPages(
|
||||||
|
tree,
|
||||||
|
format,
|
||||||
|
zip,
|
||||||
|
includeAttachments,
|
||||||
|
userId,
|
||||||
|
ignorePermissions,
|
||||||
|
);
|
||||||
|
|
||||||
const zipFile = zip.generateNodeStream({
|
const zipFile = zip.generateNodeStream({
|
||||||
type: 'nodebuffer',
|
type: 'nodebuffer',
|
||||||
@@ -223,6 +237,8 @@ export class ExportService {
|
|||||||
format: string,
|
format: string,
|
||||||
zip: JSZip,
|
zip: JSZip,
|
||||||
includeAttachments: boolean,
|
includeAttachments: boolean,
|
||||||
|
userId?: string,
|
||||||
|
ignorePermissions = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const slugIdToPath: Record<string, string> = {};
|
const slugIdToPath: Record<string, string> = {};
|
||||||
|
|
||||||
@@ -242,6 +258,8 @@ export class ExportService {
|
|||||||
const prosemirrorJson = await this.turnPageMentionsToLinks(
|
const prosemirrorJson = await this.turnPageMentionsToLinks(
|
||||||
getProsemirrorContent(page.content),
|
getProsemirrorContent(page.content),
|
||||||
page.workspaceId,
|
page.workspaceId,
|
||||||
|
userId,
|
||||||
|
ignorePermissions,
|
||||||
);
|
);
|
||||||
|
|
||||||
const currentPagePath = slugIdToPath[page.slugId];
|
const currentPagePath = slugIdToPath[page.slugId];
|
||||||
@@ -303,10 +321,15 @@ export class ExportService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async turnPageMentionsToLinks(prosemirrorJson: any, workspaceId: string) {
|
async turnPageMentionsToLinks(
|
||||||
|
prosemirrorJson: any,
|
||||||
|
workspaceId: string,
|
||||||
|
userId?: string,
|
||||||
|
ignorePermissions = false,
|
||||||
|
) {
|
||||||
const doc = jsonToNode(prosemirrorJson);
|
const doc = jsonToNode(prosemirrorJson);
|
||||||
|
|
||||||
const pageMentionIds = [];
|
let pageMentionIds: string[] = [];
|
||||||
|
|
||||||
doc.descendants((node: Node) => {
|
doc.descendants((node: Node) => {
|
||||||
if (node.type.name === 'mention' && node.attrs.entityType === 'page') {
|
if (node.type.name === 'mention' && node.attrs.entityType === 'page') {
|
||||||
@@ -320,13 +343,33 @@ export class ExportService {
|
|||||||
return prosemirrorJson;
|
return prosemirrorJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pages = await this.db
|
// Filter to only accessible pages if permissions are enforced
|
||||||
.selectFrom('pages')
|
if (!ignorePermissions && userId) {
|
||||||
.select(['id', 'slugId', 'title', 'creatorId', 'spaceId', 'workspaceId'])
|
const accessiblePages =
|
||||||
.select((eb) => this.pageRepo.withSpace(eb))
|
await this.pagePermissionRepo.filterAccessiblePageIdsWithPermissions(
|
||||||
.where('id', 'in', pageMentionIds)
|
pageMentionIds,
|
||||||
.where('workspaceId', '=', workspaceId)
|
userId,
|
||||||
.execute();
|
);
|
||||||
|
pageMentionIds = accessiblePages.map((p) => p.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const pages =
|
||||||
|
pageMentionIds.length > 0
|
||||||
|
? await this.db
|
||||||
|
.selectFrom('pages')
|
||||||
|
.select([
|
||||||
|
'id',
|
||||||
|
'slugId',
|
||||||
|
'title',
|
||||||
|
'creatorId',
|
||||||
|
'spaceId',
|
||||||
|
'workspaceId',
|
||||||
|
])
|
||||||
|
.select((eb) => this.pageRepo.withSpace(eb))
|
||||||
|
.where('id', 'in', pageMentionIds)
|
||||||
|
.where('workspaceId', '=', workspaceId)
|
||||||
|
.execute()
|
||||||
|
: [];
|
||||||
|
|
||||||
const pageMap = new Map(pages.map((page) => [page.id, page]));
|
const pageMap = new Map(pages.map((page) => [page.id, page]));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user