Repository: fossasia/open-event-server

Issue:
Ticket Downloads Path issue
**Describe the bug**
The hash of the uploads path is missing from the path of the ticket returned at the route which leads to a `FileNotFound` Error event though the ticket is present.

**Expected behavior**
The ticket needs to be returned

**Stacktrace**
FileNotFoundError: [Errno 2] No such file or directory: '/generated/tickets/attendees/tickets/pdf/44ea48b7-d9de-4b7b-ac8f-a10fecd747d7/OUMxaFQ3cF/44ea48b7-d9de-4b7b-ac8f-a10fecd747d7.pdf'

Here `OUMxaFQ3cF` is missing from the path.

**Additional details (please complete the following information):**
 - OS: [e.g. MacOS, Ubuntu, CentOS]
 - Python Version [e.g. `3.5`, `3.6`]
 - `HEAD` Commit hash [e.g. `4629c62`]

**Additional context**
Working on it.


Discussion:

Resolving patch:
diff --git a/app/api/auth.py b/app/api/auth.py
--- a/app/api/auth.py
+++ b/app/api/auth.py
@@ -8,6 +8,7 @@
 from flask_jwt import current_identity as current_user, jwt_required
 from sqlalchemy.orm.exc import NoResultFound
 from app.api.helpers.order import create_pdf_tickets_for_holder
+from app.api.helpers.storage import generate_hash
 
 from app import get_settings
 from app.api.helpers.db import save_to_db, get_count
@@ -290,8 +291,8 @@ def ticket_attendee_authorized(order_identifier):
         except NoResultFound:
             return NotFoundError({'source': ''}, 'This ticket is not associated with any order').respond()
         if current_user.id == user_id:
-            file_path = os.path.join('/generated/tickets/{}'.format(UPLOAD_PATHS['pdf']['ticket_attendee']
-                                         .format(identifier=order_identifier)), order_identifier + '.pdf')
+            key = UPLOAD_PATHS['pdf']['ticket_attendee'].format(identifier=order_identifier)
+            file_path = '../generated/tickets/{}/{}/'.format(key, generate_hash(key)) + order_identifier + '.pdf'
             try:
                 response = make_response(send_file(file_path))
                 response.headers['Content-Disposition'] = 'attachment; filename=ticket-%s.zip' % order_identifier
diff --git a/app/api/helpers/files.py b/app/api/helpers/files.py
--- a/app/api/helpers/files.py
+++ b/app/api/helpers/files.py
@@ -257,7 +257,7 @@ def make_frontend_url(path, parameters=None):
     ))
 
 
-def create_save_pdf(pdf_data, key, dir_path='/static/uploads/pdf/temp/', identifier=get_file_name(), upload_dir='static/media'):
+def create_save_pdf(pdf_data, key, dir_path='/static/uploads/pdf/temp/', identifier=get_file_name(), upload_dir='static/media/'):
     """
     Create and Saves PDFs from html
     :param pdf_data:
diff --git a/app/api/helpers/storage.py b/app/api/helpers/storage.py
--- a/app/api/helpers/storage.py
+++ b/app/api/helpers/storage.py
@@ -130,7 +130,7 @@ def save(self, path):
 # MAIN
 #########
 
-def upload(uploaded_file, key, upload_dir='static/media', **kwargs):
+def upload(uploaded_file, key, upload_dir='static/media/', **kwargs):
     """
     Upload handler
     """
@@ -155,7 +155,7 @@ def upload(uploaded_file, key, upload_dir='static/media', **kwargs):
         return upload_local(uploaded_file, key, upload_dir, **kwargs)
 
 
-def upload_local(uploaded_file, key, upload_dir='static/media', **kwargs):
+def upload_local(uploaded_file, key, upload_dir='static/media/', **kwargs):
     """
     Uploads file locally. Base dir - static/media/
     """


Test patch: