-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(refactor): Refactor code for custom attendee route (#6752)
- Loading branch information
1 parent
10a914b
commit 494608c
Showing
3 changed files
with
47 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from flask import Blueprint, request, jsonify, abort, make_response | ||
from flask_jwt_extended import current_user | ||
from sqlalchemy.orm.exc import NoResultFound | ||
|
||
from app.api.helpers.mail import send_email_to_attendees | ||
from app.api.helpers.permissions import jwt_required | ||
from app.api.helpers.errors import ( | ||
UnprocessableEntityError, | ||
NotFoundError, | ||
ForbiddenError, | ||
) | ||
from app.api.helpers.permission_manager import has_access | ||
|
||
from app.models.order import Order | ||
from app.models import db | ||
|
||
attendee_blueprint = Blueprint('attendee_blueprint', __name__, url_prefix='/v1') | ||
|
||
|
||
@attendee_blueprint.route('/attendees/send-receipt', methods=['POST']) | ||
@jwt_required | ||
def send_receipt(): | ||
""" | ||
Send receipts to attendees related to the provided order. | ||
:return: | ||
""" | ||
order_identifier = request.json.get('order-identifier') | ||
if order_identifier: | ||
try: | ||
order = db.session.query(Order).filter_by(identifier=order_identifier).one() | ||
except NoResultFound: | ||
return NotFoundError({'parameter': '{order_identifier}'}, "Order not found").respond() | ||
|
||
if (order.user_id != current_user.id) and (not has_access('is_registrar', event_id=order.event_id)): | ||
return ForbiddenError({'source': ''}, | ||
'You need to be the event organizer or order buyer to send receipts.').respond() | ||
elif order.status != 'completed': | ||
abort( | ||
make_response(jsonify(error="Cannot send receipt for an incomplete order"), 409) | ||
) | ||
else: | ||
send_email_to_attendees(order, current_user.id) | ||
return jsonify(message="receipt sent to attendees") | ||
else: | ||
return UnprocessableEntityError({'source': ''}, 'Order identifier missing').respond() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters