Merge pull request #456 from IsaacWise06/issue/334
feat(collections): Allow a contributor to pin a link from a collection to their dashboard
This commit is contained in:
commit
d5bd095827
|
@ -80,22 +80,20 @@ 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 ? (
|
<li>
|
||||||
<li>
|
<div
|
||||||
<div
|
role="button"
|
||||||
role="button"
|
tabIndex={0}
|
||||||
tabIndex={0}
|
onClick={() => {
|
||||||
onClick={() => {
|
(document?.activeElement as HTMLElement)?.blur();
|
||||||
(document?.activeElement as HTMLElement)?.blur();
|
pinLink();
|
||||||
pinLink();
|
}}
|
||||||
}}
|
>
|
||||||
>
|
{link?.pinnedBy && link.pinnedBy[0]
|
||||||
{link?.pinnedBy && link.pinnedBy[0]
|
? "Unpin"
|
||||||
? "Unpin"
|
: "Pin to Dashboard"}
|
||||||
: "Pin to Dashboard"}
|
</div>
|
||||||
</div>
|
</li>
|
||||||
</li>
|
|
||||||
) : undefined}
|
|
||||||
{linkInfo !== undefined && toggleShowInfo ? (
|
{linkInfo !== undefined && toggleShowInfo ? (
|
||||||
<li>
|
<li>
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -28,6 +28,36 @@ export default async function updateLinkById(
|
||||||
const unauthorizedSwitchCollection =
|
const unauthorizedSwitchCollection =
|
||||||
!isCollectionOwner && collectionIsAccessible?.id !== data.collection.id;
|
!isCollectionOwner && collectionIsAccessible?.id !== data.collection.id;
|
||||||
|
|
||||||
|
const canPinPermission = collectionIsAccessible?.members.some(
|
||||||
|
(e: UsersAndCollections) => e.userId === userId
|
||||||
|
);
|
||||||
|
|
||||||
|
// If the user is able to create a link, they can pin it to their dashboard only.
|
||||||
|
if (canPinPermission) {
|
||||||
|
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 };
|
||||||
|
}
|
||||||
|
|
||||||
// Makes sure collection members (non-owners) cannot move a link to/from a collection.
|
// Makes sure collection members (non-owners) cannot move a link to/from a collection.
|
||||||
if (unauthorizedSwitchCollection)
|
if (unauthorizedSwitchCollection)
|
||||||
return {
|
return {
|
||||||
|
|
Ŝarĝante…
Reference in New Issue