Skip to content

Commit

Permalink
Added file sharing reset when file becomes publicly accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianLeChat committed Feb 5, 2024
1 parent 8caf560 commit 5f9e147
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
20 changes: 17 additions & 3 deletions app/[locale]/dashboard/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,34 @@ export async function changeFileStatus( formData: FormData )
return false;
}

// On met à jour le statut du fichier dans la base de données
// avant de retourner une valeur de succès.
// On met à jour le statut du fichier dans la base de données.
const files = await prisma.file.updateMany( {
where: {
id: {
in: result.data.fileIds
},
userId: session.user.id
userId: session.user.id,
status: result.data.status === "private" ? "public" : undefined
},
data: {
status: result.data.status
}
} );

// On réinitialise également les partages des fichiers si ceux-ci
// deviennent publiquement accessibles.
if ( result.data.status === "public" )
{
await prisma.share.deleteMany( {
where: {
fileId: {
in: result.data.fileIds
}
}
} );
}

// On retourne enfin une valeur de succès à la fin du traitement.
return files.count > 0;
}

Expand Down
1 change: 1 addition & 0 deletions app/[locale]/dashboard/components/row-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export default function RowActions( {
<AlertDialogTrigger asChild>
<DropdownMenuItem
// https://github.com/radix-ui/primitives/issues/1836#issuecomment-1674338372
disabled={rowData[ 0 ].status === "shared"}
onSelect={( event ) => event.preventDefault()}
>
<FolderLock className="mr-2 h-4 w-4" />
Expand Down

0 comments on commit 5f9e147

Please sign in to comment.