def promote_member(user: _User, source: str) -> _User: """ Promote a user to Member role and change it's role on Email Marketing. Will not fail in case API call fails. Email welcome email is sent to user :param source: source of traffic :param user: :return: """ _core_facade.promote_to_member(user, source) _cohorts_facade.subscribe_to_last_cohort(user) cohort = _cohorts_facade.find_most_recent_cohort() sync_user_on_discourse(user) try: _email_marketing_facade.create_or_update_member(user.first_name, user.email, id=user.id) _email_marketing_facade.tag_as(user.email, user.id, f'turma-{cohort.slug}') except _ActiveCampaignError: pass email_msg = render_to_string( 'payments/membership_email.txt', { 'user': user, 'cohort_detail_url': build_absolute_uri(cohort.get_absolute_url()) }) _send_mail( f'Inscrição na Turma {cohort.title} realizada! Confira o link com detalhes.', email_msg, _settings.DEFAULT_FROM_EMAIL, [user.email]) return user
def test_member_creation_user_not_found(resps_user_not_found, grant_role_mock): facade.create_or_update_member('Renzo Nuccitelli', '*****@*****.**', 'turma', id=1) grant_role_mock.assert_called_once_with('*****@*****.**', '0000000001', 'member')
def force_register_member(first_name, email, source='unknown'): """ Create a new user on the system generation a random password or update existing one based on email. An Welcome email is sent to the user informing his password with the link to change it. User is also registered on Mailchimp. But she will be registered even if api call fails :param first_name: User's first name :param email: User's email :param source: source of User traffic :return: User """ user = _core_facade.register_member(first_name, email, source) _cohorts_facade.subscribe_to_last_cohort(user) cohort = _cohorts_facade.find_most_recent_cohort() sync_user_on_discourse(user) try: _email_marketing_facade.create_or_update_member(first_name, email, id=user.id) _email_marketing_facade.tag_as(email, user.id, f'turma-{cohort.slug}') except _ActiveCampaignError: pass return user