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