Emit events on proton actions (#1089)
* Emit events on proton actions * Update app/account_linking.py Co-authored-by: Adrià Casajús <acasajus@users.noreply.github.com> * Update app/account_linking.py Co-authored-by: Adrià Casajús <acasajus@users.noreply.github.com> Co-authored-by: Adrià Casajús <acasajus@users.noreply.github.com>
This commit is contained in:
parent
cf5ff6fa23
commit
3b47e79fae
|
@ -2,6 +2,7 @@ from abc import ABC, abstractmethod
|
|||
from arrow import Arrow
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
from newrelic import agent
|
||||
from typing import Optional
|
||||
|
||||
from app.db import Session
|
||||
|
@ -44,6 +45,7 @@ def set_plan_for_partner_user(partner_user: PartnerUser, plan: SLPlan):
|
|||
f"Deleting partner_subscription [user_id={partner_user.user_id}] [partner_id={partner_user.partner_id}]"
|
||||
)
|
||||
PartnerSubscription.delete(sub.id)
|
||||
agent.record_custom_event("PlanChange", {"plan": "free"})
|
||||
else:
|
||||
if sub is None:
|
||||
LOG.i(
|
||||
|
@ -53,11 +55,16 @@ def set_plan_for_partner_user(partner_user: PartnerUser, plan: SLPlan):
|
|||
partner_user_id=partner_user.id,
|
||||
end_at=plan.expiration,
|
||||
)
|
||||
agent.record_custom_event("PlanChange", {"plan": "premium", "type": "new"})
|
||||
else:
|
||||
LOG.i(
|
||||
f"Updating partner_subscription [user_id={partner_user.user_id}] [partner_id={partner_user.partner_id}]"
|
||||
)
|
||||
sub.end_at = plan.expiration
|
||||
if sub.end_at != plan.expiration:
|
||||
LOG.i(
|
||||
f"Updating partner_subscription [user_id={partner_user.user_id}] [partner_id={partner_user.partner_id}]"
|
||||
)
|
||||
agent.record_custom_event(
|
||||
"PlanChange", {"plan": "premium", "type": "extension"}
|
||||
)
|
||||
sub.end_at = plan.expiration
|
||||
Session.commit()
|
||||
|
||||
|
||||
|
@ -130,6 +137,8 @@ class NewUserStrategy(ClientMergeStrategy):
|
|||
)
|
||||
Session.commit()
|
||||
|
||||
agent.record_custom_event("PartnerUserCreation", {"partner": self.partner.name})
|
||||
|
||||
return LinkResult(
|
||||
user=new_user,
|
||||
strategy=self.__class__.__name__,
|
||||
|
@ -200,6 +209,7 @@ def link_user(
|
|||
)
|
||||
set_plan_for_partner_user(partner_user, link_request.plan)
|
||||
|
||||
agent.record_custom_event("AccountLinked", {"partner": partner.name})
|
||||
Session.commit()
|
||||
return LinkResult(
|
||||
user=current_user,
|
||||
|
|
|
@ -11,6 +11,7 @@ from flask import (
|
|||
from flask_login import login_required, current_user
|
||||
from flask_wtf import FlaskForm
|
||||
from flask_wtf.file import FileField
|
||||
from newrelic import agent
|
||||
from typing import Optional
|
||||
from wtforms import StringField, validators
|
||||
from wtforms.fields.html5 import EmailField
|
||||
|
@ -443,11 +444,13 @@ def cancel_email_change():
|
|||
@dashboard_bp.route("/unlink_proton_account", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def unlink_proton_account():
|
||||
proton_partner = get_proton_partner()
|
||||
partner_user = PartnerUser.get_by(
|
||||
user_id=current_user.id, partner_id=get_proton_partner().id
|
||||
user_id=current_user.id, partner_id=proton_partner.id
|
||||
)
|
||||
if partner_user is not None:
|
||||
PartnerUser.delete(partner_user.id)
|
||||
Session.commit()
|
||||
flash("Your Proton account has been unlinked", "success")
|
||||
agent.record_custom_event("AccountUnlinked", {"partner": proton_partner.name})
|
||||
return redirect(url_for("dashboard.setting"))
|
||||
|
|
Loading…
Reference in New Issue