Esempio n. 1
0
async def update_room(
        payload: RoomUpdate,
        room_id: int,
        viewer_uuid: int = Depends(get_uuid_from_xtoken),
):
    path = f"/rooms/{room_id}"
    room, _ = Requester.room_srv_fetch(method="GET",
                                       path=path,
                                       expected_statuses={HTTP_200_OK})

    if not AuthSender.has_permission_to_modify(viewer_uuid,
                                               room["owner_uuid"]):
        raise BadRequestError("You can't update other users rooms!")

    room_req_payload = payload.dict(exclude_unset=True)

    path = f"/rooms/{room_id}"
    room, _ = Requester.room_srv_fetch(
        method="PATCH",
        path=path,
        expected_statuses={HTTP_200_OK},
        payload=room_req_payload,
    )

    # TODO: Patch room price in payment server

    return room
async def delete_booking(booking_id: int,
                         uuid: int = Depends(get_uuid_from_xtoken)):
    path = f"/bookings/{booking_id}"
    booking, _ = Requester.payment_fetch(method="GET",
                                         path=path,
                                         expected_statuses={HTTP_200_OK})
    room_id = booking["roomId"]
    room_owner_id = booking["roomOwnerId"]

    if not AuthSender.has_permission_to_modify(uuid, room_owner_id):
        raise UnauthorizedRequestError("Can't reject other users bookings")

    path = f"/bookings/{booking_id}"
    book_deleted, _ = Requester.payment_fetch("DELETE", path, {HTTP_200_OK})

    # Delete the rejected booking in post server,
    # if it is not found it is also OK!
    booking_path = f"/rooms/{room_id}/bookings/{booking_id}"
    booking, _ = Requester.room_srv_fetch("DELETE", booking_path,
                                          {HTTP_200_OK, HTTP_404_NOT_FOUND})

    # TODO: Change BookingDB model to match camelcase in payment server
    booking_camel = payment_camel_to_snake(book_deleted)

    return booking_camel
async def accept_booking(booking_id: int,
                         uuid: int = Depends(get_uuid_from_xtoken)):
    path = f"/bookings/{booking_id}"
    booking, _ = Requester.payment_fetch(method="GET",
                                         path=path,
                                         expected_statuses={HTTP_200_OK})
    room_owner_id = booking["roomOwnerId"]

    if not AuthSender.has_permission_to_modify(uuid, room_owner_id):
        raise UnauthorizedRequestError("Can't accept other users bookings")

    path = f"/bookings/{booking_id}/accept"
    payload_accept = {"roomOwnerId": room_owner_id}
    book_accepted, _ = Requester.payment_fetch("POST",
                                               path, {HTTP_200_OK},
                                               payload=payload_accept)

    # TODO: Change BookingDB model to match camelcase in payment server
    booking_camel = payment_camel_to_snake(book_accepted)

    # Send notification
    sender, _ = Requester.user_srv_fetch(
        "GET", f"/users/{booking_camel['room_owner_id']}", {HTTP_200_OK})
    sender_name = f"{sender['firstname']} {sender['lastname']}"

    room, _ = Requester.room_srv_fetch("GET",
                                       f"/rooms/{booking_camel['room_id']}",
                                       {HTTP_200_OK})
    room_title = room["title"]

    notifier.send_booking_accepted_notification(sender_name, room_title,
                                                booking_camel["booker_id"])

    return booking_camel
async def create_guest_rating(
        payload: UserRatingSchema,
        user_id: int,
        uuid: int = Depends(get_uuid_from_xtoken),
):
    if not AuthSender.has_permission_to_comment(uuid, user_id):
        raise UnauthorizedRequestError("You can't create a rating yourself")

    path = f"/users/{uuid}"
    me, _ = Requester.user_srv_fetch(method="GET",
                                     path=path,
                                     expected_statuses={HTTP_200_OK})

    new_payload = {
        "rating": payload.dict()["rating"],
        "reviewer": f"{me['firstname']} {me['lastname']}",
        "reviewer_id": uuid,
    }

    path = f"/users/{user_id}/guest_ratings"
    rating, _ = Requester.user_srv_fetch(
        method="POST",
        path=path,
        expected_statuses={HTTP_201_CREATED},
        payload=new_payload,
    )

    # Send notification
    notifier.send_new_user_guest_rating_notification(new_payload["reviewer"],
                                                     new_payload["rating"],
                                                     user_id)

    return rating
