From 402411f7b9bc2776b55b28d0590754d20f2929d0 Mon Sep 17 00:00:00 2001 From: Alexis Feron Date: Mon, 2 Jun 2025 11:04:51 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20a=20get=20route=20for=20pin?= =?UTF-8?q?=20shares?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/routes/pins.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/app/routes/pins.py b/app/routes/pins.py index 036a802..b1dcf84 100644 --- a/app/routes/pins.py +++ b/app/routes/pins.py @@ -212,5 +212,35 @@ async def delete_pin(id: str, current_user: User = Depends(get_current_user)): raise HTTPException(status_code=403, detail="You don't have permission to delete this pin") + except bson.errors.InvalidId: + objectid_misformatted() + +@pins_router.get( + path="/{id}/shares", + responses={401: {"model": HTTPError}, 404: {"model": HTTPError}, 422: {"model": HTTPError}, 403: {"model": HTTPError}} +) +async def get_pin_shares(id: str, current_user: User = Depends(get_current_user)): + try: + # Vérifier si le pin existe et appartient à l'utilisateur courant + pin = pins_collection.find_one({"_id": ObjectId(id)}) + check_pin_is_null(pin) + + if pin["user_id"] != current_user.uid: + raise HTTPException(status_code=403, detail="You can only view shares of your own pins") + + # Récupérer toutes les permissions de partage pour ce pin + shares = pin_permissions_collection.find({"pin_id": ObjectId(id)}) + + # Transformer les résultats en liste de dictionnaires + shares_list = [] + for share in shares: + shares_list.append({ + "user_id": str(share["user_id"]), + "can_edit": share["can_edit"], + "can_delete": share["can_delete"] + }) + + return {"shares": shares_list} + except bson.errors.InvalidId: objectid_misformatted() \ No newline at end of file