Skip to content

Conversation

@pierrickdes59
Copy link

Send feedbacks mails from users

Copy link
Contributor

@abrasseu abrasseu left a comment

Choose a reason for hiding this comment

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

All in all it's good but we need to change some stuff before merge :)

Comment on lines +20 to +22
# Permit to send feedback emails from users
@api_view(['POST'])
def feedback(request, format=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Permit to send feedback emails from users
@api_view(['POST'])
def feedback(request, format=None):
@api_view(["POST"])
def feedback(request, format=None):
"""
Send feedback emails from users
"""

Use Python Docstrings

@api_view(['POST'])
def feedback(request, format=None):
data = request.data
if len(data['message']) < 2:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if len(data['message']) < 2:
if len(data.get("message", "")) < 2:

If there is no message in the POST data, get won't throw an error.

def feedback(request, format=None):
data = request.data
if len(data['message']) < 2:
return HttpResponse(status=500)
Copy link
Contributor

Choose a reason for hiding this comment

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

It should raise a 400 Bad Request error, you can maybe use ValidationError with a message like "Veuillez ajouter un message". Using a Serializer with a Model could help

Comment on lines +27 to +29
subject = "[WOOLLY][FeedBack] - " + data['reason'] + " - " + data['sender']['name']
message = 'Utilisateur : ' + data['sender']['name'] + '\n' + 'ID : ' + data['sender']['id'] + '\n' + 'Email : ' + data['sender']['email'] + '\n' + 'Date : ' + datetime.now().strftime("%d/%m/%Y, %H:%M:%S") + '\n' + 'Raison : ' + data['reason'] + '\n \n' + 'Message :' + '\n' + data['message']
message = message + '\n\nCe message a été généré automatiquement, merci de ne pas y répondre'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
subject = "[WOOLLY][FeedBack] - " + data['reason'] + " - " + data['sender']['name']
message = 'Utilisateur : ' + data['sender']['name'] + '\n' + 'ID : ' + data['sender']['id'] + '\n' + 'Email : ' + data['sender']['email'] + '\n' + 'Date : ' + datetime.now().strftime("%d/%m/%Y, %H:%M:%S") + '\n' + 'Raison : ' + data['reason'] + '\n \n' + 'Message :' + '\n' + data['message']
message = message + '\n\nCe message a été généré automatiquement, merci de ne pas y répondre'
subject = f"[WOOLLY][FeedBack] - {data['reason']} - {data['sender']['name']}"
message = "\n".join([
f"Utilisateur: {data['sender']['name']}",
f"Identifiant: {data['sender']['id']}",
f"Email: {data['sender']['email']}",
f"Date: {datetime.now().isoformat(sep=' ', timespec='seconds')}"
f"Raison: {data['reason']}",
"",
{data['message']},
"",
"Ce message a été généré automatiquement, merci de ne pas y répondre",
])

You should also check that all the data attributes are present, maybe create a Model and a Serializer ?

Comment on lines +69 to +81
# email = env.dj_email_url("EMAIL_URL")
# EMAIL_HOST = email["EMAIL_HOST"]
# EMAIL_PORT = email["EMAIL_PORT"]
# EMAIL_HOST_USER = email["EMAIL_HOST_USER"]
# EMAIL_HOST_PASSWORD = email["EMAIL_HOST_PASSWORD"]
# EMAIL_USE_SSL = email["EMAIL_USE_SSL"]
# EMAIL_USE_TLS = email["EMAIL_USE_TLS"]
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = env.str("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = env.str("EMAIL_HOST_PASSWORD")
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll need to revert that and use something like this in your personal .env:

EMAIL_URL=stmp://user@domain:[email protected]:587?tls=True

@abrasseu abrasseu changed the title Pierrick dev feat: Get user feedback Dec 13, 2020
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.

3 participants