Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/backend/src/couchers/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"hosting_status_required": "Hosting status is required.",
"incomplete_profile_create_event": "You have to complete your profile before you can create an event.",
"incomplete_profile_create_public_trip": "You have to complete your profile before you can create a public trip.",
"incomplete_profile_send_friend_request": "You have to complete your profile before you can send a friend request.",
"incomplete_profile_send_message": "You have to complete your profile before you can send a message.",
"incomplete_profile_send_request": "You have to complete your profile before you can send a request.",
"insecure_password": "The password is insecure. Please use one that is not easily guessable.",
Expand Down
4 changes: 4 additions & 0 deletions app/backend/src/couchers/servicers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from couchers.context import CouchersContext
from couchers.crypto import b64encode, generate_hash_signature, random_hex
from couchers.event_log import log_event
from couchers.helpers.completed_profile import has_completed_profile
from couchers.helpers.strong_verification import get_strong_verification_fields
from couchers.materialized_views import LiteUser, UserResponseRate
from couchers.models import (
Expand Down Expand Up @@ -722,6 +723,9 @@ def SendFriendRequest(
context.abort_with_error_code(grpc.StatusCode.FAILED_PRECONDITION, "cant_friend_self")

user = session.execute(select(User).where(User.id == context.user_id)).scalar_one()
if not has_completed_profile(session, user):
context.abort_with_error_code(grpc.StatusCode.FAILED_PRECONDITION, "incomplete_profile_send_friend_request")

to_user = session.execute(
select(User).where(users_visible(context)).where(User.id == request.user_id)
).scalar_one_or_none()
Expand Down
15 changes: 15 additions & 0 deletions app/backend/src/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,21 @@ def test_cant_friend_request_already_friends(db):
assert e.value.details() == "You are already friends with or have sent a friend request to that user."


def test_cant_friend_request_incomplete_profile(db):
user1, token1 = generate_user(complete_profile=False)
user2, token2 = generate_user(complete_profile=True)

with api_session(token1) as api:
with pytest.raises(grpc.RpcError) as e:
api.SendFriendRequest(api_pb2.SendFriendRequestReq(user_id=user2.id))
assert e.value.code() == grpc.StatusCode.FAILED_PRECONDITION
assert e.value.details() == "You have to complete your profile before you can send a friend request."

# the other direction should still work
with api_session(token2) as api:
api.SendFriendRequest(api_pb2.SendFriendRequestReq(user_id=user1.id))


def test_excessive_friend_requests_are_reported(db):
"""Test that excessive friend requests are first reported in a warning email and finally lead blocking of further requests."""
user, token = generate_user()
Expand Down
Loading