Esempio n. 5
0
async def delete_favorite_room(
        favorite_id: int,
        uuid: int = Depends(get_uuid_from_xtoken),
):

    path = f"/users/{uuid}/favorite_rooms/{favorite_id}"
    favorite_room, _ = Requester.user_srv_fetch(
        method="GET",
        path=path,
        expected_statuses={HTTP_200_OK},
    )

    room_path = f"/rooms/{favorite_room['room_id']}"
    room, _ = Requester.room_srv_fetch(method="GET",
                                       path=room_path,
                                       expected_statuses={HTTP_200_OK})

    path = f"/users/{uuid}/favorite_rooms/{favorite_id}"
    favorite_rooms, _ = Requester.user_srv_fetch(
        method="DELETE",
        path=path,
        expected_statuses={HTTP_200_OK},
    )

    return room
Esempio n. 6
0
async def add_room_picture(
        room_id: int,
        file: UploadFile = File(...),
        db: Session = Depends(get_db),
        uuid: int = Depends(get_uuid_from_xtoken),
):
    room_path = f"/rooms/{room_id}"
    room, _ = Requester.room_srv_fetch("GET", room_path, {HTTP_200_OK})

    if not AuthSender.has_permission_to_modify(room["owner_uuid"], uuid):
        raise UnauthorizedRequestError(
            "You can't add photos to another user room!")

    image_url, firebase_id = photouploader.upload_room_photo(file, room_id)

    room_photo_path = f"/rooms/{room_id}/photos"
    new_photo_request = {"url": image_url, "firebase_id": firebase_id}
    photo_response, _ = Requester.room_srv_fetch("POST",
                                                 room_photo_path,
                                                 {HTTP_201_CREATED},
                                                 payload=new_photo_request)
    # photo_id = photo_response["id"]

    # RoomPhotoDAO.add_new_room_photo(db, firebase_id, photo_id)
    return photo_response
async def create_user(
        payload: UserSchema,
        x_access_token: Optional[str] = Header(None),
):
    auth_payload = {"email": payload.dict()["email"]}
    auth_header = {"x-access-token": x_access_token}
    registered_user, _ = Requester.auth_srv_fetch(
        method="POST",
        path="/user/registered",
        expected_statuses={HTTP_201_CREATED},
        payload=auth_payload,
        extra_headers=auth_header,
    )
    path = "/users"
    payload_user = payload.dict()
    payload_user.update({"id": registered_user["uuid"]})
    user, _ = Requester.user_srv_fetch(
        method="POST",
        path=path,
        expected_statuses={HTTP_201_CREATED},
        payload=payload_user,
    )

    # create wallet
    path = "/wallets"
    payload_wallet = {"uuid": registered_user["uuid"]}
    wallet, _ = Requester.payment_fetch(
        method="POST",
        path=path,
        expected_statuses={HTTP_201_CREATED},
        payload=payload_wallet,
    )

    return user
