Repository: fossasia/open-event-server

Issue:
 'AnonymousUserMixin' object has no attribute 'email' on updating an event
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
We are facing this Attribute Error the moment we try updating any event related object which corresponds to a celery task

**To Reproduce**
Steps to reproduce the behavior:
1. Update any existing event
2. See error

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->
It should work normally without any error

**Stacktrace**
<!-- If applicable, add stacktrace to help explain your problem. -->
```cmd
AttributeError: 'AnonymousUserMixin' object has no attribute 'email'

File "/home/shreyansh/open-event-server/venv/lib/python3.6/site-packages/flask/views.py", line 88, in view
    return self.dispatch_request(*args, **kwargs)
  File "/home/shreyansh/open-event-server/venv/src/flask-rest-jsonapi/flask_rest_jsonapi/resource.py", line 68, in dispatch_request
    response = method(*args, **kwargs)
  File "/home/shreyansh/open-event-server/venv/src/flask-rest-jsonapi/flask_rest_jsonapi/decorators.py", line 56, in wrapper
    return func(*args, **kwargs)
  File "/home/shreyansh/open-event-server/venv/src/flask-rest-jsonapi/flask_rest_jsonapi/resource.py", line 311, in patch
    self._data_layer.update_object(obj, data, kwargs)
  File "/home/shreyansh/open-event-server/venv/src/flask-rest-jsonapi/flask_rest_jsonapi/data_layers/alchemy.py", line 144, in update_object
    self.after_update_object(obj, data, view_kwargs)
  File "/home/shreyansh/open-event-server/app/api/events.py", line 485, in after_update_object
    start_export_tasks(event)
  File "/home/shreyansh/open-event-server/app/api/events.py", line 553, in start_export_tasks
    create_export_job(task_xcal.id, event_id)
```
**Additional details (please complete the following information):**
 - OS: [e.g. MacOS, Ubuntu, CentOS] Ubuntu
 - Python Version [e.g. `3.5`, `3.6`] 3.5

**Additional context**
<!-- Add any other context about the problem here. -->
Working on it


Discussion:

Resolving patch:
diff --git a/app/api/helpers/export_helpers.py b/app/api/helpers/export_helpers.py
--- a/app/api/helpers/export_helpers.py
+++ b/app/api/helpers/export_helpers.py
@@ -230,6 +230,13 @@ def export_event_json(event_id, settings):
     return storage_url
 
 
+def get_current_user():
+    if current_identity:
+        return current_identity
+    else:
+        return current_user
+
+
 # HELPERS
 
 def create_export_job(task_id, event_id):
@@ -238,15 +245,17 @@ def create_export_job(task_id, event_id):
     """
     export_job = ExportJob.query.filter_by(event_id=event_id).first()
     task_url = url_for('tasks.celery_task', task_id=task_id)
+    current_logged_user = get_current_user()
+
     if export_job:
 
         export_job.task = task_url
-        export_job.user_email = current_user.email
+        export_job.user_email = current_logged_user.email
         export_job.event = Event.query.get(event_id)
         export_job.starts_at = datetime.now(pytz.utc)
     else:
         export_job = ExportJob(
-            task=task_url, user_email=current_identity.email,
+            task=task_url, user_email=current_logged_user.email,
             event=Event.query.get(event_id)
         )
     save_to_db(export_job, 'ExportJob saved')


Test patch: