mirror of
https://github.com/outline/outline.git
synced 2026-11-26 23:50:14 +03:00
* shares.info, collections.info, documents.info * shares.list, shares.create, shares.update * shares.sitemap * parity with existing document shared screen * collection share popover * parent share and table * collection scene * collection link in sidebar * sidebar and breadcrumb collection link click * collection link click in editor * meta * more meta + 404 page * map internal link, remove showLastUpdated option * fix shares.list pagination * show last updated * shareLoader tests * lint * sidebar context for collection link * badge in shares table * fix existing tests * tsc * update failing test snapshot * env * signed url for collection attachments * include collection content in SSR for screen readers * search * drafts can be shared * review * tsc, remove old shared-doc scene * tweaks * DRY * refactor loader * Remove share/collection urls * fix: Collection overview should not be editable when viewing shared link and logged in * Tweak public breadcrumb * fix: Deleted documents should never be exposed through share * empty sharedTree array where includeChildDocuments is false * revert includeChildDocs guard for logical correctness + SSR bug fix * fix: check document is part of share --------- Co-authored-by: Tom Moor <tom@getoutline.com>
235 lines
6.7 KiB
TypeScript
235 lines
6.7 KiB
TypeScript
import isUndefined from "lodash/isUndefined";
|
|
import isUUID from "validator/lib/isUUID";
|
|
import { z } from "zod";
|
|
import {
|
|
CollectionPermission,
|
|
CollectionStatusFilter,
|
|
FileOperationFormat,
|
|
} from "@shared/types";
|
|
import { UrlHelper } from "@shared/utils/UrlHelper";
|
|
import { Collection } from "@server/models";
|
|
import { zodIconType, zodIdType } from "@server/utils/zod";
|
|
import { ValidateColor, ValidateIndex } from "@server/validation";
|
|
import { BaseSchema, ProsemirrorSchema } from "../schema";
|
|
|
|
const BaseIdSchema = z.object({
|
|
/** Id of the collection to be updated */
|
|
id: zodIdType(),
|
|
});
|
|
|
|
export const CollectionsCreateSchema = BaseSchema.extend({
|
|
body: z.object({
|
|
name: z.string(),
|
|
color: z
|
|
.string()
|
|
.regex(ValidateColor.regex, { message: ValidateColor.message })
|
|
.nullish(),
|
|
description: z.string().nullish(),
|
|
data: ProsemirrorSchema({ allowEmpty: true }).nullish(),
|
|
permission: z
|
|
.nativeEnum(CollectionPermission)
|
|
.nullish()
|
|
.transform((val) => (isUndefined(val) ? null : val)),
|
|
sharing: z.boolean().default(true),
|
|
icon: zodIconType().optional(),
|
|
sort: z
|
|
.object({
|
|
field: z.union([z.literal("title"), z.literal("index")]),
|
|
direction: z.union([z.literal("asc"), z.literal("desc")]),
|
|
})
|
|
.default(Collection.DEFAULT_SORT),
|
|
index: z
|
|
.string()
|
|
.regex(ValidateIndex.regex, { message: ValidateIndex.message })
|
|
.max(ValidateIndex.maxLength, {
|
|
message: `Must be ${ValidateIndex.maxLength} or fewer characters long`,
|
|
})
|
|
.optional(),
|
|
commenting: z.boolean().nullish(),
|
|
}),
|
|
});
|
|
|
|
export type CollectionsCreateReq = z.infer<typeof CollectionsCreateSchema>;
|
|
|
|
export const CollectionsInfoSchema = BaseSchema.extend({
|
|
body: BaseIdSchema.extend({
|
|
/** Share Id, if available */
|
|
shareId: z
|
|
.string()
|
|
.refine((val) => isUUID(val) || UrlHelper.SHARE_URL_SLUG_REGEX.test(val))
|
|
.optional(),
|
|
}),
|
|
});
|
|
|
|
export type CollectionsInfoReq = z.infer<typeof CollectionsInfoSchema>;
|
|
|
|
export const CollectionsDocumentsSchema = BaseSchema.extend({
|
|
body: BaseIdSchema,
|
|
});
|
|
|
|
export type CollectionsDocumentsReq = z.infer<
|
|
typeof CollectionsDocumentsSchema
|
|
>;
|
|
|
|
export const CollectionsImportSchema = BaseSchema.extend({
|
|
body: z.object({
|
|
permission: z
|
|
.nativeEnum(CollectionPermission)
|
|
.nullish()
|
|
.transform((val) => (isUndefined(val) ? null : val)),
|
|
attachmentId: z.string().uuid(),
|
|
format: z
|
|
.nativeEnum(FileOperationFormat)
|
|
.default(FileOperationFormat.MarkdownZip),
|
|
}),
|
|
});
|
|
|
|
export type CollectionsImportReq = z.infer<typeof CollectionsImportSchema>;
|
|
|
|
export const CollectionsAddGroupSchema = BaseSchema.extend({
|
|
body: BaseIdSchema.extend({
|
|
groupId: z.string().uuid(),
|
|
permission: z
|
|
.nativeEnum(CollectionPermission)
|
|
.default(CollectionPermission.ReadWrite),
|
|
}),
|
|
});
|
|
|
|
export type CollectionsAddGroupsReq = z.infer<typeof CollectionsAddGroupSchema>;
|
|
|
|
export const CollectionsRemoveGroupSchema = BaseSchema.extend({
|
|
body: BaseIdSchema.extend({
|
|
groupId: z.string().uuid(),
|
|
}),
|
|
});
|
|
|
|
export type CollectionsRemoveGroupReq = z.infer<
|
|
typeof CollectionsRemoveGroupSchema
|
|
>;
|
|
|
|
export const CollectionsAddUserSchema = BaseSchema.extend({
|
|
body: BaseIdSchema.extend({
|
|
userId: z.string().uuid(),
|
|
permission: z.nativeEnum(CollectionPermission).optional(),
|
|
}),
|
|
});
|
|
|
|
export type CollectionsAddUserReq = z.infer<typeof CollectionsAddUserSchema>;
|
|
|
|
export const CollectionsRemoveUserSchema = BaseSchema.extend({
|
|
body: BaseIdSchema.extend({
|
|
userId: z.string().uuid(),
|
|
}),
|
|
});
|
|
|
|
export type CollectionsRemoveUserReq = z.infer<
|
|
typeof CollectionsRemoveUserSchema
|
|
>;
|
|
|
|
export const CollectionsMembershipsSchema = BaseSchema.extend({
|
|
body: BaseIdSchema.extend({
|
|
query: z.string().optional(),
|
|
permission: z.nativeEnum(CollectionPermission).optional(),
|
|
}),
|
|
});
|
|
|
|
export type CollectionsMembershipsReq = z.infer<
|
|
typeof CollectionsMembershipsSchema
|
|
>;
|
|
|
|
export const CollectionsExportSchema = BaseSchema.extend({
|
|
body: BaseIdSchema.extend({
|
|
format: z
|
|
.nativeEnum(FileOperationFormat)
|
|
.default(FileOperationFormat.MarkdownZip),
|
|
includeAttachments: z.boolean().default(true),
|
|
}),
|
|
});
|
|
|
|
export type CollectionsExportReq = z.infer<typeof CollectionsExportSchema>;
|
|
|
|
export const CollectionsExportAllSchema = BaseSchema.extend({
|
|
body: z.object({
|
|
format: z
|
|
.nativeEnum(FileOperationFormat)
|
|
.default(FileOperationFormat.MarkdownZip),
|
|
includeAttachments: z.boolean().default(true),
|
|
}),
|
|
});
|
|
|
|
export type CollectionsExportAllReq = z.infer<
|
|
typeof CollectionsExportAllSchema
|
|
>;
|
|
|
|
export const CollectionsUpdateSchema = BaseSchema.extend({
|
|
body: BaseIdSchema.extend({
|
|
name: z.string().optional(),
|
|
description: z.string().nullish(),
|
|
data: ProsemirrorSchema({ allowEmpty: true }).nullish(),
|
|
icon: zodIconType().nullish(),
|
|
permission: z.nativeEnum(CollectionPermission).nullish(),
|
|
color: z
|
|
.string()
|
|
.regex(ValidateColor.regex, { message: ValidateColor.message })
|
|
.nullish(),
|
|
sort: z
|
|
.object({
|
|
field: z.union([z.literal("title"), z.literal("index")]),
|
|
direction: z.union([z.literal("asc"), z.literal("desc")]),
|
|
})
|
|
.optional(),
|
|
sharing: z.boolean().optional(),
|
|
commenting: z.boolean().nullish(),
|
|
}),
|
|
});
|
|
|
|
export type CollectionsUpdateReq = z.infer<typeof CollectionsUpdateSchema>;
|
|
|
|
export const CollectionsListSchema = BaseSchema.extend({
|
|
body: z.object({
|
|
includeListOnly: z.boolean().default(false),
|
|
|
|
query: z.string().optional(),
|
|
|
|
/** Collection statuses to include in results */
|
|
statusFilter: z.nativeEnum(CollectionStatusFilter).array().optional(),
|
|
}),
|
|
});
|
|
|
|
export type CollectionsListReq = z.infer<typeof CollectionsListSchema>;
|
|
|
|
export const CollectionsDeleteSchema = BaseSchema.extend({
|
|
body: BaseIdSchema,
|
|
});
|
|
|
|
export type CollectionsDeleteReq = z.infer<typeof CollectionsDeleteSchema>;
|
|
|
|
export const CollectionsArchiveSchema = BaseSchema.extend({
|
|
body: BaseIdSchema,
|
|
});
|
|
|
|
export type CollectionsArchiveReq = z.infer<typeof CollectionsArchiveSchema>;
|
|
|
|
export const CollectionsRestoreSchema = BaseSchema.extend({
|
|
body: BaseIdSchema,
|
|
});
|
|
|
|
export type CollectionsRestoreReq = z.infer<typeof CollectionsRestoreSchema>;
|
|
|
|
export const CollectionsArchivedSchema = BaseSchema;
|
|
|
|
export type CollectionsArchivedReq = z.infer<typeof CollectionsArchivedSchema>;
|
|
|
|
export const CollectionsMoveSchema = BaseSchema.extend({
|
|
body: BaseIdSchema.extend({
|
|
index: z
|
|
.string()
|
|
.regex(ValidateIndex.regex, { message: ValidateIndex.message })
|
|
.max(ValidateIndex.maxLength, {
|
|
message: `Must be ${ValidateIndex.maxLength} or fewer characters long`,
|
|
}),
|
|
}),
|
|
});
|
|
|
|
export type CollectionsMoveReq = z.infer<typeof CollectionsMoveSchema>;
|