Esempio n. 8
0
async def create_room(payload: RoomSchema,
                      uuid: int = Depends(get_uuid_from_xtoken)):
    path = f"/users/{uuid}"
    user, _ = Requester.user_srv_fetch(method="GET",
                                       path=path,
                                       expected_statuses={HTTP_200_OK})
    owner = f"{user['firstname']} {user['lastname']}"

    req_payload = payload.dict()
    req_payload.update({"owner_uuid": uuid, "owner": owner})

    payment_payload = {
        "ownerId": req_payload["owner_uuid"],
        "price": req_payload["price_per_day"],
    }

    # Create room in payment server and generate an ID
    room_pay_srv, _ = Requester.payment_fetch(
        method="POST",
        path="/rooms",
        expected_statuses={HTTP_201_CREATED},
        payload=payment_payload,
    )

    # Add id to the room created in room server
    req_payload["id"] = room_pay_srv["id"]

    room, _ = Requester.room_srv_fetch(
        method="POST",
        path="/rooms",
        expected_statuses={HTTP_201_CREATED},
        payload=req_payload,
    )

    return room
Esempio n. 9
0
async def get_current_user_bookings(uuid: int = Depends(get_uuid_from_xtoken)):
    path = f"/bookings?roomOwnerId={uuid}"
    bookings_received, _ = Requester.payment_fetch(
        method="GET", path=path, expected_statuses={HTTP_200_OK})
    path = f"/bookings?bookerId={uuid}"
    bookings_made, _ = Requester.payment_fetch(method="GET",
                                               path=path,
                                               expected_statuses={HTTP_200_OK})

    # TODO: Change BookingDB model to match camelcase in payment server
    for i in range(len(bookings_made)):
        bookings_made[i] = payment_camel_to_snake(bookings_made[i])

    for i in range(len(bookings_received)):
        bookings_received[i] = payment_camel_to_snake(bookings_received[i])

    bookings = {
        "made": {
            "amount": len(bookings_made),
            "bookings": bookings_made,
        },
        "received": {
            "amount": len(bookings_received),
            "bookings": bookings_received,
        },
    }

    return bookings
async def create_new_booking(
        payload: BookingSchema,
        uuid: int = Depends(get_uuid_from_xtoken),
):

    room_id = payload.dict()["room_id"]
    room_path = f"/rooms/{room_id}"
    room, _ = Requester.room_srv_fetch("GET", room_path, {HTTP_200_OK})

    if not AuthSender.can_book_room(room["owner_uuid"], uuid):
        raise NotAllowedRequestError("Can't create booking of your own room")

    if room["blocked"]:
        raise NotAllowedRequestError(
            "Can't create booking because the room is blocked")

    # Create intent book in payment server

    booking_path = "/bookings"
    payload_booking = {
        "bookerId": uuid,
        "roomId": room_id,
        "dateFrom": payload.dict()["date_from"].strftime("%d-%m-%Y"),
        "dateTo": payload.dict()["date_to"].strftime("%d-%m-%Y"),
    }
    booking, _ = Requester.payment_fetch(
        method="POST",
        path=booking_path,
        expected_statuses={HTTP_201_CREATED},
        payload=payload_booking,
    )

    # Create booking in room server
    booking_path = f"/rooms/{room_id}/bookings"
    # Add the booking id received from the payment server
    payload_booking = {
        "id": booking["id"],
        "date_from": payload.dict()["date_from"].strftime("%Y-%m-%d"),
        "date_to": payload.dict()["date_to"].strftime("%Y-%m-%d"),
    }

    booking_room, _ = Requester.room_srv_fetch("POST",
                                               booking_path,
                                               {HTTP_201_CREATED},
                                               payload=payload_booking)

    # TODO: Change BookingDB model to match camelcase in payment server
    booking_camel = payment_camel_to_snake(booking)

    # Send notification
    sender, _ = Requester.user_srv_fetch("GET", f"/users/{uuid}",
                                         {HTTP_200_OK})

    sender_name = f"{sender['firstname']} {sender['lastname']}"

    notifier.send_new_booking_received_notification(sender_name, room["title"],
                                                    room["owner_uuid"])

    return booking_camel
