diff --git a/app/components/ExportDialog.tsx b/app/components/ExportDialog.tsx index aaef6ba84c..e65d460eb6 100644 --- a/app/components/ExportDialog.tsx +++ b/app/components/ExportDialog.tsx @@ -25,6 +25,7 @@ function ExportDialog({ collection, onSubmit }: Props) { ); const [includeAttachments, setIncludeAttachments] = React.useState(true); + const [includePrivate, setIncludePrivate] = React.useState(true); const user = useCurrentUser(); const { collections } = useStores(); const { t } = useTranslation(); @@ -44,6 +45,13 @@ function ExportDialog({ collection, onSubmit }: Props) { [] ); + const handleIncludePrivateChange = React.useCallback( + (ev: React.ChangeEvent) => { + setIncludePrivate(ev.target.checked); + }, + [] + ); + const handleSubmit = async () => { if (collection) { await collection.export(format, includeAttachments); @@ -59,7 +67,7 @@ function ExportDialog({ collection, onSubmit }: Props) { }, }); } else { - await collections.export(format, includeAttachments); + await collections.export({ format, includeAttachments, includePrivate }); toast.success(t("Export started")); } onSubmit(); @@ -123,37 +131,62 @@ function ExportDialog({ collection, onSubmit }: Props) { {item.title} - {item.description} + + {item.description} + ))} -
- +
+ + + + ); } +const HR = styled.hr` + margin: 16px 0; +`; + const Option = styled.label` display: flex; - align-items: center; + align-items: start; gap: 16px; + input { + margin-top: 4px; + } + p { margin: 0; } diff --git a/app/stores/CollectionsStore.ts b/app/stores/CollectionsStore.ts index 85572ff61a..9dd62a16ac 100644 --- a/app/stores/CollectionsStore.ts +++ b/app/stores/CollectionsStore.ts @@ -247,9 +247,9 @@ export default class CollectionsStore extends Store { await this.rootStore.documents.fetchRecentlyViewed(); } - export = (format: FileOperationFormat, includeAttachments: boolean) => - client.post("/collections.export_all", { - format, - includeAttachments, - }); + export = (options: { + format: FileOperationFormat; + includeAttachments: boolean; + includePrivate: boolean; + }) => client.post("/collections.export_all", options); } diff --git a/server/commands/collectionExporter.ts b/server/commands/collectionExporter.ts index 2091d1e68b..fa683d0ede 100644 --- a/server/commands/collectionExporter.ts +++ b/server/commands/collectionExporter.ts @@ -15,6 +15,7 @@ type Props = { user: User; format?: FileOperationFormat; includeAttachments?: boolean; + includePrivate?: boolean; ctx: APIContext; }; @@ -34,6 +35,7 @@ async function collectionExporter({ user, format = FileOperationFormat.MarkdownZip, includeAttachments = true, + includePrivate = true, ctx, }: Props) { const collectionId = collection?.id; @@ -52,6 +54,7 @@ async function collectionExporter({ collectionId, options: { includeAttachments, + includePrivate, }, userId: user.id, teamId: user.teamId, diff --git a/server/models/FileOperation.ts b/server/models/FileOperation.ts index 349d6afe00..0ec803f33e 100644 --- a/server/models/FileOperation.ts +++ b/server/models/FileOperation.ts @@ -28,6 +28,7 @@ import Fix from "./decorators/Fix"; export type FileOperationOptions = { includeAttachments?: boolean; + includePrivate?: boolean; permission?: CollectionPermission | null; }; diff --git a/server/queues/tasks/ExportTask.ts b/server/queues/tasks/ExportTask.ts index 7eb5af5d84..e6352ec3be 100644 --- a/server/queues/tasks/ExportTask.ts +++ b/server/queues/tasks/ExportTask.ts @@ -19,6 +19,7 @@ import fileOperationPresenter from "@server/presenters/fileOperation"; import FileStorage from "@server/storage/files"; import BaseTask, { TaskPriority } from "./BaseTask"; import { Op } from "sequelize"; +import { WhereOptions } from "sequelize"; type Props = { fileOperationId: string; @@ -41,16 +42,26 @@ export default abstract class ExportTask extends BaseTask { User.findByPk(fileOperation.userId, { rejectOnEmpty: true }), ]); - const where = fileOperation.collectionId + const where: WhereOptions = fileOperation.collectionId ? { teamId: user.teamId, id: fileOperation.collectionId, + permission: fileOperation.options?.includePrivate + ? undefined + : { + [Op.ne]: null, + }, } : { teamId: user.teamId, archivedAt: { [Op.eq]: null, }, + permission: fileOperation.options?.includePrivate + ? undefined + : { + [Op.ne]: null, + }, }; const collections = await Collection.scope("withDocumentStructure").findAll( diff --git a/server/routes/api/collections/collections.ts b/server/routes/api/collections/collections.ts index 316ad03eb9..b5b9fb1eef 100644 --- a/server/routes/api/collections/collections.ts +++ b/server/routes/api/collections/collections.ts @@ -533,7 +533,7 @@ router.post( validate(T.CollectionsExportAllSchema), transaction(), async (ctx: APIContext) => { - const { format, includeAttachments } = ctx.input.body; + const { format, includeAttachments, includePrivate } = ctx.input.body; const { user } = ctx.state.auth; const { transaction } = ctx.state; const team = await Team.findByPk(user.teamId, { transaction }); @@ -544,6 +544,7 @@ router.post( team, format, includeAttachments, + includePrivate, ctx, }); diff --git a/server/routes/api/collections/schema.ts b/server/routes/api/collections/schema.ts index 1fe0968164..6913a3242b 100644 --- a/server/routes/api/collections/schema.ts +++ b/server/routes/api/collections/schema.ts @@ -154,6 +154,7 @@ export const CollectionsExportAllSchema = BaseSchema.extend({ .nativeEnum(FileOperationFormat) .default(FileOperationFormat.MarkdownZip), includeAttachments: z.boolean().default(true), + includePrivate: z.boolean().default(true), }), }); diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index 1fe15b03a7..2d097e45b2 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -285,6 +285,7 @@ "You will receive an email when it's complete.": "You will receive an email when it's complete.", "Include attachments": "Include attachments", "Including uploaded images and files in the exported data": "Including uploaded images and files in the exported data", + "Include private collections": "Include private collections", "{{count}} more user": "{{count}} more user", "{{count}} more user_plural": "{{count}} more users", "Filter options": "Filter options",