def remove_volume(request, project_id, volume_id): """Remove a particular volume, if the user has permission to it. """ cursor = connection.cursor() cursor.execute(""" SELECT user_id FROM catmaid_volume WHERE id=%s """, (volume_id,)) rows = cursor.fetchall() if 0 == len(rows): raise ValueError("Could not find volume with ID {}".format(volume_id)) volume_user_id = rows[0][0] if not user_can_edit(connection.cursor(), request.user.id, volume_user_id) and not request.user.is_superuser: raise Exception("You don't have permissions to delete this volume") cursor.execute(""" WITH v AS ( DELETE FROM catmaid_volume WHERE id=%s RETURNING id ), vci AS ( DELETE FROM volume_class_instance USING v WHERE volume_id = v.id RETURNING class_instance_id ) DELETE FROM class_instance USING vci WHERE id = vci.class_instance_id; """, (volume_id,)) return Response({ "success": True, "volume_id": volume_id })
def remove_volume(request, project_id, volume_id): """Remove a particular volume, if the user has permission to it. """ cursor = connection.cursor() cursor.execute( """ SELECT user_id FROM catmaid_volume WHERE id=%s """, (volume_id, )) rows = cursor.fetchall() if 0 == len(rows): raise ValueError("Could not find volume with ID {}".format(volume_id)) volume_user_id = rows[0][0] if not user_can_edit(connection.cursor(), request.user.id, volume_user_id) and not request.user.is_superuser: raise Exception("You don't have permissions to delete this volume") cursor.execute(""" DELETE FROM catmaid_volume WHERE id=%s """, (volume_id, )) return Response({"success": True, "volume_id": volume_id})
def remove_volume(request: Request, project_id, volume_id) -> Response: """Remove a particular volume, if the user has permission to it. """ cursor = connection.cursor() cursor.execute( """ SELECT user_id FROM catmaid_volume WHERE id=%s """, (volume_id, )) rows = cursor.fetchall() if 0 == len(rows): raise ValueError(f"Could not find volume with ID {volume_id}") volume_user_id = rows[0][0] if not user_can_edit(connection.cursor(), request.user.id, volume_user_id) and not request.user.is_superuser: raise Exception("You don't have permissions to delete this volume") cursor.execute( """ WITH v AS ( DELETE FROM catmaid_volume WHERE id=%s RETURNING id ), vci AS ( DELETE FROM volume_class_instance USING v WHERE volume_id = v.id RETURNING class_instance_id ), ci AS ( DELETE FROM class_instance USING vci WHERE id = vci.class_instance_id RETURNING id ) DELETE FROM class_instance_class_instance USING ci WHERE class_instance_a = ci.id OR class_instance_b = ci.id """, (volume_id, )) return Response({"success": True, "volume_id": volume_id})