Esempio n. 11
0
async def create_room_comment(
        payload: RoomCommentSchema,
        room_id: int,
        viewer_uuid: int = Depends(get_uuid_from_xtoken),
):
    room_path = "/rooms" + f"/{room_id}"
    room, _ = Requester.room_srv_fetch(method="GET",
                                       path=room_path,
                                       expected_statuses={HTTP_200_OK})

    if ((payload.dict()["main_comment_id"] is None)
            and (not AuthSender.has_permission_to_comment(
                viewer_uuid, room["owner_uuid"]))):
        raise BadRequestError("You can't comment your own rooms!")

    user_path = "/users" + f"/{viewer_uuid}"
    user, _ = Requester.user_srv_fetch(method="GET",
                                       path=user_path,
                                       expected_statuses={HTTP_200_OK})
    commentator = f"{user['firstname']} {user['lastname']}"

    comment_payload = payload.dict()
    comment_payload.update({
        "commentator": commentator,
        "commentator_id": viewer_uuid
    })

    comment_path = "/rooms" + f"/{room_id}/comments"
    comment, _ = Requester.room_srv_fetch(
        method="POST",
        path=comment_path,
        expected_statuses={HTTP_201_CREATED},
        payload=comment_payload,
    )

    # Send notifications
    if (comment_payload["main_comment_id"] is None):
        # send notification to room_owner
        notifier.send_new_comment_notification(commentator, room["title"],
                                               room["owner_uuid"])
    elif (viewer_uuid == room["owner_uuid"]):
        # send notification answer to main_comment_owner
        main_comment, _ = Requester.room_srv_fetch(
            method="GET",
            path=comment_path + f'/{comment_payload["main_comment_id"]}',
            expected_statuses={HTTP_200_OK})
        notifier.send_answered_comment_notification(
            commentator, room["title"], main_comment["commentator_id"])
    else:
        # send notification answer to owner
        notifier.send_answered_comment_notification(commentator, room["title"],
                                                    room["owner_uuid"])

    return comment
Esempio n. 12
0
async def get_current_user_rooms(uuid: int = Depends(get_uuid_from_xtoken)):
    path = f"/rooms?owner_uuid={uuid}"
    rooms, _ = Requester.room_srv_fetch(method="GET",
                                        path=path,
                                        expected_statuses={HTTP_200_OK})

    return rooms
Esempio n. 13
0
async def get_room(room_id: int, uuid: int = Depends(get_uuid_from_xtoken)):
    path = f"/rooms/{room_id}"
    room, _ = Requester.room_srv_fetch(method="GET",
                                       path=path,
                                       expected_statuses={HTTP_200_OK})

    path = f"/users/{uuid}/favorite_rooms/{room_id}"
    favorite_room, _ = Requester.user_srv_fetch(
        method="GET",
        path=path,
        expected_statuses={HTTP_200_OK, HTTP_404_NOT_FOUND},
    )

    if "room_id" in favorite_room.keys():
        room["favorite"] = True

    return room
Esempio n. 14
0
async def delete_room_comment(
        room_id: int,
        comment_id: int,
        viewer_uuid: int = Depends(get_uuid_from_xtoken),
):
    comment_path = f"/rooms/{room_id}/comments/{comment_id}"
    comment, _ = Requester.room_srv_fetch(method="GET",
                                          path=comment_path,
                                          expected_statuses={HTTP_200_OK})

    if not AuthSender.has_permission_to_modify(viewer_uuid,
                                               comment["commentator_id"]):
        raise BadRequestError("You can't delete other users room comments!")

    comment, _ = Requester.room_srv_fetch(method="DELETE",
                                          path=comment_path,
                                          expected_statuses={HTTP_200_OK})
    return comment
Esempio n. 15
0
async def delete_room_review(
        room_id: int,
        review_id: int,
        viewer_uuid: int = Depends(get_uuid_from_xtoken),
):
    review_path = f"/rooms/{room_id}/reviews/{review_id}"
    review, _ = Requester.room_srv_fetch(method="GET",
                                         path=review_path,
                                         expected_statuses={HTTP_200_OK})

    if not AuthSender.has_permission_to_modify(viewer_uuid,
                                               review["reviewer_id"]):
        raise BadRequestError("You can't delete other users room reviews!")

    review, _ = Requester.room_srv_fetch(method="DELETE",
                                         path=review_path,
                                         expected_statuses={HTTP_200_OK})
    return review
Esempio n. 16
0
async def delete_user(user_id: int,
                      uuid: int = Depends(get_uuid_from_xtoken),
                      x_access_token: Optional[str] = Header(None)):

    auth_header = {"x-access-token": x_access_token}
    if not AuthSender.has_permission_to_modify(uuid, user_id):
        raise UnauthorizedRequestError("You can't delete other users")

    path = f"/users/{user_id}"
    new_user_info, _ = Requester.user_srv_fetch(
        method="DELETE", path=path, expected_statuses={HTTP_200_OK})

    auth_path = f"/user/registered/{uuid}"
    Requester.auth_srv_fetch("DELETE",
                             path=auth_path,
                             expected_statuses={HTTP_200_OK},
                             extra_headers=auth_header)

    return new_user_info
async def get_booking(booking_id: int):
    path = f"/bookings/{booking_id}"
    booking, _ = Requester.payment_fetch(method="GET",
                                         path=path,
                                         expected_statuses={HTTP_200_OK})

    # TODO: Change BookingDB model to match camelcase in payment server
    booking_camel = payment_camel_to_snake(booking)

    return booking_camel
Esempio n. 18
0
async def create_favorite_room(
        payload: UserFavoriteRoomSchema,
        uuid: int = Depends(get_uuid_from_xtoken),
):

    room_path = f"/rooms/{payload.dict()['room_id']}"
    room, _ = Requester.room_srv_fetch(method="GET",
                                       path=room_path,
                                       expected_statuses={HTTP_200_OK})

    path = f"/users/{uuid}/favorite_rooms"
    favorite_room, _ = Requester.user_srv_fetch(
        method="POST",
        path=path,
        expected_statuses={HTTP_201_CREATED},
        payload=payload.dict(),
    )

    return room
Esempio n. 19
0
async def get_all_rooms(date_begins: Optional[str] = None,
                        date_ends: Optional[str] = None,
                        longitude: Optional[float] = None,
                        latitude: Optional[float] = None,
                        people: Optional[int] = None,
                        types: List[str] = Query(None),
                        max_price: Optional[int] = None,
                        min_price: Optional[int] = None,
                        allow_blocked: Optional[bool] = False,
                        only_blocked: Optional[bool] = False):
    query = "?"
    path = "/rooms"

    if date_begins is not None:
        query = query + f"date_begins={date_begins}&"

    if date_ends is not None:
        query = query + f"date_ends={date_ends}&"

    if longitude is not None:
        query = query + f"longitude={longitude}&"

    if latitude is not None:
        query = query + f"latitude={latitude}&"

    if people is not None:
        query = query + f"people={people}&"

    if types is not None:
        for specific_type in types:
            query = query + f"types={specific_type}&"

    if min_price is not None:
        query = query + f"min_price={min_price}&"

    if max_price is not None:
        query = query + f"max_price={max_price}&"

    if allow_blocked is not None:
        query = query + f"allow_blocked={allow_blocked}&"

    if only_blocked is not None:
        query = query + f"only_blocked={only_blocked}&"

    if len(query) > 1:
        # strip last & in the query
        query = query[:(len(query) - 1)]
        path = path + "/" + query

    rooms, _ = Requester.room_srv_fetch(method="GET",
                                        path=path,
                                        expected_statuses={HTTP_200_OK})

    return rooms
