Coverage for src/couchers/servicers/reporting.py: 100%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import grpc
2from google.protobuf import empty_pb2
4from couchers import errors
5from couchers.db import session_scope
6from couchers.models import ContentReport, User
7from couchers.sql import couchers_select as select
8from couchers.tasks import send_content_report_email
9from proto import reporting_pb2_grpc
12class Reporting(reporting_pb2_grpc.ReportingServicer):
13 def Report(self, request, context):
14 with session_scope() as session:
15 # note no filtering on visibility
16 author_user = session.execute(select(User).where_username_or_id(request.author_user)).scalar_one_or_none()
18 if not author_user:
19 context.abort(grpc.StatusCode.NOT_FOUND, errors.USER_NOT_FOUND)
21 content_report = ContentReport(
22 reporting_user_id=context.user_id,
23 reason=request.reason,
24 description=request.description,
25 content_ref=request.content_ref,
26 author_user=author_user,
27 user_agent=request.user_agent,
28 page=request.page,
29 )
31 session.add(content_report)
32 session.flush()
34 send_content_report_email(content_report)
36 return empty_pb2.Empty()