-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Command contact_owners
: add support to filter by usernames
#9882
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
Add `--usernames` argument to be able to filter by usernames when sending contacting users. This can be used as: ``` django-admin contact_owners --notification notification.md --sticky --usernames usernames.txt ``` ``` humitos santos anthony ``` ``` Read the Docs is going to force email verification to be able to login accounts in the following weeks. We've noticed **your account doesn't have any email verified**. Please, go to [your email settings](/accounts/email/) and verify your email now. ``` In this case, it will send a sticky notification with that content to these 3 users. Required by #9865
Not really sure if it's worth trying to support every use case on this command, I've been using the """
Script to email owners of organizations
that have domains already on Cloudflare.
We are asking more about their setup.
Email at https://pad.riseup.net.....
"""
from pprint import pprint
import requests
from django.contrib.auth.models import User
from readthedocs.core.utils.contact import contact_users
from readthedocs.projects.models import Domain
pending_domains = [
"example.com"
]
def get_email():
url = 'https://pad.riseup.net/p/..../export/txt'
content = requests.get(url).text.split('\n')
email_subject = content[0].strip()
email_content = '\n'.join(content[1:]).strip()
return email_subject, email_content
def get_users():
return User.objects.filter(
owner_organizations__projects__domains__domain__in=pending_domains,
).distinct()
def get_context(user):
domains = Domain.objects.filter(
project__organizations__owners=user,
domain__in=pending_domains,
).distinct()
return {
'pending_domains': domains,
}
def email_owners(dryrun=True):
email_subject, email_content = get_email()
response = contact_users(
users=get_users(),
email_subject=email_subject,
email_content=email_content,
from_email="Read the Docs <[email protected]>",
context_function=get_context,
dryrun=dryrun,
)
pprint(response) |
Gotcha! 👍🏼 I'm fine merging the changes in this PR into the script since it's not changing its core behavior, but just adding another generic way to get the emails that have to be contacted ( |
I think adding this makes sense, given that it's a pretty common use case. Probably worth saving Santos' example somewhere, and linking to it in a comment from this code. |
@ericholscher Done! Added a new commit that extends the class docstring pointing to the demo script. |
Co-authored-by: Santos Gallegos <[email protected]>
Add
--usernames
argument to be able to filter by usernames when sending contacting users.This can be used as:
In this case, it will send a sticky notification with that content to these 3 users.
Example
Required by #9865
Fixes https://github.com/readthedocs/meta/issues/104