Skip to content

Commit

Permalink
feat: Receive user name instead of customer intent for new terms UI
Browse files Browse the repository at this point in the history
  • Loading branch information
calvin-codecov committed Jan 13, 2025
1 parent 5433cb3 commit 2a07b3a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
36 changes: 17 additions & 19 deletions codecov_auth/commands/owner/interactors/save_terms_agreement.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Optional
from typing import Any

from django.utils import timezone

Expand All @@ -11,30 +11,28 @@

@dataclass
class TermsAgreementInput:
business_email: Optional[str] = None
business_email: str
name: str
terms_agreement: bool = False
marketing_consent: bool = False
customer_intent: Optional[str] = None


class SaveTermsAgreementInteractor(BaseInteractor):
requires_service = False

def validate(self, input: TermsAgreementInput):
valid_customer_intents = ["Business", "BUSINESS", "Personal", "PERSONAL"]
if (
input.customer_intent
and input.customer_intent not in valid_customer_intents
):
raise ValidationError("Invalid customer intent provided")
def validate(self, input: dict) -> None:
if not self.current_user.business_email:
raise ValidationError("Business email is required")
if not self.current_user.name:
raise ValidationError("Name is required")
if not self.current_user.is_authenticated:
raise Unauthenticated()

def update_terms_agreement(self, input: TermsAgreementInput):
def update_terms_agreement(self, input: TermsAgreementInput) -> None:
self.current_user.terms_agreement = input.terms_agreement
self.current_user.terms_agreement_at = timezone.now()
self.current_user.customer_intent = input.customer_intent
self.current_user.email_opt_in = input.marketing_consent
self.current_user.name = input.name
self.current_user.save()

if input.business_email and input.business_email != "":
Expand All @@ -44,19 +42,19 @@ def update_terms_agreement(self, input: TermsAgreementInput):
if input.marketing_consent:
self.send_data_to_marketo()

def send_data_to_marketo(self):
def send_data_to_marketo(self) -> None:
event_data = {
"email": self.current_user.email,
}
AnalyticsService().opt_in_email(self.current_user.id, event_data)

@sync_to_async
def execute(self, input):
def execute(self, input: dict[str, Any]) -> None:
typed_input = TermsAgreementInput(
business_email=input.get("business_email"),
terms_agreement=input.get("terms_agreement"),
marketing_consent=input.get("marketing_consent"),
customer_intent=input.get("customer_intent"),
business_email=input.get("business_email", ""),
terms_agreement=input.get("terms_agreement", False),
marketing_consent=input.get("marketing_consent", False),
name=input.get("name", ""),
)
self.validate(typed_input)
self.validate(input)
return self.update_terms_agreement(typed_input)
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ type SaveTermsAgreementPayload {
}

input SaveTermsAgreementInput {
businessEmail: String
businessEmail: String!
termsAgreement: Boolean!
marketingConsent: Boolean
customerIntent: String
name: String!
}
1 change: 1 addition & 0 deletions graphql_api/types/user/user.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ type User {
student: Boolean!
studentCreatedAt: DateTime
studentUpdatedAt: DateTime
# this will no longer be updated from the UI with Appless
customerIntent: String
}
1 change: 1 addition & 0 deletions graphql_api/types/user/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def resolve_student_updated_at(user: Owner, info) -> Optional[datetime]:
return user.student_updated_at


# this will no longer be updated from the UI
@user_bindable.field("customerIntent")
def resolve_customer_intent(user: Owner, info) -> str:
owner = user
Expand Down

0 comments on commit 2a07b3a

Please sign in to comment.