⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
feat: add ability to propagate members and permissions to subcollections
9helixd066378076f6
diff --git a/apps/web/components/ModalContent/EditCollectionSharingModal.tsx b/apps/web/components/ModalContent/EditCollectionSharingModal.tsxindex bb7131f4..c9632a55 100644--- a/apps/web/components/ModalContent/EditCollectionSharingModal.tsx+++ b/apps/web/components/ModalContent/EditCollectionSharingModal.tsx@@ -41,6 +41,9 @@ export default function EditCollectionSharingModal({const [collection, setCollection] =useState<CollectionIncludingMembersAndLinkCount>(activeCollection);+ const [propagateToSubcollections, setPropagateToSubcollections] =+ useState(false);+const [submitLoader, setSubmitLoader] = useState(false);const updateCollection = useUpdateCollection();@@ -53,9 +56,11 @@ export default function EditCollectionSharingModal({const load = toast.loading(t("updating_collection"));- await updateCollection.mutateAsync(collection, {- onSettled: (data, error) => {- setSubmitLoader(false);+ await updateCollection.mutateAsync(+ { ...collection, propagateToSubcollections },+ {+ onSettled: (data, error) => {+ setSubmitLoader(false);toast.dismiss(load);if (error) {@@ -365,6 +370,27 @@ export default function EditCollectionSharingModal({</>)}+ {permissions === true && !isPublicRoute && (+ <div>+ <label className="label cursor-pointer justify-start gap-2">+ <input+ type="checkbox"+ checked={propagateToSubcollections}+ onChange={() =>+ setPropagateToSubcollections(!propagateToSubcollections)+ }+ className="checkbox checkbox-primary"+ />+ <span className="label-text">+ {t("propagate_to_subcollections")}+ </span>+ </label>+ <p className="text-neutral text-sm">+ {t("propagate_to_subcollections_desc")}+ </p>+ </div>+ )}+{permissions === true && !isPublicRoute && (<Buttonvariant="accent"diff --git a/apps/web/lib/api/controllers/collections/collectionId/updateCollectionById.ts b/apps/web/lib/api/controllers/collections/collectionId/updateCollectionById.tsindex 4480da72..b28b898f 100644--- a/apps/web/lib/api/controllers/collections/collectionId/updateCollectionById.ts+++ b/apps/web/lib/api/controllers/collections/collectionId/updateCollectionById.ts@@ -65,6 +65,46 @@ export default async function updateCollection();const updatedCollection = await prisma.$transaction(async () => {+ if (data.propagateToSubcollections) {+ const getAllSubCollections = async (+ parentId: number+ ): Promise<{ id: number; ownerId: number }[]> => {+ const children = await prisma.collection.findMany({+ where: { parentId },+ select: { id: true, ownerId: true },+ });+ let result = [...children];+ for (const child of children) {+ result = [...result, ...(await getAllSubCollections(child.id))];+ }+ return result;+ };++ const subCollections = await getAllSubCollections(collectionId);++ for (const sub of subCollections) {+ await prisma.usersAndCollections.deleteMany({+ where: { collectionId: sub.id },+ });++ const subMembers = uniqueMembers.filter(+ (m) => m.userId !== sub.ownerId+ );++ if (subMembers.length > 0) {+ await prisma.usersAndCollections.createMany({+ data: subMembers.map((e) => ({+ userId: e.userId,+ collectionId: sub.id,+ canCreate: e.canCreate,+ canUpdate: e.canUpdate,+ canDelete: e.canDelete,+ })),+ });+ }+ }+ }+await prisma.usersAndCollections.deleteMany({where: {collection: {diff --git a/apps/web/public/locales/en/common.json b/apps/web/public/locales/en/common.jsonindex d50e49b9..c5cb4d15 100644--- a/apps/web/public/locales/en/common.json+++ b/apps/web/public/locales/en/common.json@@ -525,5 +525,7 @@"expand_sidebar": "Expand Sidebar","shrink_sidebar": "Shrink Sidebar","trial_left_plural": "Trial ends in {{count}} days. Subscribe.",- "trial_left_singular": "Trial ends in 1 day. Subscribe."+ "trial_left_singular": "Trial ends in 1 day. Subscribe.",+ "propagate_to_subcollections": "Propagate to subcollections",+ "propagate_to_subcollections_desc": "This will update the members of all subcollections to match this collection."}diff --git a/packages/lib/schemaValidation.ts b/packages/lib/schemaValidation.tsindex 9488d0f1..52ac2317 100644--- a/packages/lib/schemaValidation.ts+++ b/packages/lib/schemaValidation.ts@@ -236,6 +236,7 @@ export const UpdateCollectionSchema = z.object({canDelete: z.boolean(),})),+ propagateToSubcollections: z.boolean().optional(),});export type UpdateCollectionSchemaType = z.infer<typeof UpdateCollectionSchema>;