Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds mautic-dnc to settings and for account deletion #8975

Merged
merged 1 commit into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions app/marketing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@
from chartit import PivotChart, PivotDataPool
from dashboard.models import Activity, HackathonEvent, Profile, TokenApproval
from dashboard.utils import create_user_action, get_orgs_perms, is_valid_eth_address
from dashboard.views import mautic_proxy_backend
from gas.utils import recommend_min_gas_price_to_confirm_in_time
from git.utils import get_github_primary_email
from grants.models import Grant
from marketing.country_codes import COUNTRY_CODES, COUNTRY_NAMES, FLAG_API_LINK, FLAG_ERR_MSG, FLAG_SIZE, FLAG_STYLE
from marketing.mails import new_feedback
from marketing.models import AccountDeletionRequest, EmailSubscriber, Keyword, LeaderboardRank, UpcomingDate
from marketing.utils import delete_user_from_mailchimp, get_or_save_email_subscriber, validate_slack_integration
from marketing.utils import get_or_save_email_subscriber, validate_slack_integration
from quests.models import Quest
from retail.emails import ALL_EMAILS, render_new_bounty, render_nth_day_email_campaign
from retail.helpers import get_ip
Expand Down Expand Up @@ -283,6 +284,23 @@ def feedback_settings(request):
return TemplateResponse(request, 'settings/feedback.html', context)


def set_mautic_dnc(profile, es, form):
"""Places contact on the DNC list on mautic

Args:
profile (Profile): The user who is being unsubscribed
es (EmailSubscriber): The details of the subscription
form (dict): email_type: bool
"""
preferences = es.preferences.get('suppression_preferences', {})
# ensure contact is marked as DNC in mautic (this wont be in sync if the user unsubscribes by following the link in the email)
# todo: add a cronjob to keep this state in sync with mautic or place unsubscribe logic in django and include gitcoin.co links in emails
if bool(form['marketing']) == True and preferences['marketing'] == False:
mautic_proxy_backend('POST', f'contacts/{profile.mautic_id}/dnc/email/add', b'{"reason":3}')
elif bool(form['marketing']) == False and preferences['marketing'] == True:
mautic_proxy_backend('POST', f'contacts/{profile.mautic_id}/dnc/email/remove', b'{"reason":3}')


def email_settings(request, key):
"""Display email settings.

Expand Down Expand Up @@ -319,6 +337,8 @@ def email_settings(request, key):
es.email = email
unsubscribed_email_type = {}
unsubscribed_email_type[email_type] = True
if email_type == 'marketing':
set_mautic_dnc(profile, es, unsubscribed_email_type)
es.build_email_preferences(unsubscribed_email_type)
es = record_form_submission(request, es, 'email')
ip = get_ip(request)
Expand Down Expand Up @@ -364,6 +384,7 @@ def email_settings(request, key):
if key not in form.keys():
form[key] = False

set_mautic_dnc(profile, es, form)
es.build_email_preferences(form)
es = record_form_submission(request, es, 'email')
ip = get_ip(request)
Expand Down Expand Up @@ -564,7 +585,7 @@ def account_settings(request):
profile.save()

# remove email
delete_user_from_mailchimp(es.email)
mautic_proxy_backend('POST', f'contacts/{profile.mautic_id}/dnc/email/add', b'{"reason":3}')

if es:
es.delete()
Expand Down Expand Up @@ -643,7 +664,7 @@ def job_settings(request):
profile.save()

# remove email
delete_user_from_mailchimp(es.email)
mautic_proxy_backend('POST', f'contacts/{profile.mautic_id}/dnc/email/add', b'{"reason":3}')

if es:
es.delete()
Expand Down
12 changes: 9 additions & 3 deletions app/retail/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@
('mention', _('Mentions'), _('Only when other users mention you on posts')),
]

ALL_EMAILS = MARKETING_EMAILS + TRANSACTIONAL_EMAILS + NOTIFICATION_EMAILS

MAUTIC_EMAILS = [
('marketing', _('General Marketing Emails'), _('as it comes')),
]


ALL_EMAILS = MARKETING_EMAILS + TRANSACTIONAL_EMAILS + NOTIFICATION_EMAILS + MAUTIC_EMAILS


def premailer_transform(html):
Expand Down Expand Up @@ -699,7 +705,7 @@ def render_new_bounty(to_email, bounties, old_bounties, offset=3, quest_of_the_d
counter += 1
print(counter, time.time())
foo = render_to_string("emails/new_bounty.html", params)

print(counter, time.time())
response_html = premailer_transform(foo)
print(counter, time.time())
Expand Down Expand Up @@ -1588,7 +1594,7 @@ def bounty_feedback(request):
if to_fulfiller:
response_html, _ = render_bounty_feedback(bounty, 'fulfiller', fulfiller_previous_bounties)
return HttpResponse(response_html)

if to_funder:
response_html, _ = render_bounty_feedback(bounty, 'funder', funder_previous_bounties)
return HttpResponse(response_html)
Expand Down