Skip to content

Added feature for sending abandoned project mail #3722

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 13 additions & 1 deletion readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,19 @@ def clean_name(self):
name = self.cleaned_data.get('name', '')
if not self.instance.pk:
potential_slug = slugify(name)
if Project.objects.filter(slug=potential_slug).exists():
project_exist = Project.objects.filter(slug=potential_slug).exists()
if project_exist:
project = Project.objects.get(slug=potential_slug)
for user in project.users.all():
if user.is_superuser:
email = user.email
if project.is_abandoned:
self.fields['abandon'] = forms.CharField(
widget=forms.HiddenInput())
self.fields['mail_id'] = forms.EmailField(
initial=email, widget=forms.HiddenInput())
self.fields['proj_name'] = forms.CharField(
initial=name, widget=forms.HiddenInput())
raise forms.ValidationError(
_('Invalid project name, a project already exists with that name')) # yapf: disable # noqa
return name
Expand Down
17 changes: 17 additions & 0 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import os
from builtins import object # pylint: disable=redefined-builtin
from datetime import datetime

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

@property
def is_abandoned(self):
"""Is project abandoned."""
if self.has_good_build:
latest_build = self.get_latest_build()
if latest_build:
latest_build_date = latest_build.date
today = datetime.today()
diff = today - latest_build_date
# Latest build a year ago.
if diff > 365:
return True
return False
return False
return True

@property
def is_type_sphinx(self):
"""Is project type Sphinx."""
Expand Down
4 changes: 4 additions & 0 deletions readthedocs/projects/urls/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@
url(r'^(?P<project_slug>[-\w]+)/advertising/$',
ProjectAdvertisingUpdate.as_view(),
name='projects_advertising'),

url(r'^import/manual/send_mail/$',
Copy link
Member

@stsewd stsewd Mar 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this should live on the project import page. I mean in general, not just the url.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I do like this hint when the project name is already taken

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you suggest something if we do not want this to stay on project import page ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe showing this on the project page that is abandoned (only for logged users, of course). And a link to that project on the import page if the name is already taken by an abandoned project. Just a personal suggestion anyway, I'm don't know if the core maintainers want to go in that direction here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also some tests for the is_abandoned property would be awesome.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @stsewd , Shall I make the changes for displaying the option of sending mail as suggested by you ?
Also can you please elaborate on the tests which will help reduce false results on the is_abandoned property.
Thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what Eric said

I think we should keep it light weight in terms of implementation so this isn't a lot to maintain. Perhaps just an admin-only button that says "email project owner with our abandoned project email" as a start, which sends an email from a template that we have in the repo.

I think this button must be only shown to admins (rtd admins) and probably should be on the project page.

About the tests, you can create a project with different scenarios like failed build but not too old, too old but with successful build, etc. Probably the tests should live on this file https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/rtd_tests/tests/test_project.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay Got it !
Thank you

private.send_mail,
name='send_mail'),
]

domain_urls = [
Expand Down
18 changes: 17 additions & 1 deletion readthedocs/projects/views/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from readthedocs.builds.forms import AliasForm, VersionForm
from readthedocs.builds.models import Version, VersionAlias
from readthedocs.core.mixins import ListViewWithForm, LoginRequiredMixin
from readthedocs.core.utils import broadcast, trigger_build
from readthedocs.core.utils import broadcast, trigger_build, send_email
from readthedocs.integrations.models import HttpExchange, Integration
from readthedocs.oauth.services import registry
from readthedocs.oauth.utils import attach_webhook, update_webhook
Expand Down Expand Up @@ -264,6 +264,22 @@ def is_advanced(self):
return data.get('advanced', True)


def send_mail(request):
"""Sends abandoned project email."""
email = request.POST.get('mail_id')
proj_name = request.POST.get('proj_name')
context = {'proj_name': proj_name}
subject = 'Rename request for abandoned project'
send_email(
recipient=email,
subject=subject,
template='projects/email/abandon_project.txt',
template_html='projects/email/abandon_project.html',
context=context)
messages.success(request, _('Mail sent!'))
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))


class ImportDemoView(PrivateViewMixin, View):

"""View to pass request on to import form to import demo project."""
Expand Down
13 changes: 13 additions & 0 deletions readthedocs/templates/projects/email/abandon_project.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "core/email/common.html" %}

{% load i18n %}

{% block content %}
<p>
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).
</p>

<p>
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.
</p>
{% endblock %}
9 changes: 9 additions & 0 deletions readthedocs/templates/projects/email/abandon_project.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "core/email/common.txt" %}

{% load i18n %}

{% block content %}
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).

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.
{% endblock %}
7 changes: 7 additions & 0 deletions readthedocs/templates/projects/import_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

{% block content %}
<div class="module wizard wizard-project">
{% if wizard.form.fields.abandon %}
<form action="{% url "send_mail" %}" method="post">
{% csrf_token %}
<input type="hidden" name="mail_id" value="{{ wizard.form.fields.mail_id.initial }}">
<input type="hidden" name="proj_name" value="{{ wizard.form.fields.proj_name.initial }}">
<input type="submit" name="submit-btn" value="{% trans "Email project owner with our abandoned project email" %}">
{% endif %}
<form action="{% url "projects_import_manual" %}" method="post">

{% csrf_token %}
Expand Down