Skip to content

Conversation

@uds5501
Copy link
Contributor

@uds5501 uds5501 commented Jul 9, 2019

Fixes #6162

Short description of what this resolves:

This adds an endpoint which triggers re sending email confirmation for tickets

Changes proposed in this pull request:

  • Ensures that only organisers and co organisers have ability to resend the emails.

Checklist

  • I have read the Contribution & Best practices Guide and my PR follows them.
  • My branch is up-to-date with the Upstream development branch.
  • The unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • All the functions created/modified in this PR contain relevant docstrings.

@auto-label auto-label bot added the feature label Jul 9, 2019
@uds5501 uds5501 force-pushed the resend-emails-route branch from 32b8d44 to d71c128 Compare July 9, 2019 05:10
@uds5501
Copy link
Contributor Author

uds5501 commented Jul 9, 2019

@mrsaicharan1 @prateekj117 @shreyanshdwivedi Please review

@codecov
Copy link

codecov bot commented Jul 9, 2019

Codecov Report

Merging #6163 into development will decrease coverage by 0.1%.
The diff coverage is 31.57%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development    #6163      +/-   ##
===============================================
- Coverage        66.18%   66.08%   -0.11%     
===============================================
  Files              288      288              
  Lines            14460    14497      +37     
===============================================
+ Hits              9571     9580       +9     
- Misses            4889     4917      +28
Impacted Files Coverage Δ
app/api/auth.py 24.39% <31.57%> (+0.26%) ⬆️
app/api/tickets.py 47.61% <0%> (-5.8%) ⬇️
app/models/event.py 79.04% <0%> (-0.22%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2bfa553...6d93fc7. Read the comment docs.

return redirect(make_frontend_url('orders/{}/view'.format(order_identifier)))


@order_misc_routes.route('/orders/<string:order_identifier>/resend-email', methods=['POST'])
Copy link
Member

Choose a reason for hiding this comment

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

Ensure this endpoint has rate limiting

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!

:param order_identifier:
:return: JSON response if the email was succesfully sent
"""
order = safe_query(db, Order, 'identifier', order_identifier, 'identifier')
Copy link
Member

Choose a reason for hiding this comment

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

Sometimes, the order may not be fetched. So I guess a try...except block would be great here :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The failure is simply handled by a server 500 in the safe_query itself, IMO that should do

Copy link
Member

@mrsaicharan1 mrsaicharan1 left a comment

Choose a reason for hiding this comment

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

Check this too!

@fossasia fossasia deleted a comment Jul 10, 2019
@uds5501 uds5501 force-pushed the resend-emails-route branch from 86d3eb8 to 71c510a Compare July 10, 2019 04:45
@fossasia fossasia deleted a comment Jul 10, 2019
@fossasia fossasia deleted a comment Jul 10, 2019
@fossasia fossasia deleted a comment Jul 10, 2019
app/api/auth.py Outdated
'3/hour', key_func=lambda: request.json['data']['order'], error_message='Limit for this action exceeded'
)
@limiter.limit(
'1/minute', key_func=get_remote_address, error_message='Limit for this action exceeded'
Copy link
Member

Choose a reason for hiding this comment

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

IMO 1/minute is very less for this threshold. An organizer can go on clicking the resent invite button on the client side so we should increase this. @iamareebjamal what can be a suitable threshold for this endpoint?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

60/minute for IP
5/minute for user_id

invoice_path = 'generated/invoices/{}/{}/'.format(key, generate_hash(key)) + order_identifier + '.pdf'

# send email.
send_email_to_attendees(order=order, purchaser_id=current_user.id, attachments=[ticket_path, invoice_path])
Copy link
Member

@mrsaicharan1 mrsaicharan1 Jul 10, 2019

Choose a reason for hiding this comment

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

I believe that attachments should be empty for placed orders as they're meant for offline tickets?

Copy link
Member

Choose a reason for hiding this comment

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

I think placed orders should have tickets too. They are meant to show this ticket when they reach event venue

Copy link
Member

@mrsaicharan1 mrsaicharan1 Jul 10, 2019

Choose a reason for hiding this comment

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

I think placed orders should have tickets too. They are meant to show this ticket when they reach event venue

Agreed 👍

@uds5501 uds5501 force-pushed the resend-emails-route branch from 89dbaea to 639a187 Compare July 10, 2019 10:45
@fossasia fossasia deleted a comment Jul 10, 2019
app/api/auth.py Outdated
return jsonify(status=True, message="Verification emails for order : {} has been sent succesfully".
format(order_identifier))
else:
return jsonify(status=False, message="Only placed and complete orders are verified")
Copy link
Member

Choose a reason for hiding this comment

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

This be raised as an error. Not a success response

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@niranjan94 did it, please check.

@fossasia fossasia deleted a comment Jul 10, 2019
@fossasia fossasia deleted a comment Jul 11, 2019
app/api/auth.py Outdated

@ticket_blueprint.route('/orders/resend-email', methods=['POST'])
@limiter.limit(
'5/minute', key_func=lambda: request.json['data']['order'], error_message='Limit for this action exceeded'
Copy link
Member

Choose a reason for hiding this comment

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

Where is limit by user?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iamareebjamal modified order to user key.

@fossasia fossasia deleted a comment Jul 11, 2019
@iamareebjamal
Copy link
Member

Did you test it?

@uds5501
Copy link
Contributor Author

uds5501 commented Jul 11, 2019

@iamareebjamal yes, tested it via postman, it's working as expected.

@uds5501
Copy link
Contributor Author

uds5501 commented Jul 12, 2019

@mrsaicharan1 @shreyanshdwivedi @prateekj117 Please review

return jsonify(status=True, message="Verification emails for order : {} has been sent succesfully".
format(order_identifier))
else:
return UnprocessableEntityError({'source': 'data/order'},
Copy link
Member

Choose a reason for hiding this comment

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

Why is it returning instead of raising?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iamareebjamal because these errors are actually a subclass of ErrorResponse and not actual errors. To make them work we need to initiate their respond function (the same error classes have been used all through this file)

return UnprocessableEntityError({'source': 'data/order'},
"Only placed and completed orders have confirmation").respond()
else:
return ForbiddenError({'source': ''}, "Co-Organizer Access Required").respond()
Copy link
Member

Choose a reason for hiding this comment

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

Same

@iamareebjamal iamareebjamal merged commit 336ec2d into fossasia:development Jul 12, 2019
iamareebjamal pushed a commit to iamareebjamal/open-event-server that referenced this pull request Aug 2, 2019
* add the resend email route

* resend emails using ticket route

* handle errors with UnprocessableEntry

* modify order to user key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement order route for re-sending order confirmation mails

6 participants