We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Call for Speakers Signup Form: "Don't require this email" possible for everyone
Server issue for [fossasia/open-event-frontend#3506](https://github.com/fossasia/open-event-frontend/issues/3506) 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `app/api/speakers.py`
Content:
```
1 from flask import request
2 from flask_login import current_user
3 from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship
4 from flask_rest_jsonapi.exceptions import ObjectNotFound
5 
6 from app.api.bootstrap import api
7 from app.api.helpers.db import safe_query, get_count, save_to_db
8 from app.api.helpers.exceptions import ForbiddenException
9 from app.api.helpers.permission_manager import has_access
10 from app.api.helpers.query import event_query
11 from app.api.helpers.utilities import require_relationship
12 from app.api.schema.speakers import SpeakerSchema
13 from app.models import db
14 from app.models.event import Event
15 from app.models.session import Session
16 from app.models.speaker import Speaker
17 from app.models.session_speaker_link import SessionsSpeakersLink
18 from app.models.user import User
19 
20 
21 class SpeakerListPost(ResourceList):
22     """
23     List and create speakers
24     """
25 
26     def before_post(self, args, kwargs, data=None):
27         """
28         method to add user_id to view_kwargs before post
29         :param args:
30         :param kwargs:
31         :param data:
32         :return:
33         """
34         require_relationship(['event', 'user'], data)
35 
36         if not has_access('is_coorganizer', event_id=data['event']):
37             event = db.session.query(Event).filter_by(id=data['event']).one()
38             if event.state == "draft":
39                 raise ObjectNotFound({'parameter': 'event_id'},
40                                      "Event: {} not found".format(data['event_id']))
41 
42         if get_count(db.session.query(Event).filter_by(id=int(data['event']), is_sessions_speakers_enabled=False)) > 0:
43             raise ForbiddenException({'pointer': ''}, "Speakers are disabled for this Event")
44 
45         if not data.get('is_email_overridden') and \
46             get_count(db.session.query(Speaker).filter_by(event_id=int(data['event']), email=data['email'],
47                                                           deleted_at=None)) > 0:
48             raise ForbiddenException({'pointer': ''}, 'Speaker with this Email ID already exists')
49 
50         if data.get('is_email_overriden') and not has_access('is_organizer', event_id=data['event']):
51             raise ForbiddenException({'pointer': 'data/attributes/is_email_overriden'},
52                                      'Organizer access required to override email')
53         elif data.get('is_email_overriden') and has_access('is_organizer', event_id=data['event']) and \
54                 not data.get('email'):
55             data['email'] = current_user.email
56 
57         if 'sessions' in data:
58             session_ids = data['sessions']
59             for session_id in session_ids:
60                 if not has_access('is_session_self_submitted', session_id=session_id):
61                     raise ObjectNotFound({'parameter': 'session_id'},
62                                          "Session: {} not found".format(session_id))
63 
64     def after_create_object(self, speaker, data, view_kwargs):
65         """
66         after create method to save resized images for speaker
67         :param speaker:
68         :param data:
69         :param view_kwargs:
70         :return:
71         """
72 
73         if data.get('photo_url'):
74             start_image_resizing_tasks(speaker, data['photo_url'])
75 
76     schema = SpeakerSchema
77     methods = ['POST', ]
78     data_layer = {'session': db.session,
79                   'model': Speaker,
80                   'methods': {
81                       'after_create_object': after_create_object
82                   }}
83 
84 
85 class SpeakerList(ResourceList):
86     """
87     List speakers based on different params from view_kwargs
88     """
89 
90     def query(self, view_kwargs):
91         """
92         query method for speakers list class
93         :param view_kwargs:
94         :return:
95         """
96         query_ = self.session.query(Speaker)
97         query_ = event_query(self, query_, view_kwargs)
98 
99         if view_kwargs.get('user_id'):
100             user = safe_query(self, User, 'id', view_kwargs['user_id'], 'user_id')
101             query_ = query_.join(User).filter(User.id == user.id)
102 
103         if view_kwargs.get('session_id'):
104             session = safe_query(self, Session, 'id', view_kwargs['session_id'], 'session_id')
105             # session-speaker :: many-to-many relationship
106             query_ = Speaker.query.filter(Speaker.sessions.any(id=session.id))
107             if 'Authorization' in request.headers and not has_access('is_coorganizer', event_id=session.event_id):
108                 if not has_access('is_session_self_submitted', session_id=session.id):
109                     query_ = query_.filter(Session.state == "approved" or Session.state == "accepted")
110 
111         return query_
112 
113     view_kwargs = True
114     schema = SpeakerSchema
115     methods = ['GET', ]
116     data_layer = {'session': db.session,
117                   'model': Speaker,
118                   'methods': {
119                       'query': query,
120                   }}
121 
122 
123 class SpeakerDetail(ResourceDetail):
124     """
125     Speakers Detail by id
126     """
127     def before_update_object(self, speaker, data, view_kwargs):
128         """
129         method to save image urls before updating speaker object
130         :param speaker:
131         :param data:
132         :param view_kwargs:
133         :return:
134         """
135         if data.get('photo_url') and data['photo_url'] != speaker.photo_url:
136             start_image_resizing_tasks(speaker, data['photo_url'])
137 
138         if data.get('is_email_overriden') and not has_access('is_organizer', event_id=speaker.event_id):
139             raise ForbiddenException({'pointer': 'data/attributes/is_email_overriden'},
140                                      'Organizer access required to override email')
141         elif data.get('is_email_overriden') and has_access('is_organizer', event_id=speaker.event_id) and \
142                 not data.get('email'):
143             data['email'] = current_user.email
144 
145     def after_patch(self, result):
146         """
147         method to create session speaker link
148         :param result:
149         """
150         # This method is executed when a new speaker is created
151         # and added to an existing session
152         speaker_id = result['data']['id']
153         speaker = Speaker.query.filter_by(id=speaker_id).first()
154         if SessionsSpeakersLink.query.filter_by(speaker_id=speaker_id).count() == 0:
155             all_sessions = Session.query.filter_by(deleted_at=None)
156             for session in all_sessions:
157                 if speaker in session.speakers:
158                     session_speaker_link = SessionsSpeakersLink(session_state=session.state,
159                                                                 session_id=session.id,
160                                                                 event_id=session.event.id,
161                                                                 speaker_id=speaker.id)
162                     save_to_db(session_speaker_link, "Session Speaker Link Saved")
163 
164     decorators = (api.has_permission('is_speaker_itself_or_admin', methods="PATCH,DELETE", fetch="event_id",
165                                      fetch_as="event_id", model=Speaker),
166                   api.has_permission('is_coorganizer_or_user_itself', methods="PATCH,DELETE", fetch="event_id",
167                                      fetch_as="event_id", model=Speaker),)
168     schema = SpeakerSchema
169     data_layer = {'session': db.session,
170                   'model': Speaker,
171                   'methods': {
172                       'before_update_object': before_update_object
173                   }}
174 
175 
176 class SpeakerRelationshipRequired(ResourceRelationship):
177     """
178     Speaker Relationship class for required entities
179     """
180     decorators = (api.has_permission('is_coorganizer_or_user_itself', methods="PATCH,DELETE", fetch="event_id",
181                                      fetch_as="event_id", model=Speaker),)
182     methods = ['GET', 'PATCH']
183     schema = SpeakerSchema
184     data_layer = {'session': db.session,
185                   'model': Speaker}
186 
187 
188 class SpeakerRelationshipOptional(ResourceRelationship):
189     """
190     Speaker Relationship class
191     """
192     decorators = (api.has_permission('is_coorganizer_or_user_itself', methods="PATCH,DELETE", fetch="event_id",
193                                      fetch_as="event_id", model=Speaker),)
194     schema = SpeakerSchema
195     data_layer = {'session': db.session,
196                   'model': Speaker}
197 
198 
199 def start_image_resizing_tasks(speaker, photo_url):
200     speaker_id = str(speaker.id)
201     from .helpers.tasks import resize_speaker_images_task
202     resize_speaker_images_task.delay(speaker_id, photo_url)
203
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/app/api/speakers.py b/app/api/speakers.py
--- a/app/api/speakers.py
+++ b/app/api/speakers.py
@@ -47,10 +47,10 @@
                                                           deleted_at=None)) > 0:
             raise ForbiddenException({'pointer': ''}, 'Speaker with this Email ID already exists')
 
-        if data.get('is_email_overriden') and not has_access('is_organizer', event_id=data['event']):
-            raise ForbiddenException({'pointer': 'data/attributes/is_email_overriden'},
+        if data.get('is_email_overridden') and not has_access('is_organizer', event_id=data['event']):
+            raise ForbiddenException({'pointer': 'data/attributes/is_email_overridden'},
                                      'Organizer access required to override email')
-        elif data.get('is_email_overriden') and has_access('is_organizer', event_id=data['event']) and \
+        elif data.get('is_email_overridden') and has_access('is_organizer', event_id=data['event']) and \
                 not data.get('email'):
             data['email'] = current_user.email
 
@@ -135,10 +135,10 @@
         if data.get('photo_url') and data['photo_url'] != speaker.photo_url:
             start_image_resizing_tasks(speaker, data['photo_url'])
 
-        if data.get('is_email_overriden') and not has_access('is_organizer', event_id=speaker.event_id):
-            raise ForbiddenException({'pointer': 'data/attributes/is_email_overriden'},
+        if data.get('is_email_overridden') and not has_access('is_organizer', event_id=speaker.event_id):
+            raise ForbiddenException({'pointer': 'data/attributes/is_email_overridden'},
                                      'Organizer access required to override email')
-        elif data.get('is_email_overriden') and has_access('is_organizer', event_id=speaker.event_id) and \
+        elif data.get('is_email_overridden') and has_access('is_organizer', event_id=speaker.event_id) and \
                 not data.get('email'):
             data['email'] = current_user.email

{"golden_diff": "diff --git a/app/api/speakers.py b/app/api/speakers.py\n--- a/app/api/speakers.py\n+++ b/app/api/speakers.py\n@@ -47,10 +47,10 @@\n                                                           deleted_at=None)) > 0:\n             raise ForbiddenException({'pointer': ''}, 'Speaker with this Email ID already exists')\n \n-        if data.get('is_email_overriden') and not has_access('is_organizer', event_id=data['event']):\n-            raise ForbiddenException({'pointer': 'data/attributes/is_email_overriden'},\n+        if data.get('is_email_overridden') and not has_access('is_organizer', event_id=data['event']):\n+            raise ForbiddenException({'pointer': 'data/attributes/is_email_overridden'},\n                                      'Organizer access required to override email')\n-        elif data.get('is_email_overriden') and has_access('is_organizer', event_id=data['event']) and \\\n+        elif data.get('is_email_overridden') and has_access('is_organizer', event_id=data['event']) and \\\n                 not data.get('email'):\n             data['email'] = current_user.email\n \n@@ -135,10 +135,10 @@\n         if data.get('photo_url') and data['photo_url'] != speaker.photo_url:\n             start_image_resizing_tasks(speaker, data['photo_url'])\n \n-        if data.get('is_email_overriden') and not has_access('is_organizer', event_id=speaker.event_id):\n-            raise ForbiddenException({'pointer': 'data/attributes/is_email_overriden'},\n+        if data.get('is_email_overridden') and not has_access('is_organizer', event_id=speaker.event_id):\n+            raise ForbiddenException({'pointer': 'data/attributes/is_email_overridden'},\n                                      'Organizer access required to override email')\n-        elif data.get('is_email_overriden') and has_access('is_organizer', event_id=speaker.event_id) and \\\n+        elif data.get('is_email_overridden') and has_access('is_organizer', event_id=speaker.event_id) and \\\n                 not data.get('email'):\n             data['email'] = current_user.email\n", "issue": "Call for Speakers Signup Form: \"Don't require this email\" possible for everyone\nServer issue for [fossasia/open-event-frontend#3506](https://github.com/fossasia/open-event-frontend/issues/3506) \n", "before_files": [{"content": "from flask import request\nfrom flask_login import current_user\nfrom flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship\nfrom flask_rest_jsonapi.exceptions import ObjectNotFound\n\nfrom app.api.bootstrap import api\nfrom app.api.helpers.db import safe_query, get_count, save_to_db\nfrom app.api.helpers.exceptions import ForbiddenException\nfrom app.api.helpers.permission_manager import has_access\nfrom app.api.helpers.query import event_query\nfrom app.api.helpers.utilities import require_relationship\nfrom app.api.schema.speakers import SpeakerSchema\nfrom app.models import db\nfrom app.models.event import Event\nfrom app.models.session import Session\nfrom app.models.speaker import Speaker\nfrom app.models.session_speaker_link import SessionsSpeakersLink\nfrom app.models.user import User\n\n\nclass SpeakerListPost(ResourceList):\n    \"\"\"\n    List and create speakers\n    \"\"\"\n\n    def before_post(self, args, kwargs, data=None):\n        \"\"\"\n        method to add user_id to view_kwargs before post\n        :param args:\n        :param kwargs:\n        :param data:\n        :return:\n        \"\"\"\n        require_relationship(['event', 'user'], data)\n\n        if not has_access('is_coorganizer', event_id=data['event']):\n            event = db.session.query(Event).filter_by(id=data['event']).one()\n            if event.state == \"draft\":\n                raise ObjectNotFound({'parameter': 'event_id'},\n                                     \"Event: {} not found\".format(data['event_id']))\n\n        if get_count(db.session.query(Event).filter_by(id=int(data['event']), is_sessions_speakers_enabled=False)) > 0:\n            raise ForbiddenException({'pointer': ''}, \"Speakers are disabled for this Event\")\n\n        if not data.get('is_email_overridden') and \\\n            get_count(db.session.query(Speaker).filter_by(event_id=int(data['event']), email=data['email'],\n                                                          deleted_at=None)) > 0:\n            raise ForbiddenException({'pointer': ''}, 'Speaker with this Email ID already exists')\n\n        if data.get('is_email_overriden') and not has_access('is_organizer', event_id=data['event']):\n            raise ForbiddenException({'pointer': 'data/attributes/is_email_overriden'},\n                                     'Organizer access required to override email')\n        elif data.get('is_email_overriden') and has_access('is_organizer', event_id=data['event']) and \\\n                not data.get('email'):\n            data['email'] = current_user.email\n\n        if 'sessions' in data:\n            session_ids = data['sessions']\n            for session_id in session_ids:\n                if not has_access('is_session_self_submitted', session_id=session_id):\n                    raise ObjectNotFound({'parameter': 'session_id'},\n                                         \"Session: {} not found\".format(session_id))\n\n    def after_create_object(self, speaker, data, view_kwargs):\n        \"\"\"\n        after create method to save resized images for speaker\n        :param speaker:\n        :param data:\n        :param view_kwargs:\n        :return:\n        \"\"\"\n\n        if data.get('photo_url'):\n            start_image_resizing_tasks(speaker, data['photo_url'])\n\n    schema = SpeakerSchema\n    methods = ['POST', ]\n    data_layer = {'session': db.session,\n                  'model': Speaker,\n                  'methods': {\n                      'after_create_object': after_create_object\n                  }}\n\n\nclass SpeakerList(ResourceList):\n    \"\"\"\n    List speakers based on different params from view_kwargs\n    \"\"\"\n\n    def query(self, view_kwargs):\n        \"\"\"\n        query method for speakers list class\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        query_ = self.session.query(Speaker)\n        query_ = event_query(self, query_, view_kwargs)\n\n        if view_kwargs.get('user_id'):\n            user = safe_query(self, User, 'id', view_kwargs['user_id'], 'user_id')\n            query_ = query_.join(User).filter(User.id == user.id)\n\n        if view_kwargs.get('session_id'):\n            session = safe_query(self, Session, 'id', view_kwargs['session_id'], 'session_id')\n            # session-speaker :: many-to-many relationship\n            query_ = Speaker.query.filter(Speaker.sessions.any(id=session.id))\n            if 'Authorization' in request.headers and not has_access('is_coorganizer', event_id=session.event_id):\n                if not has_access('is_session_self_submitted', session_id=session.id):\n                    query_ = query_.filter(Session.state == \"approved\" or Session.state == \"accepted\")\n\n        return query_\n\n    view_kwargs = True\n    schema = SpeakerSchema\n    methods = ['GET', ]\n    data_layer = {'session': db.session,\n                  'model': Speaker,\n                  'methods': {\n                      'query': query,\n                  }}\n\n\nclass SpeakerDetail(ResourceDetail):\n    \"\"\"\n    Speakers Detail by id\n    \"\"\"\n    def before_update_object(self, speaker, data, view_kwargs):\n        \"\"\"\n        method to save image urls before updating speaker object\n        :param speaker:\n        :param data:\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        if data.get('photo_url') and data['photo_url'] != speaker.photo_url:\n            start_image_resizing_tasks(speaker, data['photo_url'])\n\n        if data.get('is_email_overriden') and not has_access('is_organizer', event_id=speaker.event_id):\n            raise ForbiddenException({'pointer': 'data/attributes/is_email_overriden'},\n                                     'Organizer access required to override email')\n        elif data.get('is_email_overriden') and has_access('is_organizer', event_id=speaker.event_id) and \\\n                not data.get('email'):\n            data['email'] = current_user.email\n\n    def after_patch(self, result):\n        \"\"\"\n        method to create session speaker link\n        :param result:\n        \"\"\"\n        # This method is executed when a new speaker is created\n        # and added to an existing session\n        speaker_id = result['data']['id']\n        speaker = Speaker.query.filter_by(id=speaker_id).first()\n        if SessionsSpeakersLink.query.filter_by(speaker_id=speaker_id).count() == 0:\n            all_sessions = Session.query.filter_by(deleted_at=None)\n            for session in all_sessions:\n                if speaker in session.speakers:\n                    session_speaker_link = SessionsSpeakersLink(session_state=session.state,\n                                                                session_id=session.id,\n                                                                event_id=session.event.id,\n                                                                speaker_id=speaker.id)\n                    save_to_db(session_speaker_link, \"Session Speaker Link Saved\")\n\n    decorators = (api.has_permission('is_speaker_itself_or_admin', methods=\"PATCH,DELETE\", fetch=\"event_id\",\n                                     fetch_as=\"event_id\", model=Speaker),\n                  api.has_permission('is_coorganizer_or_user_itself', methods=\"PATCH,DELETE\", fetch=\"event_id\",\n                                     fetch_as=\"event_id\", model=Speaker),)\n    schema = SpeakerSchema\n    data_layer = {'session': db.session,\n                  'model': Speaker,\n                  'methods': {\n                      'before_update_object': before_update_object\n                  }}\n\n\nclass SpeakerRelationshipRequired(ResourceRelationship):\n    \"\"\"\n    Speaker Relationship class for required entities\n    \"\"\"\n    decorators = (api.has_permission('is_coorganizer_or_user_itself', methods=\"PATCH,DELETE\", fetch=\"event_id\",\n                                     fetch_as=\"event_id\", model=Speaker),)\n    methods = ['GET', 'PATCH']\n    schema = SpeakerSchema\n    data_layer = {'session': db.session,\n                  'model': Speaker}\n\n\nclass SpeakerRelationshipOptional(ResourceRelationship):\n    \"\"\"\n    Speaker Relationship class\n    \"\"\"\n    decorators = (api.has_permission('is_coorganizer_or_user_itself', methods=\"PATCH,DELETE\", fetch=\"event_id\",\n                                     fetch_as=\"event_id\", model=Speaker),)\n    schema = SpeakerSchema\n    data_layer = {'session': db.session,\n                  'model': Speaker}\n\n\ndef start_image_resizing_tasks(speaker, photo_url):\n    speaker_id = str(speaker.id)\n    from .helpers.tasks import resize_speaker_images_task\n    resize_speaker_images_task.delay(speaker_id, photo_url)\n", "path": "app/api/speakers.py"}], "after_files": [{"content": "from flask import request\nfrom flask_login import current_user\nfrom flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship\nfrom flask_rest_jsonapi.exceptions import ObjectNotFound\n\nfrom app.api.bootstrap import api\nfrom app.api.helpers.db import safe_query, get_count, save_to_db\nfrom app.api.helpers.exceptions import ForbiddenException\nfrom app.api.helpers.permission_manager import has_access\nfrom app.api.helpers.query import event_query\nfrom app.api.helpers.utilities import require_relationship\nfrom app.api.schema.speakers import SpeakerSchema\nfrom app.models import db\nfrom app.models.event import Event\nfrom app.models.session import Session\nfrom app.models.speaker import Speaker\nfrom app.models.session_speaker_link import SessionsSpeakersLink\nfrom app.models.user import User\n\n\nclass SpeakerListPost(ResourceList):\n    \"\"\"\n    List and create speakers\n    \"\"\"\n\n    def before_post(self, args, kwargs, data=None):\n        \"\"\"\n        method to add user_id to view_kwargs before post\n        :param args:\n        :param kwargs:\n        :param data:\n        :return:\n        \"\"\"\n        require_relationship(['event', 'user'], data)\n\n        if not has_access('is_coorganizer', event_id=data['event']):\n            event = db.session.query(Event).filter_by(id=data['event']).one()\n            if event.state == \"draft\":\n                raise ObjectNotFound({'parameter': 'event_id'},\n                                     \"Event: {} not found\".format(data['event_id']))\n\n        if get_count(db.session.query(Event).filter_by(id=int(data['event']), is_sessions_speakers_enabled=False)) > 0:\n            raise ForbiddenException({'pointer': ''}, \"Speakers are disabled for this Event\")\n\n        if not data.get('is_email_overridden') and \\\n            get_count(db.session.query(Speaker).filter_by(event_id=int(data['event']), email=data['email'],\n                                                          deleted_at=None)) > 0:\n            raise ForbiddenException({'pointer': ''}, 'Speaker with this Email ID already exists')\n\n        if data.get('is_email_overridden') and not has_access('is_organizer', event_id=data['event']):\n            raise ForbiddenException({'pointer': 'data/attributes/is_email_overridden'},\n                                     'Organizer access required to override email')\n        elif data.get('is_email_overridden') and has_access('is_organizer', event_id=data['event']) and \\\n                not data.get('email'):\n            data['email'] = current_user.email\n\n        if 'sessions' in data:\n            session_ids = data['sessions']\n            for session_id in session_ids:\n                if not has_access('is_session_self_submitted', session_id=session_id):\n                    raise ObjectNotFound({'parameter': 'session_id'},\n                                         \"Session: {} not found\".format(session_id))\n\n    def after_create_object(self, speaker, data, view_kwargs):\n        \"\"\"\n        after create method to save resized images for speaker\n        :param speaker:\n        :param data:\n        :param view_kwargs:\n        :return:\n        \"\"\"\n\n        if data.get('photo_url'):\n            start_image_resizing_tasks(speaker, data['photo_url'])\n\n    schema = SpeakerSchema\n    methods = ['POST', ]\n    data_layer = {'session': db.session,\n                  'model': Speaker,\n                  'methods': {\n                      'after_create_object': after_create_object\n                  }}\n\n\nclass SpeakerList(ResourceList):\n    \"\"\"\n    List speakers based on different params from view_kwargs\n    \"\"\"\n\n    def query(self, view_kwargs):\n        \"\"\"\n        query method for speakers list class\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        query_ = self.session.query(Speaker)\n        query_ = event_query(self, query_, view_kwargs)\n\n        if view_kwargs.get('user_id'):\n            user = safe_query(self, User, 'id', view_kwargs['user_id'], 'user_id')\n            query_ = query_.join(User).filter(User.id == user.id)\n\n        if view_kwargs.get('session_id'):\n            session = safe_query(self, Session, 'id', view_kwargs['session_id'], 'session_id')\n            # session-speaker :: many-to-many relationship\n            query_ = Speaker.query.filter(Speaker.sessions.any(id=session.id))\n            if 'Authorization' in request.headers and not has_access('is_coorganizer', event_id=session.event_id):\n                if not has_access('is_session_self_submitted', session_id=session.id):\n                    query_ = query_.filter(Session.state == \"approved\" or Session.state == \"accepted\")\n\n        return query_\n\n    view_kwargs = True\n    schema = SpeakerSchema\n    methods = ['GET', ]\n    data_layer = {'session': db.session,\n                  'model': Speaker,\n                  'methods': {\n                      'query': query,\n                  }}\n\n\nclass SpeakerDetail(ResourceDetail):\n    \"\"\"\n    Speakers Detail by id\n    \"\"\"\n    def before_update_object(self, speaker, data, view_kwargs):\n        \"\"\"\n        method to save image urls before updating speaker object\n        :param speaker:\n        :param data:\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        if data.get('photo_url') and data['photo_url'] != speaker.photo_url:\n            start_image_resizing_tasks(speaker, data['photo_url'])\n\n        if data.get('is_email_overridden') and not has_access('is_organizer', event_id=speaker.event_id):\n            raise ForbiddenException({'pointer': 'data/attributes/is_email_overridden'},\n                                     'Organizer access required to override email')\n        elif data.get('is_email_overridden') and has_access('is_organizer', event_id=speaker.event_id) and \\\n                not data.get('email'):\n            data['email'] = current_user.email\n\n    def after_patch(self, result):\n        \"\"\"\n        method to create session speaker link\n        :param result:\n        \"\"\"\n        # This method is executed when a new speaker is created\n        # and added to an existing session\n        speaker_id = result['data']['id']\n        speaker = Speaker.query.filter_by(id=speaker_id).first()\n        if SessionsSpeakersLink.query.filter_by(speaker_id=speaker_id).count() == 0:\n            all_sessions = Session.query.filter_by(deleted_at=None)\n            for session in all_sessions:\n                if speaker in session.speakers:\n                    session_speaker_link = SessionsSpeakersLink(session_state=session.state,\n                                                                session_id=session.id,\n                                                                event_id=session.event.id,\n                                                                speaker_id=speaker.id)\n                    save_to_db(session_speaker_link, \"Session Speaker Link Saved\")\n\n    decorators = (api.has_permission('is_speaker_itself_or_admin', methods=\"PATCH,DELETE\", fetch=\"event_id\",\n                                     fetch_as=\"event_id\", model=Speaker),\n                  api.has_permission('is_coorganizer_or_user_itself', methods=\"PATCH,DELETE\", fetch=\"event_id\",\n                                     fetch_as=\"event_id\", model=Speaker),)\n    schema = SpeakerSchema\n    data_layer = {'session': db.session,\n                  'model': Speaker,\n                  'methods': {\n                      'before_update_object': before_update_object\n                  }}\n\n\nclass SpeakerRelationshipRequired(ResourceRelationship):\n    \"\"\"\n    Speaker Relationship class for required entities\n    \"\"\"\n    decorators = (api.has_permission('is_coorganizer_or_user_itself', methods=\"PATCH,DELETE\", fetch=\"event_id\",\n                                     fetch_as=\"event_id\", model=Speaker),)\n    methods = ['GET', 'PATCH']\n    schema = SpeakerSchema\n    data_layer = {'session': db.session,\n                  'model': Speaker}\n\n\nclass SpeakerRelationshipOptional(ResourceRelationship):\n    \"\"\"\n    Speaker Relationship class\n    \"\"\"\n    decorators = (api.has_permission('is_coorganizer_or_user_itself', methods=\"PATCH,DELETE\", fetch=\"event_id\",\n                                     fetch_as=\"event_id\", model=Speaker),)\n    schema = SpeakerSchema\n    data_layer = {'session': db.session,\n                  'model': Speaker}\n\n\ndef start_image_resizing_tasks(speaker, photo_url):\n    speaker_id = str(speaker.id)\n    from .helpers.tasks import resize_speaker_images_task\n    resize_speaker_images_task.delay(speaker_id, photo_url)\n", "path": "app/api/speakers.py"}]}