Allow contributors to pin a link in a shared to a collection to their dashboard
This commit is contained in:
parent
34e0115a0f
commit
2d0093172a
|
@ -67,8 +67,7 @@ export default function LinkActions({
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
className={`dropdown dropdown-left dropdown-end absolute ${
|
className={`dropdown dropdown-left dropdown-end absolute ${position || "top-3 right-3"
|
||||||
position || "top-3 right-3"
|
|
||||||
} z-20`}
|
} z-20`}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
@ -80,7 +79,7 @@ export default function LinkActions({
|
||||||
<i title="More" className="bi-three-dots text-xl" />
|
<i title="More" className="bi-three-dots text-xl" />
|
||||||
</div>
|
</div>
|
||||||
<ul className="dropdown-content z-[20] menu shadow bg-base-200 border border-neutral-content rounded-box w-44 mr-1 translate-y-10">
|
<ul className="dropdown-content z-[20] menu shadow bg-base-200 border border-neutral-content rounded-box w-44 mr-1 translate-y-10">
|
||||||
{permissions === true ? (
|
{permissions ? (
|
||||||
<li>
|
<li>
|
||||||
<div
|
<div
|
||||||
role="button"
|
role="button"
|
||||||
|
|
|
@ -21,6 +21,10 @@ export default async function updateLinkById(
|
||||||
(e: UsersAndCollections) => e.userId === userId && e.canUpdate
|
(e: UsersAndCollections) => e.userId === userId && e.canUpdate
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const canCreatePermission = collectionIsAccessible?.members.some(
|
||||||
|
(e: UsersAndCollections) => e.userId === userId && e.canCreate
|
||||||
|
);
|
||||||
|
|
||||||
const isCollectionOwner =
|
const isCollectionOwner =
|
||||||
collectionIsAccessible?.ownerId === data.collection.ownerId &&
|
collectionIsAccessible?.ownerId === data.collection.ownerId &&
|
||||||
data.collection.ownerId === userId;
|
data.collection.ownerId === userId;
|
||||||
|
@ -34,6 +38,32 @@ export default async function updateLinkById(
|
||||||
response: "You can't move a link to/from a collection you don't own.",
|
response: "You can't move a link to/from a collection you don't own.",
|
||||||
status: 401,
|
status: 401,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// If the user is able to create a link, they can pin it to their dashboard only.
|
||||||
|
if (canCreatePermission) {
|
||||||
|
const updatedLink = await prisma.link.update({
|
||||||
|
where: {
|
||||||
|
id: linkId,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
pinnedBy: data?.pinnedBy && data.pinnedBy[0]
|
||||||
|
? { connect: { id: userId } }
|
||||||
|
: { disconnect: { id: userId } },
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
collection: true,
|
||||||
|
pinnedBy: isCollectionOwner
|
||||||
|
? {
|
||||||
|
where: { id: userId },
|
||||||
|
select: { id: true },
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return { response: updatedLink, status: 200 };
|
||||||
|
}
|
||||||
|
|
||||||
else if (collectionIsAccessible?.ownerId !== userId && !memberHasAccess)
|
else if (collectionIsAccessible?.ownerId !== userId && !memberHasAccess)
|
||||||
return {
|
return {
|
||||||
response: "Collection is not accessible.",
|
response: "Collection is not accessible.",
|
||||||
|
|
Ŝarĝante…
Reference in New Issue