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

Conversation

bansalnitish
Copy link
Contributor

@bansalnitish bansalnitish commented Mar 2, 2018

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.

if not has_good_build:
latest_build_date = project.get_latest_build().date
today = datetime.today()
diff = ((today.year - latest_build_date.year) * 12 +
Copy link
Member

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

@@ -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:
Copy link
Member

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:
    ...

@stsewd
Copy link
Member

stsewd commented Mar 2, 2018

Can you add a screenshot of how this looks?

Also, I think it's better if you put a property to the project model, something like is_abandoned, so we can uses this on others part of the code.

@bansalnitish
Copy link
Contributor Author

bansalnitish commented Mar 2, 2018

@stsewd Here is a screenshot:


screenshot from 2018-03-03 21-57-29

Also, I have added the is_abandoned property to the project model itself!

@bansalnitish bansalnitish force-pushed the abandon-proj branch 4 times, most recently from 1fe2e29 to 1b4f62f Compare March 2, 2018 23:45
@bansalnitish bansalnitish changed the title WIP: Add feature for sending abandoned project mail Added feature for sending abandoned project mail Mar 3, 2018
@bansalnitish
Copy link
Contributor Author

bansalnitish commented Mar 3, 2018

@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.

screenshot from 2018-03-03 21-57-29

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 Mail sent message.

screenshot from 2018-03-03 22-15-50

screenshot from 2018-03-03 21-57-40

@bansalnitish bansalnitish force-pushed the abandon-proj branch 9 times, most recently from 5fac5f0 to 8c850a9 Compare March 3, 2018 17:45
@@ -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

@bansalnitish bansalnitish force-pushed the abandon-proj branch 7 times, most recently from c2dd6d7 to afc6d25 Compare March 4, 2018 16:04
@bansalnitish
Copy link
Contributor Author

bansalnitish commented Mar 4, 2018

@stsewd How to run the tests locally ? I was writing the tests as said by you but was not able to run them locally.

@stsewd
Copy link
Member

stsewd commented Mar 4, 2018

@bansalnitish You can check https://docs.readthedocs.io/en/latest/tests.html, let me know if something isn't clear.

@bansalnitish
Copy link
Contributor Author

Hi @stsewd, I have written the tests. Can you please have a look and suggest improvements!
Thanks 😄

<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>
Copy link
Member

Choose a reason for hiding this comment

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

was sent

Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Contributor Author

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?

Copy link
Member

@stsewd stsewd Mar 6, 2018

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure @stsewd! Thanks 😄

Copy link
Contributor Author

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!

Copy link
Contributor Author

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!

Copy link
Member

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.

Copy link
Contributor Author

@bansalnitish bansalnitish Mar 8, 2018

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?

Copy link
Member

@ericholscher ericholscher left a 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!

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)
Copy link
Member

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.

@property
def is_abandoned_mail_sent(self):
"""Is abandoned mail sent."""
return self.abandoned_mail_sent
Copy link
Member

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.

@@ -36,6 +36,10 @@
private.project_manage,
name='projects_manage'),

url(r'^(?P<project_slug>[-\w]+)/send_mail/$',
private.send_mail,
name='send_mail'),
Copy link
Member

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
Copy link
Member

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.

@bansalnitish
Copy link
Contributor Author

bansalnitish commented Mar 8, 2018

Hi, @ericholscher I have made the requested changes. Can you have a look once!
Thanks!

@bansalnitish bansalnitish force-pushed the abandon-proj branch 2 times, most recently from 015d82f to 1274c8f Compare March 8, 2018 11:33
Copy link
Contributor

@agjohnson agjohnson left a 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.

@agjohnson
Copy link
Contributor

As per feedback in #3382, I'm closing this. The branch will still be available for reference if needed.

@agjohnson agjohnson closed this Jun 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants