Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions app/controllers/events/view/tickets/orders/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ export default Controller.extend({
.finally(() => {
this.set('isLoading', false);
});
},
async resendConfirmation(order) {
try {
const payload = {
'data': {
Copy link
Contributor

Choose a reason for hiding this comment

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

 order_identifier = request.json['data']['order']
    order = safe_query(db, Order, 'identifier', order_identifier, 'identifier')
    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 UnprocessableEntityError({'source': 'data/order'},
                                            "Only placed and completed orders have confirmation").respond()
    else:
        return ForbiddenError({'source': ''}, "Co-Organizer Access Required").respond()

This is the code for this end point on the server,
why is it the user field required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

User is being used for rate limiting for users

'order' : order.identifier,
'user' : this.authManager.currentUser.email
}
};
await this.loader.post('orders/resend-email', payload);
this.notify.success(this.l10n.t('Email confirmation has been sent to attendees successfully'));
} catch (error) {
if (error.status && error.status === 429) {
this.notify.error(this.l10n.t('Only 5 resend actions are allowed in a minute'));
Copy link
Member

Choose a reason for hiding this comment

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

What if the error is something other than the two you specified.
Comparing error returned by server with the codes is not a optimisable solution its more like a workaround. @uds5501 is this the only working way for this problem ?

Copy link
Member

Choose a reason for hiding this comment

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

@kushthedude There's no context of optimality here. @uds5501 Just add an else statement for other errors & this is good to go :D

} else if (error.status && error.status === 422) {
this.notify.error(this.l10n.tVar(error.response.errors[0].detail));
} else {
this.notify.error(this.l10n.t('An unexpected error has occurred.'));
}
}
}
}
});
16 changes: 8 additions & 8 deletions app/services/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { buildUrl } from 'open-event-frontend/utils/url';
import httpStatus from 'http-status';
import objectToFormData from 'object-to-formdata';
import fetch from 'fetch';
import { clone, assign, merge } from 'lodash-es';
import { clone, assign, merge, pick, isString } from 'lodash-es';
const bodyAllowedIn = ['PATCH', 'POST', 'PUT'];

export default Service.extend({
Expand Down Expand Up @@ -94,17 +94,17 @@ export default Service.extend({

if (!response.ok) {
const defaultMessage = httpStatus[response.status];
if (parsedResponse) {
throw parsedResponse;
}
throw new Error(
getErrorMessage(
const errorResponse = pick(response, ['status', 'ok', 'statusText', 'headers', 'url']);
errorResponse.statusText = defaultMessage;
errorResponse.response = parsedResponse;
errorResponse.errorMessage = isString(parsedResponse) ? parsedResponse
: getErrorMessage(
response.statusText,
defaultMessage
? `${response.status} - ${defaultMessage}`
: `Could not make ${fetchOptions.type} request to ${fetchOptions.url}`
)
);
);
throw errorResponse;
}
return parsedResponse;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<i class="trash icon"></i>
{{/ui-popup}}
{{/if}}
{{#ui-popup content=(t 'Resend order confirmation') class="{{if device.isMobile 'medium' 'huge'}} ui icon button" position='top center'}}
{{#ui-popup content=(t 'Resend order confirmation') click=(action resendConfirmation record) class="{{if device.isMobile 'medium' 'huge'}} ui icon button" position='top center'}}
<i class="mail outline icon"></i>
{{/ui-popup}}
</div>
1 change: 1 addition & 0 deletions app/templates/events/view/tickets/orders/list.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
completeOrder=(action 'completeOrder')
deleteOrder=(action 'deleteOrder')
cancelOrder=(action 'cancelOrder')
resendConfirmation=(action 'resendConfirmation')
}}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ module('Integration | Component | ui table/cell/events/view/tickets/orders/cell
setupIntegrationTest(hooks);

test('it renders', async function(assert) {
this.set('deleteOrder', () => {});
this.set('cancelOrder', () => {});
this.setProperties({
'deleteOrder' : () => {},
'cancelOrder' : () => {},
'resendConfirmation' : () => {}
});
let record = EmberObject.create({
amount : 20,
status : 'cancelled',
identifier : 'identifier_order'
});
this.set('record', record);
await render(hbs`{{ui-table/cell/events/view/tickets/orders/cell-order deleteOrder=(action deleteOrder) cancelOrder=(action cancelOrder) record=record }}`);
await render(hbs`{{ui-table/cell/events/view/tickets/orders/cell-order deleteOrder=(action deleteOrder) cancelOrder=(action cancelOrder) resendConfirmation=(action resendConfirmation) record=record }}`);
assert.ok(this.element.textContent.trim().includes(''));
});
});