Repository: fossasia/open-event-server

Issue:
Ticket Email: Ticket Download not working. Wrong URL
The ticket download email comes with a wrong URL to something like "https://api.eventyay.com/generated/tickets/orders/tickets/pdf/9bdedaa....".

It results in a page: "Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again."

![Screenshot from 2020-02-05 03-13-13](https://user-images.githubusercontent.com/1583873/73804964-a7f1ea00-47c5-11ea-9d9f-7f80612f5684.png)
![Screenshot from 2020-02-05 03-12-36](https://user-images.githubusercontent.com/1583873/73804966-a88a8080-47c5-11ea-8ed4-ac622269dce3.png)



Discussion:
I will be working on it.
@kushthedude i may be wrong but this appears to be server issue.
@iamareebjamal 
@abhiandthetruth Are you willing to work on this?

Nope it's open
Will fix this. 
All the best.


On Wed, Feb 5, 2020, 7:48 PM Sai Charan <notifications@github.com> wrote:

> @abhiandthetruth <https://github.com/abhiandthetruth> Are you willing to
> work on this?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/fossasia/open-event-server/issues/6818?email_source=notifications&email_token=ALNBECOEJQJRZY64KPKUZJLRBLDEHA5CNFSM4KQKSRT2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEK3SRUY#issuecomment-582428883>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ALNBECPJOG67GY3FYD5RMSDRBLDEHANCNFSM4KQKSRTQ>
> .
>

@iamareebjamal @mariobehling If the user can access the ticket via a link, it would bring us back to this issue https://github.com/fossasia/open-event-server/issues/5608
As the tickets are already attached, I don't think it's necessary for the link. If there was any error and the tickets/invoice could not be sent to the user, we could point them to eventyay.com so that they could download it.

Similar to the pre-existing system mail for `TICKET_PURCHASED`, the mail reflect the following text:

```
    TICKET_PURCHASED: {
        'recipient': 'User',
        'subject': u'Your order invoice and tickets for {event_name} ({invoice_id}) ',
        'message': (
            u"Hi, this is a confirmation mail of your tickets for the event {event_name}"
            u"<br/>Your order has been processed successfully."
            + u"<br/> You can find your Tickets and Order Invoice attached to this mail."
            u"<br><br><em>Looking forward to seeing you at the event."
            u"<br/>Login to manage your orders, tickets & invoices at {frontend_url} </em>"
        ),
    }
```
The pdf link should still work. It won't lead to the above issue because of your PR itself 
Alright

On Wed, 5 Feb 2020 at 8:50 PM, Areeb Jamal <notifications@github.com> wrote:

> The pdf link should still work. It won't lead to the above issue because
> of your PR itself
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/fossasia/open-event-server/issues/6818?email_source=notifications&email_token=AGAHUW7SCK3TWHE5OXMEE23RBLKNJA5CNFSM4KQKSRT2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEK3ZYNI#issuecomment-582458421>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AGAHUW3IPN3TGRSN43XCGEDRBLKNJANCNFSM4KQKSRTQ>
> .
>

`https://<API_HOST>/generated/invoices/orders/invoices/pdf/1a523e55-7b46-46bd-90c1-85805384e9da/U3ZUQUZoTE/1a523e55-7b46-46bd-90c1-85805384e9da.pdf`.

The current link which is being stored would've had no errors if the files had been stored in static/templates(where flask looks to serve static files like these). But all our tickets are at `generated/`.

@iamareebjamal What do you suggest as a plausible solution? I was wondering if we could create an exclusive `generated` route. 
It was already created by you only
Thinking about this again, you are right @mrsaicharan1. This can not work without it being accessible to the general public. @mariobehling It will either be available to anyone with the link or it'll throw an error for the user. There is no way to know who the user is with just the link of the PDF. So what should be done? We can either remove the link from the email and users can go to frontend to see the ticket. Or, we can allow it to be accessed by anyone who has the link
Best would be to provide a request for the user to login. The first step is to send the tickets by email and dont send the link in the confirmation email as a quick fix. We can simply say "Your ticket is enclosed. You can also download in the My ticket section in your account."
@mariobehling Ticket attachments are already being sent. So that's covered. I'll add the request for the user to login. 

Resolving patch:
diff --git a/app/api/helpers/mail.py b/app/api/helpers/mail.py
--- a/app/api/helpers/mail.py
+++ b/app/api/helpers/mail.py
@@ -336,7 +336,6 @@ def send_email_to_attendees(order, purchaser_id, attachments=None):
                     frontend_url=get_settings()['frontend_url'],
                 ),
                 html=MAILS[TICKET_PURCHASED]['message'].format(
-                    pdf_url=holder.pdf_url,
                     event_name=order.event.name,
                     frontend_url=get_settings()['frontend_url'],
                 ),
@@ -351,7 +350,8 @@ def send_email_to_attendees(order, purchaser_id, attachments=None):
                     event_name=order.event.name, invoice_id=order.invoice_number
                 ),
                 html=MAILS[TICKET_PURCHASED_ATTENDEE]['message'].format(
-                    pdf_url=holder.pdf_url, event_name=order.event.name
+                    my_tickets_url=get_settings()['frontend_url'] + '/my-tickets',
+                    event_name=order.event.name,
                 ),
                 attachments=attachments,
             )
diff --git a/app/api/helpers/system_mails.py b/app/api/helpers/system_mails.py
--- a/app/api/helpers/system_mails.py
+++ b/app/api/helpers/system_mails.py
@@ -188,7 +188,9 @@
         'message': (
             u"Hi, this is a confirmation mail of your tickets for the event {event_name}"
             u"<br/>Your order has been processed successfully."
-            + u"<br/> <a href='{pdf_url}'>Click here</a> to view/download your ticket."
+            + u"<br/> Your tickets & invoice have been enclosed."
+            u"<br><br>You can also download your tickets in <b>My Tickets</b> section."
+            u"<br/>Login to manage the orders at <a href='{mytickets_url}' target='_blank'>{mytickets_url}</a> </em>"
             u"<br><br><em>Looking forward to seeing you at the event."
         ),
     },


Test patch: