Skip to content

Commit

Permalink
fix: Remove tos input defaults and separate out more new vs deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
calvin-codecov committed Jan 16, 2025
1 parent 7bc85a9 commit ace77db
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions codecov_auth/commands/owner/interactors/save_terms_agreement.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,25 @@ def validate(self, input: TermsAgreementInput) -> None:
if not self.current_user.is_authenticated:
raise Unauthenticated()

def update_terms_agreement(self, input: TermsAgreementInput) -> None:
def update_terms_agreement_deprecated(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.save()

if input.business_email and input.business_email != "":
self.current_user.email = input.business_email
self.current_user.save()

if input.marketing_consent:
self.send_data_to_marketo()

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.name = input.name
self.current_user.email_opt_in = input.marketing_consent
self.current_user.save()

if input.business_email and input.business_email != "":
Expand All @@ -61,15 +75,22 @@ def send_data_to_marketo(self) -> None:

@sync_to_async
def execute(self, input: Any) -> None:
typed_input = TermsAgreementInput(
business_email=input.get("business_email", ""),
terms_agreement=input.get("terms_agreement", False),
marketing_consent=input.get("marketing_consent", False),
customer_intent=input.get("customer_intent"),
name=input.get("name", ""),
)
if input.get("customer_intent"):
self.validate_deprecated(typed_input)
else:
if input.get("name"):
typed_input = TermsAgreementInput(
business_email=input.get("business_email"),
terms_agreement=input.get("terms_agreement"),
marketing_consent=input.get("marketing_consent"),
name=input.get("name", ""),
)
self.validate(typed_input)
return self.update_terms_agreement(typed_input)
self.update_terms_agreement(typed_input)
# this handles the deprecated inputs
else:
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"),
)
self.validate_deprecated(typed_input)
self.update_terms_agreement_deprecated(typed_input)

0 comments on commit ace77db

Please sign in to comment.