Esempio n. 20
0
async def delete_room(room_id: int,
                      viewer_uuid: int = Depends(get_uuid_from_xtoken)):
    path = "/rooms" + f"/{room_id}"
    room, _ = Requester.room_srv_fetch(method="GET",
                                       path=path,
                                       expected_statuses={HTTP_200_OK})

    if not AuthSender.has_permission_to_modify(viewer_uuid,
                                               room["owner_uuid"]):
        raise BadRequestError("You can't delete other users rooms!")

    path = "/rooms" + f"/{room_id}"
    room, _ = Requester.room_srv_fetch(method="DELETE",
                                       path=path,
                                       expected_statuses={HTTP_200_OK})

    room_pay, _ = Requester.payment_fetch(method="DELETE",
                                          path=path,
                                          expected_statuses={HTTP_200_OK})

    return room
Esempio n. 21
0
async def get_favorite_rooms(uuid: int = Depends(get_uuid_from_xtoken), ):
    path = f"/users/{uuid}/favorite_rooms"
    favorite_rooms, _ = Requester.user_srv_fetch(
        method="GET",
        path=path,
        expected_statuses={HTTP_200_OK},
    )

    query = "?"
    if len(favorite_rooms["favorites"]) > 0:
        for favorite in favorite_rooms["favorites"]:
            query = query + f"ids={favorite['room_id']}&"
    else:
        query = query + f"ids={-1}"

    room_path = "/rooms" + query
    rooms, _ = Requester.room_srv_fetch(method="GET",
                                        path=room_path,
                                        expected_statuses={HTTP_200_OK})

    return rooms
Esempio n. 22
0
async def rate_room(
        payload: RoomRatingSchema,
        room_id: int,
        viewer_uuid: int = Depends(get_uuid_from_xtoken),
):
    room_path = f"/rooms/{room_id}"
    room, _ = Requester.room_srv_fetch(method="GET",
                                       path=room_path,
                                       expected_statuses={HTTP_200_OK})

    if not AuthSender.has_permission_to_comment(viewer_uuid,
                                                room["owner_uuid"]):
        raise BadRequestError("You can't rate your own rooms!")

    user_path = f"/users/{viewer_uuid}"
    user, _ = Requester.user_srv_fetch(method="GET",
                                       path=user_path,
                                       expected_statuses={HTTP_200_OK})
    reviewer_name = f"{user['firstname']} {user['lastname']}"

    rating_req_payload = payload.dict()
    rating_req_payload.update({
        "reviewer": reviewer_name,
        "reviewer_id": viewer_uuid
    })

    room_rating_path = f"/rooms/{room_id}/ratings"
    rating, _ = Requester.room_srv_fetch(
        method="POST",
        path=room_rating_path,
        expected_statuses={HTTP_201_CREATED},
        payload=rating_req_payload,
    )

    # Send notification
    notifier.send_new_room_rating_notification(reviewer_name, room["title"],
                                               rating_req_payload["rating"],
                                               room["owner_uuid"])

    return rating
Esempio n. 23
0
    def is_valid_token(cls, token):
        response, code = Requester.auth_srv_fetch(
            method="POST",
            path="/auth/sign-in",
            expected_statuses={HTTP_200_OK},
            payload={},
            extra_headers=cls.tkn_hdr(token),
        )
        logger.debug(
            "Auth server validate token response: %s, status_code: %s",
            response, code)

        return code == 200
Esempio n. 24
0
async def delete_room_photo(
        room_id: int,
        firebase_id: int,
        db: Session = Depends(get_db),
        uuid: int = Depends(get_uuid_from_xtoken),
):
    room_path = f"/rooms/{room_id}"
    room, _ = Requester.room_srv_fetch("GET", room_path, {HTTP_200_OK})

    if not AuthSender.has_permission_to_modify(room["owner_uuid"], uuid):
        raise UnauthorizedRequestError(
            "You can't delete photos of another user room!")

    # photo = RoomPhotoDAO.delete_room_photo(db, firebase_id)
    # if photo is None:
    #     raise NotFoundError("Photo id")
    # photo_id = photo["room_photo_id"]

    # room_photo_path = f"/rooms/{room_id}/photos/{photo_id}"
    room_photo_path = f"/rooms/{room_id}/photos/{firebase_id}"
    photo_response, _ = Requester.room_srv_fetch("DELETE", room_photo_path,
                                                 {HTTP_200_OK})
    return photo_response
