mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 00:11:37 -06:00
5a668b0015
Add an isPublic flag to collections allowing users to share collections across the instance. Public collections are readable by all authenticated users while write, edit, reorder, and delete operations remain restricted to the owner.
14 lines
523 B
TypeScript
14 lines
523 B
TypeScript
import type { Collection } from '@bookorbit/types'
|
|
|
|
export function canMutateCollection(collection: Collection | null | undefined): boolean {
|
|
return collection?.isOwner === true
|
|
}
|
|
|
|
export function ownedCollectionOrder(
|
|
collections: readonly Collection[],
|
|
order: readonly { id: number; displayOrder: number }[],
|
|
): { id: number; displayOrder: number }[] {
|
|
const ownedIds = new Set(collections.filter(canMutateCollection).map((collection) => collection.id))
|
|
return order.filter((entry) => ownedIds.has(entry.id))
|
|
}
|