Skip to content

Commit

Permalink
Merge pull request #456 from IsaacWise06/issue/334
Browse files Browse the repository at this point in the history
feat(collections): Allow a contributor to pin a link from a collection to their dashboard
  • Loading branch information
daniel31x13 committed Feb 7, 2024
2 parents 39e022f + daed2d8 commit d5bd095
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 16 deletions.
30 changes: 14 additions & 16 deletions components/LinkViews/LinkComponents/LinkActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,20 @@ export default function LinkActions({
<i title="More" className="bi-three-dots text-xl" />
</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">
{permissions === true ? (
<li>
<div
role="button"
tabIndex={0}
onClick={() => {
(document?.activeElement as HTMLElement)?.blur();
pinLink();
}}
>
{link?.pinnedBy && link.pinnedBy[0]
? "Unpin"
: "Pin to Dashboard"}
</div>
</li>
) : undefined}
<li>
<div
role="button"
tabIndex={0}
onClick={() => {
(document?.activeElement as HTMLElement)?.blur();
pinLink();
}}
>
{link?.pinnedBy && link.pinnedBy[0]
? "Unpin"
: "Pin to Dashboard"}
</div>
</li>
{linkInfo !== undefined && toggleShowInfo ? (
<li>
<div
Expand Down
30 changes: 30 additions & 0 deletions lib/api/controllers/links/linkId/updateLinkById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,36 @@ export default async function updateLinkById(
const unauthorizedSwitchCollection =
!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.
if (unauthorizedSwitchCollection)
return {
Expand Down

0 comments on commit d5bd095

Please sign in to comment.