-
Couldn't load subscription status.
- Fork 1.8k
feat: implement resend email confirmation button #3251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@uds5501 I have told this before. Do not create frontend PRs without the server code being merged in. When something depends on the server APIs, it is not possible to test the frontend code until server is merged in.
| } | ||
| }; | ||
| let resend = await this.loader.post('orders/resend-email', payload); | ||
| if (resend.status) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment regarding this added on the server PR. fossasia/open-event-server#6163 (comment)
|
Re-open after server PR is merged |
25dc235 to
56d14d1
Compare
| } | ||
| }; | ||
| let resendEmail = await this.loader.post('orders/resend-email', payload); | ||
| if (resendEmail.status) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@uds5501 update this to the correct error handling. If this.loader.post succeeds it should be considered a success. Any error should be in the catch block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@niranjan94 Did it!
f3cd499 to
dfa01da
Compare
| await this.loader.post('orders/resend-email', payload); | ||
| this.notify.success(this.l10n.t('Email confirmation has been sent to attendees successfully')); | ||
| } catch (error) { | ||
| this.notify.error(this.l10n.t('An unexpected error occurred.')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the error ? Could we display something better ? Like for example, if it was a ratelimitting error, show that it was due to it. Else show whatever the actual error sent by the backend is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@niranjan94 I have changed error handling, is it any better?
dfa01da to
f8c6ac4
Compare
| this.notify.success(this.l10n.t('Email confirmation has been sent to attendees successfully')); | ||
| } catch (error) { | ||
| console.log(error); | ||
| const errorMessage = error.message || error.errors[0].detail; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the case where the rate limiting kicks in ? What is the error message sent by the server ? Does it come in here correctly ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@niranjan94 When rate limit kicks in, it's handled by error.message. If it's other trivial error like sending confirmation for cancelled orders, it's handled by error.errors[0].detail. Otherwise the else condition.
The rate limiting error sent is : TOO MANY REQUESTS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@uds5501 for rate limiting the server would be sending a 429 if I'm right. When that comes, please show a proper and a more human-friendly error message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, with translations
| this.notify.success(this.l10n.t('Email confirmation has been sent to attendees successfully')); | ||
| } catch (error) { | ||
| console.log(error); | ||
| const errorMessage = error.message || error.errors[0].detail; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Give first priority to error.errors[0].detail. Also, what if server is sending multiple errors. You should not hard code to display only the first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@niranjan94 Understood
f8c6ac4 to
427011a
Compare
427011a to
af928c0
Compare
| 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.message === 'TOO MANY REQUESTS') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@niranjan94 @shreyanshdwivedi @CosmicCoder96 Will this workaround be okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@uds5501 this is very wrong. You must use the status code.
Modify the loader service to ensure the original response is sent as the error along with the message that is being currently sent there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@niranjan94 Understood.
| 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.message === 'TOO MANY REQUESTS') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@uds5501 this is very wrong. You must use the status code.
Modify the loader service to ensure the original response is sent as the error along with the message that is being currently sent there
af928c0 to
d529408
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@uds5501 try not to find shortcuts. Spend some more time on fixes. See how you can make it such that its re-usable
app/services/loader.js
Outdated
| if (parsedResponse) { | ||
| throw parsedResponse; | ||
| } | ||
| if (response.status === 429) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Make this a generic implementation such that status code and the original response is always passed in.
if (!response.ok) {
const defaultMessage = httpStatus[response.status];
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;
}7697d01 to
15a1563
Compare
15a1563 to
4e215bb
Compare
|
@mrsaicharan1 @shreyanshdwivedi @CosmicCoder96 Please review this |
| this.notify.success(this.l10n.t('Email confirmation has been sent to attendees successfully')); | ||
| } catch (error) { | ||
| if (error.status === 429) { | ||
| this.notify.error(this.l10n.t('Only 5 resend actions are allowed in a minute')); |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
4e215bb to
b7463d5
Compare
tests/integration/components/ui-table/cell/events/view/tickets/orders/cell-order-test.js
Outdated
Show resolved
Hide resolved
| let payload = {}; | ||
| try { | ||
| payload = { | ||
| 'data': { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is not how commits should be, squash them use semantic naming.
b2157c5 to
26436bf
Compare
26436bf to
b1d83cd
Compare
|
@CosmicCoder96 @mrsaicharan1 @shreyanshdwivedi @kushthedude Please review this. |
Fixes #2893
Server PR : fossasia/open-event-server#6163
Short description of what this resolves:
The PR implements the utlizes rate limited end point on the server side to send order confirmation for completed and placed tickets.
Changes proposed in this pull request:
Checklist
developmentbranch.