def handle_complaint(ses_message): recipient_email = remove_emails_from_complaint(ses_message)[0] current_app.logger.info("Complaint from SES: \n{}".format(ses_message)) try: reference = ses_message['mail']['messageId'] except KeyError as e: current_app.logger.exception( "Complaint from SES failed to get reference from message", e) return notification = dao_get_notification_history_by_reference(reference) ses_complaint = ses_message.get('complaint', None) complaint = Complaint( notification_id=notification.id, service_id=notification.service_id, # TODO: this ID is unique, we should make it a unique index so we don't # store duplicate complaints. # See https://docs.aws.amazon.com/ses/latest/DeveloperGuide/notification-contents.html#complaint-object ses_feedback_id=ses_complaint.get('feedbackId', None) if ses_complaint else None, complaint_type=ses_complaint.get('complaintFeedbackType', None) if ses_complaint else None, complaint_date=ses_complaint.get('timestamp', None) if ses_complaint else None) save_complaint(complaint) return complaint, notification, recipient_email
def handle_complaint(ses_message): recipient_email = remove_emails_from_complaint(ses_message)[0] current_app.logger.info("Complaint from SES: \n{}".format( json.dumps(ses_message).replace("{", "(").replace("}", ")"))) try: reference = ses_message["mail"]["messageId"] except KeyError as e: current_app.logger.exception( "Complaint from SES failed to get reference from message", e) return notification = dao_get_notification_history_by_reference(reference) ses_complaint = ses_message.get("complaint", None) complaint = Complaint( notification_id=notification.id, service_id=notification.service_id, ses_feedback_id=ses_complaint.get("feedbackId", None) if ses_complaint else None, complaint_type=ses_complaint.get("complaintFeedbackType", None) if ses_complaint else None, complaint_date=ses_complaint.get("timestamp", None) if ses_complaint else None, ) save_complaint(complaint) return complaint, notification, recipient_email
def handle_ses_complaint( ses_message: dict) -> Tuple[Complaint, Notification, str]: recipient_email = remove_emails_from_complaint(ses_message)[0] current_app.logger.info("Complaint from SES: \n{}".format( json.dumps(ses_message).replace('{', '(').replace('}', ')'))) try: reference = ses_message['mail']['messageId'] except KeyError as e: current_app.logger.exception( "Complaint from SES failed to get reference from message", e) return notification = dao_get_notification_history_by_reference(reference) ses_complaint = ses_message.get('complaint', None) complaint_type = ses_complaint.get('complaintFeedbackType', None) if ses_complaint else None if not complaint_type: current_app.logger.info( f'Received null complaint type from SES for notification {notification.id}' ) complaint = Complaint(notification_id=notification.id, service_id=notification.service_id, feedback_id=ses_complaint.get('feedbackId', None) if ses_complaint else None, complaint_type=complaint_type, complaint_date=ses_complaint.get('timestamp', None) if ses_complaint else None) save_complaint(complaint) return complaint, notification, recipient_email
def check_billable_units(notification_update): notification = dao_get_notification_history_by_reference( notification_update.reference) if int(notification_update.page_count) != notification.billable_units: msg = 'Notification with id {} has {} billable_units but DVLA says page count is {}'.format( notification.id, notification.billable_units, notification_update.page_count) try: raise DVLAException(msg) except DVLAException: current_app.logger.exception(msg)
def check_billable_units(notification_update): try: # This try except is necessary because in test keys and research mode does not create notification history. # Otherwise we could just search for the NotificationHistory object notification = dao_get_notification_by_reference(notification_update.reference) except NoResultFound: notification = dao_get_notification_history_by_reference(notification_update.reference) if int(notification_update.page_count) != notification.billable_units: msg = 'Notification with id {} had {} billable_units but a page count of {}'.format( notification.id, notification.billable_units, notification_update.page_count) current_app.logger.error(msg)
def handle_complaint(ses_message): recipient_email = remove_emails_from_complaint(ses_message)[0] current_app.logger.info("Complaint from SES: \n{}".format(ses_message)) try: reference = ses_message['mail']['messageId'] except KeyError as e: current_app.logger.exception( "Complaint from SES failed to get reference from message", e) return notification = dao_get_notification_history_by_reference(reference) ses_complaint = ses_message.get('complaint', None) complaint = Complaint( notification_id=notification.id, service_id=notification.service_id, ses_feedback_id=ses_complaint.get('feedbackId', None) if ses_complaint else None, complaint_type=ses_complaint.get('complaintFeedbackType', None) if ses_complaint else None, complaint_date=ses_complaint.get('timestamp', None) if ses_complaint else None) save_complaint(complaint) return complaint, notification, recipient_email