Esempio n. 25
0
async def get_room_photo(
        room_id: int,
        firebase_id: int,
        db: Session = Depends(get_db),
):
    # photo = RoomPhotoDAO.get_room_photo(db, firebase_id)

    # photo_id = photo["room_photo_id"]
    # room_photo_path = f"/rooms/{room_id}/photos/{photo_id}"
    room_photo_path = f"/rooms/{room_id}/photos/{firebase_id}"

    photo_response, _ = Requester.room_srv_fetch("GET", room_photo_path,
                                                 {HTTP_200_OK})
    return photo_response
Esempio n. 26
0
async def delete_guest_rating(
        user_id: int,
        rating_id: int,
        uuid: int = Depends(get_uuid_from_xtoken),
):
    rating_path = f"/users/{user_id}/guest_ratings/{rating_id}"
    if not AuthSender.has_permission_to_modify(uuid, user_id):
        raise UnauthorizedRequestError(
            "You can't delete a rating of another user")

    review, _ = Requester.user_srv_fetch(method="DELETE",
                                         path=rating_path,
                                         expected_statuses={HTTP_200_OK})
    return review
Esempio n. 27
0
async def update_profile_photo(
        _response: Response,
        file: UploadFile = File(...),
        uuid: int = Depends(get_uuid_from_xtoken),
):
    image_url = photouploader.upload_profile_photo(file, uuid)

    user_patch = {"photo": image_url}
    user_profile_path = f"/users/{uuid}"
    user_response, _ = Requester.user_srv_fetch("PATCH",
                                                user_profile_path,
                                                {HTTP_200_OK},
                                                payload=user_patch)

    return user_response
Esempio n. 28
0
async def send_message(
        _reponse: Response,
        payload: MessageSchema,
        other_uuid: int,
        uuid: int = Depends(get_uuid_from_xtoken),
):
    path = f"/users/{uuid}"
    me, _ = Requester.user_srv_fetch(method="GET",
                                     path=path,
                                     expected_statuses={HTTP_200_OK})

    path = f"/users/{other_uuid}"
    other, _ = Requester.user_srv_fetch(method="GET",
                                        path=path,
                                        expected_statuses={HTTP_200_OK})

    own_name = f"{me['firstname']} {me['lastname']}"
    other_name = f"{other['firstname']} {other['lastname']}"

    own_data = {"name": own_name, "uuid": uuid}
    other_data = {"name": other_name, "uuid": other_uuid}

    return chat_service.send_message(payload.dict()["message"], own_data,
                                     other_data)
Esempio n. 29
0
async def update_user(
        user_id: int,
        payload: UserUpdateSchema,
        uuid: int = Depends(get_uuid_from_xtoken),
):
    if not AuthSender.has_permission_to_modify(uuid, user_id):
        raise UnauthorizedRequestError(
            "You can't update info about other users")

    path = f"/users/{user_id}"
    new_user_info, _ = Requester.user_srv_fetch(
        method="PATCH",
        path=path,
        expected_statuses={HTTP_200_OK},
        payload=payload.dict(exclude_unset=True),
    )
    return new_user_info
Esempio n. 30
0
    def get_uuid_from_token(cls, token):
        # if not cls.url:
        #    cls._mock_get_info(int(token))
        #    return int(token)

        response, code = Requester.auth_srv_fetch(
            method="GET",
            path="/user/id",
            expected_statuses={HTTP_200_OK},
            payload={},
            extra_headers=cls.tkn_hdr(token),
        )
        logger.debug("Auth server get uuid response: %s, status_code: %s",
                     response, code)

        if code != 200:
            raise NotFoundError("User")

        logger.info("Obtained user uuid: %d", response["uuid"])
        return response["uuid"]