From dd0598a4dd6441e4d7f4536d6f9694402cc97e40 Mon Sep 17 00:00:00 2001 From: Carlos Quintana <74399022+cquintana92@users.noreply.github.com> Date: Tue, 28 Jun 2022 11:57:21 +0200 Subject: [PATCH] Send welcome email when user created by login with proton (#1115) * Send welcome email when user created by login with proton * Add dedicated test to user.created_by_partner --- app/account_linking.py | 5 ++++- app/models.py | 6 ++++++ tests/models/test_user.py | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/account_linking.py b/app/account_linking.py index f886453d..754dd12f 100644 --- a/app/account_linking.py +++ b/app/account_linking.py @@ -9,7 +9,7 @@ from typing import Optional from app import config from app.db import Session -from app.email_utils import send_email_at_most_times, render +from app.email_utils import send_email_at_most_times, send_welcome_email, render from app.errors import AccountAlreadyLinkedToAnotherPartnerException from app.log import LOG from app.models import ( @@ -182,6 +182,9 @@ class NewUserStrategy(ClientMergeStrategy): ) Session.commit() + if not new_user.created_by_partner: + send_welcome_email(new_user) + agent.record_custom_event("PartnerUserCreation", {"partner": self.partner.name}) return LinkResult( diff --git a/app/models.py b/app/models.py index b63dc7ac..bd8812b8 100644 --- a/app/models.py +++ b/app/models.py @@ -525,6 +525,12 @@ class User(Base, ModelMixin, UserMixin, PasswordOracle): - CustomDomain.filter_by(user_id=self.id, is_sl_subdomain=True).count(), ) + @property + def created_by_partner(self): + return User.FLAG_CREATED_FROM_PARTNER == ( + self.flags & User.FLAG_CREATED_FROM_PARTNER + ) + @staticmethod def subdomain_is_available(): return SLDomain.filter_by(can_use_subdomain=True).count() > 0 diff --git a/tests/models/test_user.py b/tests/models/test_user.py index 98b9d85c..3e39804f 100644 --- a/tests/models/test_user.py +++ b/tests/models/test_user.py @@ -21,3 +21,11 @@ def test_create_from_partner(flask_client): assert job is not None assert job.name == config.JOB_SEND_PROTON_WELCOME_1 assert job.payload.get("user_id") == user.id + + +def test_user_created_by_partner(flask_client): + user_from_partner = User.create(email=random_email(), from_partner=True) + assert user_from_partner.created_by_partner is True + + regular_user = User.create(email=random_email()) + assert regular_user.created_by_partner is False