Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions app/api/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,8 @@ def after_create_object(self, order, data, view_kwargs):

key = UPLOAD_PATHS['pdf']['order'].format(identifier=order_identifier)
invoice_path = 'generated/invoices/{}/{}/'.format(key, generate_hash(key)) + order_identifier + '.pdf'

# send email and notifications.
send_email_to_attendees(order=order, purchaser_id=current_user.id, attachments=[ticket_path, invoice_path])

send_notif_to_attendees(order, current_user.id)

if order.payment_mode in ['free', 'bank', 'cheque', 'onsite']:
Expand Down Expand Up @@ -535,3 +533,30 @@ def omise_checkout(order_identifier):
logging.info(f"Successful charge: {charge.id}. Order ID: {order_identifier}")

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!

def resend_emails(order_identifier):
"""
Sends confirmation email for pending and completed orders on organizer request
: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

if (has_access('is_coorganizer', event_id=order.event_id)):
if order.status == 'completed' or order.status == 'placed':
# fetch tickets attachment
order_identifier = order.identifier
key = UPLOAD_PATHS['pdf']['tickets_all'].format(identifier=order_identifier)
ticket_path = 'generated/tickets/{}/{}/'.format(key, generate_hash(key)) + order_identifier + '.pdf'
key = UPLOAD_PATHS['pdf']['order'].format(identifier=order_identifier)
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])
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")
else:
raise ForbiddenException({'source': ''}, "Co-Organizer Access Required")