Skip to content

Commit 5fac5f0

Browse files
committed
feature to send abandoned project mail
1 parent 0e1112f commit 5fac5f0

File tree

7 files changed

+77
-2
lines changed

7 files changed

+77
-2
lines changed

readthedocs/projects/forms.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,16 @@ def clean_name(self):
114114
name = self.cleaned_data.get('name', '')
115115
if not self.instance.pk:
116116
potential_slug = slugify(name)
117-
if Project.objects.filter(slug=potential_slug).exists():
117+
project_exist = Project.objects.filter(slug=potential_slug).exists()
118+
if project_exist:
119+
project = Project.objects.get(slug=potential_slug)
120+
for user in project.users.all():
121+
if user.is_superuser:
122+
email = user.email
123+
if project.is_abandoned:
124+
self.fields['abandon'] = forms.CharField(widget=forms.HiddenInput())
125+
self.fields['mail_id'] = forms.EmailField(initial=email, widget=forms.HiddenInput())
126+
self.fields['proj_name'] = forms.CharField(initial=name, widget=forms.HiddenInput())
118127
raise forms.ValidationError(
119128
_('Invalid project name, a project already exists with that name')) # yapf: disable # noqa
120129
return name

readthedocs/projects/models.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import logging
99
import os
1010
from builtins import object # pylint: disable=redefined-builtin
11+
from datetime import datetime
1112

1213
from django.conf import settings
1314
from django.contrib.auth.models import User
@@ -558,6 +559,22 @@ def conf_dir(self, version=LATEST):
558559
if conf_file:
559560
return os.path.dirname(conf_file)
560561

562+
@property
563+
def is_abandoned(self):
564+
"""Is project abandoned."""
565+
if self.has_good_build:
566+
latest_build = self.get_latest_build()
567+
if latest_build:
568+
latest_build_date = latest_build.date
569+
today = datetime.today()
570+
diff = today - latest_build_date
571+
# Latest build a year ago.
572+
if diff > 365:
573+
return True
574+
return False
575+
return False
576+
return True
577+
561578
@property
562579
def is_type_sphinx(self):
563580
"""Is project type Sphinx."""

readthedocs/projects/urls/private.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@
103103
url(r'^(?P<project_slug>[-\w]+)/advertising/$',
104104
ProjectAdvertisingUpdate.as_view(),
105105
name='projects_advertising'),
106+
107+
url(r'^import/manual/send_mail/$',
108+
private.send_mail,
109+
name='send_mail'),
106110
]
107111

108112
domain_urls = [

readthedocs/projects/views/private.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from readthedocs.builds.forms import AliasForm, VersionForm
2727
from readthedocs.builds.models import Version, VersionAlias
2828
from readthedocs.core.mixins import ListViewWithForm, LoginRequiredMixin
29-
from readthedocs.core.utils import broadcast, trigger_build
29+
from readthedocs.core.utils import broadcast, trigger_build, send_email
3030
from readthedocs.integrations.models import HttpExchange, Integration
3131
from readthedocs.oauth.services import registry
3232
from readthedocs.oauth.utils import attach_webhook, update_webhook
@@ -264,6 +264,22 @@ def is_advanced(self):
264264
return data.get('advanced', True)
265265

266266

267+
def send_mail(request):
268+
"""Sends abandoned project email."""
269+
email = request.POST.get('mail_id')
270+
proj_name = request.POST.get('proj_name')
271+
context = {'proj_name': proj_name}
272+
subject = 'Rename request for abandoned project'
273+
send_email(
274+
recipient=email,
275+
subject=subject,
276+
template='projects/email/abandon_project.txt',
277+
template_html='projects/email/abandon_project.html',
278+
context=context)
279+
messages.success(request, _('Mail sent!'))
280+
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
281+
282+
267283
class ImportDemoView(PrivateViewMixin, View):
268284

269285
"""View to pass request on to import form to import demo project."""
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% extends "core/email/common.html" %}
2+
3+
{% load i18n %}
4+
5+
{% block content %}
6+
<p>
7+
We've had a request from one of our users for the project name {{proj_name}} on Read the Docs. You are the current owner, and we wanted to reach out to you in accordance with our Abandoned Project policy (http://docs.readthedocs.io/en/latest/abandoned-projects.html).
8+
</p>
9+
10+
<p>
11+
Please reply at [email protected] either allowing or disallowing the transfer of the name on Read the Docs within 6 weeks, otherwise we will take the action of *initiating the transfer to a new owner* by default.
12+
</p>
13+
{% endblock %}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% extends "core/email/common.txt" %}
2+
3+
{% load i18n %}
4+
5+
{% block content %}
6+
We've had a request from one of our users for the project name {{proj_name}} on Read the Docs. You are the current owner, and we wanted to reach out to you in accordance with our Abandoned Project policy (http://docs.readthedocs.io/en/latest/abandoned-projects.html).
7+
8+
Please reply at [email protected] either allowing or disallowing the transfer of the name on Read the Docs within 6 weeks, otherwise we will take the action of *initiating the transfer to a new owner* by default.
9+
{% endblock %}

readthedocs/templates/projects/import_base.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55

66
{% block content %}
77
<div class="module wizard wizard-project">
8+
{% if wizard.form.fields.abandon %}
9+
<form action="{% url "send_mail" %}" method="post">
10+
{% csrf_token %}
11+
<input type="hidden" name="mail_id" value="{{ wizard.form.fields.mail_id.initial }}">
12+
<input type="hidden" name="proj_name" value="{{ wizard.form.fields.proj_name.initial }}">
13+
<input type="submit" name="submit-btn" value="{% trans "Email project owner with our abandoned project email" %}">
14+
{% endif %}
815
<form action="{% url "projects_import_manual" %}" method="post">
916

1017
{% csrf_token %}

0 commit comments

Comments
 (0)