Skip to content

Commit

Permalink
Log letter create, send, download events from backend (#2400)
Browse files Browse the repository at this point in the history
  • Loading branch information
shakao authored Oct 3, 2022
1 parent 47eb2f8 commit 3060136
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion common-data/amplitude-logged-event-choices.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[
["SAFE_MODE_ENABLE", "Enable compatibility mode"],
["SAFE_MODE_DISABLE", "Disable compatibility mode"]
["SAFE_MODE_DISABLE", "Disable compatibility mode"],
["LATENANTS_LETTER_CREATE", "LA TAC create letter"],
["LATENANTS_LETTER_SEND", "LA TAC send letter"],
["LATENANTS_LETTER_DOWNLOAD", "LA TAC download letter"]
]
12 changes: 12 additions & 0 deletions laletterbuilder/schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, Dict, List
from django.http import HttpRequest
from django.db import transaction
from amplitude.models import LoggedEvent
from laletterbuilder import letter_sending, models
from onboarding.scaffolding import purge_scaffolding
from onboarding.schema import complete_onboarding
Expand Down Expand Up @@ -139,6 +140,9 @@ def perform_mutate(cls, form, info: ResolveInfo):
info, "This form can only be used from the LA Letter Builder site."
)
letter_sending.create_letter(user)
LoggedEvent.objects.create_for_request(
request, kind=LoggedEvent.CHOICES.LATENANTS_LETTER_CREATE
)

return cls.mutation_success()

Expand Down Expand Up @@ -177,6 +181,9 @@ def perform_mutate(cls, form, info: ResolveInfo):
user=request.user, letter_sent_at=None, letter_emailed_at=None, fully_processed_at=None
)
letter_sending.send_letter(letter)
LoggedEvent.objects.create_for_request(
request, kind=LoggedEvent.CHOICES.LATENANTS_LETTER_SEND
)

return cls.mutation_success()

Expand Down Expand Up @@ -296,6 +303,8 @@ def resolve(cls, parent, info: ResolveInfo):
@classmethod
@mutation_requires_onboarding
def perform_mutate(cls, form, info: ResolveInfo):
request = info.context

with transaction.atomic():
user = info.context.user
letter_id = form.cleaned_data["letter_id"]
Expand All @@ -314,6 +323,9 @@ def perform_mutate(cls, form, info: ResolveInfo):
f"Could not find PDF bytes for letter with id {letter_id}. \
Has the letter been fully processed?"
)
LoggedEvent.objects.create_for_request(
request, kind=LoggedEvent.CHOICES.LATENANTS_LETTER_DOWNLOAD
)
return cls.mutation_success(pdf_base64=letter.pdf_base64)


Expand Down

0 comments on commit 3060136

Please sign in to comment.