mirror of
https://github.com/outline/outline.git
synced 2026-11-21 05:24:03 +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>
66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
import { Hour } from "@shared/utils/time";
|
|
import Collection from "@server/models/Collection";
|
|
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
|
|
import { APIContext } from "@server/types";
|
|
import presentUser from "./user";
|
|
|
|
type Options = {
|
|
/** Whether to render the collection's public fields. */
|
|
isPublic?: boolean;
|
|
/** The root share ID when presenting a shared collection. */
|
|
shareId?: string;
|
|
/** Whether to include the updatedAt timestamp. */
|
|
includeUpdatedAt?: boolean;
|
|
};
|
|
|
|
export default async function presentCollection(
|
|
ctx: APIContext | undefined,
|
|
collection: Collection,
|
|
options: Options = {}
|
|
) {
|
|
const asData = !ctx || Number(ctx?.headers["x-api-version"] ?? 0) >= 3;
|
|
|
|
const res: Record<string, any> = {
|
|
id: collection.id,
|
|
url: collection.url,
|
|
urlId: collection.urlId,
|
|
name: collection.name,
|
|
data: asData
|
|
? await DocumentHelper.toJSON(
|
|
collection,
|
|
options.isPublic
|
|
? {
|
|
signedUrls: Hour.seconds,
|
|
teamId: collection.teamId,
|
|
internalUrlBase: `/s/${options.shareId}`,
|
|
}
|
|
: undefined
|
|
)
|
|
: undefined,
|
|
description: asData ? undefined : collection.description,
|
|
sort: collection.sort,
|
|
icon: collection.icon,
|
|
index: collection.index,
|
|
color: collection.color,
|
|
permission: collection.permission,
|
|
commenting: collection.commenting,
|
|
sharing: collection.sharing,
|
|
createdAt: collection.createdAt,
|
|
updatedAt: collection.updatedAt,
|
|
deletedAt: collection.deletedAt,
|
|
archivedAt: collection.archivedAt,
|
|
archivedBy: undefined,
|
|
};
|
|
|
|
if (options.isPublic && !options.includeUpdatedAt) {
|
|
delete res.updatedAt;
|
|
}
|
|
|
|
if (!options.isPublic) {
|
|
res.archivedBy =
|
|
collection.archivedBy && presentUser(collection.archivedBy);
|
|
}
|
|
|
|
return res;
|
|
}
|