diff --git a/components/InputSelect/CollectionSelection.tsx b/components/InputSelect/CollectionSelection.tsx
index dcbbe0f..ec586ea 100644
--- a/components/InputSelect/CollectionSelection.tsx
+++ b/components/InputSelect/CollectionSelection.tsx
@@ -4,6 +4,7 @@ import { useEffect, useState } from "react";
import { styles } from "./styles";
import { Options } from "./types";
import CreatableSelect from "react-select/creatable";
+import Select from "react-select";
type Props = {
onChange: any;
@@ -14,12 +15,14 @@ type Props = {
value?: number;
}
| undefined;
+ creatable?: boolean;
};
export default function CollectionSelection({
onChange,
defaultValue,
showDefaultValue = true,
+ creatable = true,
}: Props) {
const { collections } = useCollectionStore();
const router = useRouter();
@@ -47,16 +50,31 @@ export default function CollectionSelection({
setOptions(formatedCollections);
}, [collections]);
- return (
-
- );
+ if (creatable) {
+ return (
+
+ );
+ } else {
+ return (
+
+ );
+ }
}
diff --git a/components/ModalContent/BulkEditLinksModal.tsx b/components/ModalContent/BulkEditLinksModal.tsx
index e552746..07b3914 100644
--- a/components/ModalContent/BulkEditLinksModal.tsx
+++ b/components/ModalContent/BulkEditLinksModal.tsx
@@ -20,6 +20,7 @@ export default function BulkEditLinksModal({ onClose }: Props) {
const setCollection = (e: any) => {
const collectionId = e?.value || null;
+ console.log(updatedValues);
setUpdatedValues((prevValues) => ({ ...prevValues, collectionId }));
};
@@ -66,6 +67,7 @@ export default function BulkEditLinksModal({ onClose }: Props) {
@@ -74,7 +76,7 @@ export default function BulkEditLinksModal({ onClose }: Props) {
-
+
diff --git a/lib/api/controllers/links/linkId/updateLinkById.ts b/lib/api/controllers/links/linkId/updateLinkById.ts
index 6944999..62b2945 100644
--- a/lib/api/controllers/links/linkId/updateLinkById.ts
+++ b/lib/api/controllers/links/linkId/updateLinkById.ts
@@ -16,6 +16,10 @@ export default async function updateLinkById(
};
const collectionIsAccessible = await getPermission({ userId, linkId });
+ const targetCollectionIsAccessible = await getPermission({
+ userId,
+ collectionId: data.collection.id,
+ });
const memberHasAccess = collectionIsAccessible?.members.some(
(e: UsersAndCollections) => e.userId === userId && e.canUpdate
@@ -25,6 +29,28 @@ export default async function updateLinkById(
collectionIsAccessible?.ownerId === data.collection.ownerId &&
data.collection.ownerId === userId;
+ const targetCollectionsAccessible =
+ targetCollectionIsAccessible?.ownerId === userId;
+
+ const targetCollectionMatchesData = data.collection.id
+ ? data.collection.id === targetCollectionIsAccessible?.id
+ : true && data.collection.name
+ ? data.collection.name === targetCollectionIsAccessible?.name
+ : true && data.collection.ownerId
+ ? data.collection.ownerId === targetCollectionIsAccessible?.ownerId
+ : true;
+
+ if (!targetCollectionsAccessible)
+ return {
+ response: "Target collection is not accessible.",
+ status: 401,
+ };
+ else if (!targetCollectionMatchesData)
+ return {
+ response: "Target collection does not match the data.",
+ status: 401,
+ };
+
const unauthorizedSwitchCollection =
!isCollectionOwner && collectionIsAccessible?.id !== data.collection.id;
diff --git a/lib/api/getPermission.ts b/lib/api/getPermission.ts
index 61dc5c5..93dd04c 100644
--- a/lib/api/getPermission.ts
+++ b/lib/api/getPermission.ts
@@ -3,12 +3,14 @@ import { prisma } from "@/lib/api/db";
type Props = {
userId: number;
collectionId?: number;
+ collectionName?: string;
linkId?: number;
};
export default async function getPermission({
userId,
collectionId,
+ collectionName,
linkId,
}: Props) {
if (linkId) {
@@ -24,10 +26,11 @@ export default async function getPermission({
});
return check;
- } else if (collectionId) {
+ } else if (collectionId || collectionName) {
const check = await prisma.collection.findFirst({
where: {
- id: collectionId,
+ id: collectionId || undefined,
+ name: collectionName || undefined,
OR: [{ ownerId: userId }, { members: { some: { userId } } }],
},
include: { members: true },
diff --git a/store/links.ts b/store/links.ts
index 01935e4..408a3ee 100644
--- a/store/links.ts
+++ b/store/links.ts
@@ -152,6 +152,11 @@ const useLinkStore = create
()((set) => ({
links.some((link) => link.id === e.id)
? {
...e,
+ collectionId: newData.collectionId ?? e.collectionId,
+ collection: {
+ ...e.collection,
+ id: newData.collectionId ?? e.collection.id,
+ },
tags: removePreviousTags
? [...(newData.tags ?? [])]
: [...e.tags, ...(newData.tags ?? [])],