Skip to content

Commit 242641b

Browse files
authored
Deprecation: opt-out from config file email (#10440)
* Deprecation: opt-out from config file email This is the minimal version without spending too much time. If we are fine with this, we can merge it for now and grow from here. It does not look too complex, to keep or to remove it later :) * Make the field nullable * Update text from the email to mention opt-out * Minor copy feedback
1 parent 187e698 commit 242641b

File tree

7 files changed

+70
-9
lines changed

7 files changed

+70
-9
lines changed

readthedocs/core/forms.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Forms for core app."""
22

33
import structlog
4-
4+
from crispy_forms.helper import FormHelper
5+
from crispy_forms.layout import Fieldset, Layout, Submit
56
from django import forms
67
from django.contrib.auth.models import User
78
from django.forms.fields import CharField
@@ -21,7 +22,12 @@ class UserProfileForm(forms.ModelForm):
2122
class Meta:
2223
model = UserProfile
2324
# Don't allow users edit someone else's user page
24-
fields = ['first_name', 'last_name', 'homepage']
25+
profile_fields = ["first_name", "last_name", "homepage"]
26+
optout_email_fields = ["optout_email_config_file_deprecation"]
27+
fields = (
28+
*profile_fields,
29+
*optout_email_fields,
30+
)
2531

2632
def __init__(self, *args, **kwargs):
2733
super().__init__(*args, **kwargs)
@@ -31,6 +37,20 @@ def __init__(self, *args, **kwargs):
3137
except AttributeError:
3238
pass
3339

40+
self.helper = FormHelper()
41+
field_sets = [
42+
Fieldset(
43+
_("User settings"),
44+
*self.Meta.profile_fields,
45+
),
46+
Fieldset(
47+
_("Email settings"),
48+
*self.Meta.optout_email_fields,
49+
),
50+
]
51+
self.helper.layout = Layout(*field_sets)
52+
self.helper.add_input(Submit("save", _("Save")))
53+
3454
def save(self, commit=True):
3555
first_name = self.cleaned_data.pop('first_name', None)
3656
last_name = self.cleaned_data.pop('last_name', None)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Generated by Django 3.2.19 on 2023-06-14 17:17
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("core", "0012_add_newsletter_setting"),
9+
]
10+
11+
operations = [
12+
migrations.AddField(
13+
model_name="historicaluserprofile",
14+
name="optout_email_config_file_deprecation",
15+
field=models.BooleanField(
16+
default=False,
17+
null=True,
18+
verbose_name="Opt-out from email about 'Config file deprecation'",
19+
),
20+
),
21+
migrations.AddField(
22+
model_name="userprofile",
23+
name="optout_email_config_file_deprecation",
24+
field=models.BooleanField(
25+
default=False,
26+
null=True,
27+
verbose_name="Opt-out from email about 'Config file deprecation'",
28+
),
29+
),
30+
]

readthedocs/core/models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ class UserProfile(TimeStampedModel):
4343
whitelisted = models.BooleanField(_("Whitelisted"), default=False)
4444
banned = models.BooleanField(_("Banned"), default=False)
4545

46+
# Opt-out on emails
47+
# NOTE: this is a temporary field that we can remove after September 25, 2023
48+
# See https://blog.readthedocs.com/migrate-configuration-v2/
49+
optout_email_config_file_deprecation = models.BooleanField(
50+
_("Opt-out from email about 'Config file deprecation'"),
51+
default=False,
52+
null=True,
53+
)
54+
4655
# Model history
4756
history = ExtraHistoricalRecords()
4857

readthedocs/projects/tasks/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,11 @@ def deprecated_config_file_used_notification():
269269
# Only send 1 email per user,
270270
# even if that user has multiple projects without a configuration file.
271271
# The notification will mention all the projects.
272-
queryset = User.objects.filter(username__in=users, profile__banned=False).order_by(
273-
"id"
274-
)
272+
queryset = User.objects.filter(
273+
username__in=users,
274+
profile__banned=False,
275+
profile__optout_email_config_file_deprecation=False,
276+
).order_by("id")
275277

276278
n_users = queryset.count()
277279
for i, user in enumerate(queryset.iterator()):
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% extends "profiles/base_profile_edit.html" %}
2+
{% load crispy_forms_tags %}
23

34
{% load i18n %}
45

@@ -9,8 +10,5 @@
910
{% block edit_content_header %} {% trans "Edit your profile" %} {% endblock %}
1011

1112
{% block edit_content %}
12-
<form method="POST" action=".">{% csrf_token %}
13-
{{ form.as_p }}
14-
<input type="submit" name="submit" value="{% trans "OK, save it!" %}" id="submit"/>
15-
</form>
13+
{% crispy form %}
1614
{% endblock %}

readthedocs/templates/projects/notifications/deprecated_config_file_used_email.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
</ul>
2626

2727
Please add a configuration file to your projects to ensure that they continue building successfully and to stop receiving these notifications.
28+
If you want to opt-out from these emails, you can <a href="https://readthedocs.org/accounts/edit/"> edit your preferences in your account settings</a>.
2829

2930
For more information on how to create a required configuration file,
3031
<a href="https://blog.readthedocs.com/migrate-configuration-v2/">read our blog post</a>

readthedocs/templates/projects/notifications/deprecated_config_file_used_email.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ We have identified that the following projects which you maintain, and were buil
2121
{% endif %}
2222

2323
Please add a configuration file to your projects to ensure that they continue building successfully and to stop receiving these notifications.
24+
If you want to opt-out from these emails, you can edit your preferences in your account settings, at https://readthedocs.org/accounts/edit/.
2425

2526
For more information on how to create a required configuration file,
2627
read our blog post at https://blog.readthedocs.com/migrate-configuration-v2/

0 commit comments

Comments
 (0)