-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unique coupon code in org and assignee email in item (#295)
* checking for unique coupon code in org * forgot to add participant view * linting fix * added makefile for easy build * added csrf token in form * added link to github issue and 404 * fixed timezone in query * fixed item collection description and error message for assignee details * removed field specific errors * Move webpack config and package json to assets folder. Add Make file. (#296) * Move webpack config and package json to assets folder. Add Make file * remove manifest.json * node_modules is already ignored below * Add make to travis script file * removed extra fields from AssigneeForm * fix form save * added todo for sending notification on asignee update
- Loading branch information
Bibhas
authored
Aug 1, 2019
1 parent
e7107b4
commit a97af60
Showing
9 changed files
with
175 additions
and
52 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
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 |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
from .order_refund import * | ||
from .discount import * | ||
from .category import * | ||
from .participant import * |
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,34 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from baseframe import __ | ||
import baseframe.forms as forms | ||
|
||
from boxoffice.models import Assignee, Item, LineItem | ||
|
||
__all__ = ['AssigneeForm'] | ||
|
||
|
||
class AssigneeForm(forms.Form): | ||
email = forms.EmailField( | ||
__("Email"), | ||
validators=[forms.validators.DataRequired(), forms.validators.Length(max=254)], | ||
) | ||
fullname = forms.StringField( | ||
__("Full Name"), validators=[forms.validators.DataRequired()] | ||
) | ||
phone = forms.StringField( | ||
__("Phone number"), validators=[forms.validators.DataRequired()] | ||
) | ||
|
||
def validate_email(self, field): | ||
existing_assignees = ( | ||
Assignee.query.join(LineItem) | ||
.filter(LineItem.item == self.edit_parent.item) | ||
.filter(Assignee.email == field.data) | ||
) | ||
if self.edit_obj is not None: | ||
existing_assignees = existing_assignees.filter( | ||
Assignee.id != self.edit_obj.id | ||
) | ||
if existing_assignees.count() > 0: | ||
raise forms.ValidationError(__("Email address has been already used")) |
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,8 @@ | ||
all: assets | ||
|
||
assets: | ||
npm install | ||
npm run build | ||
|
||
buildonly: | ||
npm run build |
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 |
---|---|---|
@@ -1,49 +1,93 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from flask import request, jsonify, make_response | ||
from .. import app | ||
from ..models import db | ||
from ..models import LineItem, Assignee | ||
from ..models import Order | ||
from coaster.views import load_models | ||
from flask import jsonify, make_response, request | ||
|
||
from boxoffice.mailclient import send_ticket_assignment_mail | ||
from utils import xhr_only | ||
|
||
from coaster.views import load_models, render_with | ||
|
||
from .. import app | ||
from ..forms import AssigneeForm | ||
from ..models import Assignee, LineItem, Order, db | ||
|
||
|
||
@app.route('/participant/<access_token>/assign', methods=['GET', 'OPTIONS', 'POST']) | ||
@xhr_only | ||
@load_models( | ||
(Order, {'access_token': 'access_token'}, 'order') | ||
) | ||
@render_with(json=True) | ||
@load_models((Order, {'access_token': 'access_token'}, 'order')) | ||
def assign(order): | ||
""" | ||
Assign a line_item to a participant | ||
""" | ||
assignee_dict = request.json.get('attendee') | ||
if not request.json or not assignee_dict or not assignee_dict.get('email') or not assignee_dict.get('fullname'): | ||
return make_response(jsonify(status='error', error='missing_attendee_details', error_description="Attendee details are missing"), 400) | ||
line_item = LineItem.query.get(request.json.get('line_item_id')) | ||
if line_item.is_cancelled: | ||
return make_response(jsonify(status='error', error='cancelled_ticket', error_description="Ticket has been cancelled"), 400) | ||
|
||
item_assignee_details = line_item.item.assignee_details | ||
assignee_details = {} | ||
if item_assignee_details: | ||
for key in item_assignee_details.keys(): | ||
assignee_details[key] = assignee_dict.get(key) | ||
if line_item.current_assignee and assignee_dict['email'] == line_item.current_assignee.email: | ||
# updating details of the current assignee | ||
line_item.current_assignee.fullname = assignee_dict['fullname'] | ||
line_item.current_assignee.phone = assignee_dict['phone'] | ||
line_item.current_assignee.details = assignee_details | ||
db.session.commit() | ||
if line_item is None: | ||
return ( | ||
{ | ||
'status': 'error', | ||
'error': 'missing_line_item', | ||
'error_description': u"Invalid line item", | ||
}, | ||
404, | ||
) | ||
elif line_item.is_cancelled: | ||
return ( | ||
{ | ||
'status': 'error', | ||
'error': 'cancelled_ticket', | ||
'error_description': u"Ticket has been cancelled", | ||
}, | ||
400, | ||
) | ||
|
||
assignee_dict = request.json.get('attendee') | ||
assignee_form = AssigneeForm.from_json( | ||
assignee_dict, | ||
obj=line_item.current_assignee, | ||
parent=line_item, | ||
csrf_token=request.json.get('csrf_token'), | ||
) | ||
|
||
if assignee_form.validate_on_submit(): | ||
item_assignee_details = line_item.item.assignee_details | ||
assignee_details = {} | ||
if item_assignee_details: | ||
for key in item_assignee_details.keys(): | ||
assignee_details[key] = assignee_dict.get(key) | ||
if ( | ||
line_item.current_assignee | ||
and assignee_dict['email'] == line_item.current_assignee.email | ||
): | ||
# updating details of the current assignee | ||
line_item.current_assignee.fullname = assignee_dict['fullname'] | ||
line_item.current_assignee.phone = assignee_dict['phone'] | ||
line_item.current_assignee.details = assignee_details | ||
db.session.commit() | ||
else: | ||
if line_item.current_assignee: | ||
# Assignee is being changed. Archive current assignee. | ||
# TODO: Send notification to previous assignee. | ||
# https://github.com/hasgeek/boxoffice/issues/244 | ||
line_item.current_assignee.current = None | ||
new_assignee = Assignee( | ||
current=True, | ||
email=assignee_dict.get('email'), | ||
fullname=assignee_dict.get('fullname'), | ||
phone=assignee_dict.get('phone'), | ||
details=assignee_details, | ||
line_item=line_item, | ||
) | ||
db.session.add(new_assignee) | ||
db.session.commit() | ||
send_ticket_assignment_mail.queue(line_item.id) | ||
return {'status': 'ok', 'result': {'message': 'Ticket assigned'}} | ||
else: | ||
if line_item.current_assignee: | ||
# Archive current assignee | ||
line_item.current_assignee.current = None | ||
new_assignee = Assignee(current=True, email=assignee_dict.get('email'), fullname=assignee_dict.get('fullname'), | ||
phone=assignee_dict.get('phone'), details=assignee_details, line_item=line_item) | ||
db.session.add(new_assignee) | ||
db.session.commit() | ||
send_ticket_assignment_mail.queue(line_item.id) | ||
return make_response(jsonify(status='ok', result={'message': 'Ticket assigned'}), 201) | ||
return ( | ||
{ | ||
'status': 'error', | ||
'error': 'invalid_assignee_details', | ||
'error_description': u"Invalid form values. Please resubmit.", | ||
'error_details': assignee_form.errors, | ||
}, | ||
400, | ||
) |