-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
readthedocs/projects/forms.py
Outdated
if not has_good_build: | ||
latest_build_date = project.get_latest_build().date | ||
today = datetime.today() | ||
diff = ((today.year - latest_build_date.year) * 12 + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is better if you use timedelta
for date operations
readthedocs/projects/forms.py
Outdated
@@ -114,7 +116,25 @@ def clean_name(self): | |||
name = self.cleaned_data.get('name', '') | |||
if not self.instance.pk: | |||
potential_slug = slugify(name) | |||
project = Project.objects.get(slug=potential_slug) | |||
for user in project.users.all(): | |||
if user.is_superuser == True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be just
if user.is_superuser:
...
Can you add a screenshot of how this looks? Also, I think it's better if you put a property to the |
@stsewd Here is a screenshot: Also, I have added the |
1fe2e29
to
1b4f62f
Compare
@ericholscher @stsewd I have added a feature for sending mail to the owner of abandoned projects when renaming is required. If a user enters a name which is already used and the project is abandoned, a button is displayed on top to send mail. If the user clicks on the button mail will be sent to the owner and user will be redirected to the import page with a |
5fac5f0
to
8c850a9
Compare
8c850a9
to
bb6e9b7
Compare
readthedocs/projects/urls/private.py
Outdated
@@ -103,6 +103,10 @@ | |||
url(r'^(?P<project_slug>[-\w]+)/advertising/$', | |||
ProjectAdvertisingUpdate.as_view(), | |||
name='projects_advertising'), | |||
|
|||
url(r'^import/manual/send_mail/$', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
c2dd6d7
to
afc6d25
Compare
afc6d25
to
91bb197
Compare
@stsewd How to run the tests locally ? I was writing the tests as said by you but was not able to run them locally. |
@bansalnitish You can check https://docs.readthedocs.io/en/latest/tests.html, let me know if something isn't clear. |
91bb197
to
38ef44d
Compare
Hi @stsewd, I have written the tests. Can you please have a look and suggest improvements! |
<input type="submit" name="submit-btn" value="{% trans "Email project owner with our abandoned project email" %}"/> | ||
</form> | ||
{% else %} | ||
<p><strong>{%trans "Abandonment mail is sent to the owner of the project." %}</strong></p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was sent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
proj_name = project_slug | ||
for user in project.users.all(): | ||
if AdminPermission.is_admin(user, project): | ||
email = user.email |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be done on another way (not sure how we can decide to which owner send the email)? Probably a break
is needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I think this is insecure, since any logged in user can send a request here, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this button to be visible only to a superuser in the html template. Does that look fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I have added a break
statement. Should the mail be sent to a list of all users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but any user could do a manual request, so probably is worth to check for the superuser here. I'm not sure what is the best way of do it anyway, probably the required_login
decorator accepts a argument or there is a super_user_only
decorator?
Maybe @humitos can help us here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure @stsewd! Thanks 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stsewd I tested this on my local instance and it works as expected!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ericholscher Can you please guide me here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it is checking for project owners who are admins. We just want to send the email to all project owners, but only let admins do it. We should be doing a request.user.is_superuser
or similar check to determine if the logged in user is an admin, and then send the email to all project owners.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The button for sending mail is only visible to the admins i.e. I have done a request.user.is_superuser
check in the html template. Also, we can check for superuser using a decorator like this: https://stackoverflow.com/questions/12003736/django-login-required-decorator-for-a-superuser. Does that look fine @ericholscher?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a great change! I had a few small pieces of feedback, which need to be updated before we ship it, but I think this is close!
readthedocs/projects/forms.py
Outdated
project_url = project.get_absolute_url() | ||
if project.is_abandoned: | ||
err_msg = ('Invalid project name, a <a href="{}" style="color: red">' | ||
'project</a> already exists with that name').format(project_url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to check for abandoned, we should just always link to the project here.
readthedocs/projects/models.py
Outdated
@property | ||
def is_abandoned_mail_sent(self): | ||
"""Is abandoned mail sent.""" | ||
return self.abandoned_mail_sent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this is necessary, you can just use obj.abandoned_mail_sent
directly.
readthedocs/projects/urls/private.py
Outdated
@@ -36,6 +36,10 @@ | |||
private.project_manage, | |||
name='projects_manage'), | |||
|
|||
url(r'^(?P<project_slug>[-\w]+)/send_mail/$', | |||
private.send_mail, | |||
name='send_mail'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have a more explicit name & URL, send_abandoned_mail
or similar
proj_name = project_slug | ||
for user in project.users.all(): | ||
if AdminPermission.is_admin(user, project): | ||
email = user.email |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it is checking for project owners who are admins. We just want to send the email to all project owners, but only let admins do it. We should be doing a request.user.is_superuser
or similar check to determine if the logged in user is an admin, and then send the email to all project owners.
Hi, @ericholscher I have made the requested changes. Can you have a look once! |
015d82f
to
1274c8f
Compare
1274c8f
to
8e2f573
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started reviewing this, but I suppose I don't agree with the underlying ticket or with this feature addition. I do have specific feedback on the implementation, but I think we need to step back from this feature first. This UI will actually never be shown, as a user still needs to contact us to start the process of determining that a project is abandoned. Once that process happens, the reporting user will be assigned the namespace. So I think we're solving the wrong problem here.
There are pieces here that I think we can use, but i don't think we've well defined exactly what we want here yet.
I'm going to block on this review for now while I raise some thoughts in the underlying issue.
As per feedback in #3382, I'm closing this. The branch will still be available for reference if needed. |
Fixes #3382
@ericholscher I have added a button which is displayed when a project meets abandon policy and a user wants to use the name of the project. I am working on linking the button to send an email when it is clicked.