Repository: fossasia/open-event-server

Issue:
Speakers-call: add seperate resource list class for direct endpoints
parent issue: #4101 


Discussion:
Hi @shubham-padia!

Looks like you're missing some information we'll need to replicate this issue.

The easier it is for us to decipher an issue with the info provided,
the more likely it is that we'll be able to help.

Please make sure you have the following information in this issue:

1. The current (incorrect) behavior you're seeing.
2. The behavior you expect.
3. The OS version, browser, app, device you use.
4. A [short, self-contained example](http://sscce.org/).

Resolving patch:
diff --git a/app/api/__init__.py b/app/api/__init__.py
--- a/app/api/__init__.py
+++ b/app/api/__init__.py
@@ -233,8 +233,7 @@
 api.route(TrackRelationshipRequired, 'track_event', '/tracks/<int:id>/relationships/event')
 
 # speakers_calls
-api.route(SpeakersCallList, 'speakers_call_list', '/speakers-calls', '/events/<int:event_id>/speakers-call',
-          '/events/<event_identifier>/speakers-call')
+api.route(SpeakersCallList, 'speakers_call_list', '/speakers-calls')
 api.route(SpeakersCallDetail, 'speakers_call_detail', '/speakers-calls/<int:id>',
           '/events/<int:event_id>/speakers-call', '/events/<event_identifier>/speakers-call')
 api.route(SpeakersCallRelationship, 'speakers_call_event',
diff --git a/app/api/speakers_calls.py b/app/api/speakers_calls.py
--- a/app/api/speakers_calls.py
+++ b/app/api/speakers_calls.py
@@ -7,14 +7,14 @@
 from flask_rest_jsonapi.exceptions import ObjectNotFound
 
 from app.api.bootstrap import api
-from app.api.helpers.db import safe_query
 from app.api.helpers.utilities import dasherize
 from app.models import db
-from app.api.helpers.permissions import jwt_required
 from app.models.event import Event
 from app.api.helpers.exceptions import UnprocessableEntity
 from app.models.speakers_call import SpeakersCall
 from app.api.helpers.utilities import require_relationship
+from app.api.helpers.permission_manager import has_access
+from app.api.helpers.exceptions import ForbiddenException
 
 
 class SpeakersCallSchema(Schema):
@@ -65,33 +65,13 @@ class SpeakersCallList(ResourceList):
     """
     def before_post(self, args, kwargs, data):
         require_relationship(['event'], data)
+        if not has_access('is_coorganizer', event_id=data['event']):
+            raise ForbiddenException({'source': ''}, 'Co-organizer access is required.')
 
-    def before_create_object(self, data, view_kwargs):
-        event = None
-        if view_kwargs.get('event_id'):
-            event = safe_query(self, Event, 'id', view_kwargs['event_id'], 'event_id')
-        elif view_kwargs.get('event_identifier'):
-            event = safe_query(self, Event, 'identifier', view_kwargs['event_identifier'], 'event_identifier')
-        if event:
-            data['event_id'] = event.id
-
-        try:
-            self.session.query(SpeakersCall).filter_by(event_id=data['event_id']).one()
-        except NoResultFound:
-            pass
-        else:
-            raise UnprocessableEntity({'source': 'event_identifier'},
-                                      "SpeakersCall already exists for the provided Event ID")
-
-    view_kwargs = True
-    decorators = (api.has_permission('is_coorganizer', fetch="event_id", fetch_as="event_id"),)
     schema = SpeakersCallSchema
     methods = ['POST', ]
     data_layer = {'session': db.session,
-                  'model': SpeakersCall,
-                  'methods': {
-                      'before_create_object': before_create_object
-                  }}
+                  'model': SpeakersCall}
 
 
 class SpeakersCallDetail(ResourceDetail):
diff --git a/app/api/sponsors.py b/app/api/sponsors.py
--- a/app/api/sponsors.py
+++ b/app/api/sponsors.py
@@ -5,7 +5,6 @@
 from flask import request
 
 from app.api.helpers.utilities import dasherize
-from app.api.helpers.permissions import jwt_required
 from app.models import db
 from app.models.sponsor import Sponsor
 from app.models.event import Event


Test patch:
diff --git a/tests/hook_main.py b/tests/hook_main.py
--- a/tests/hook_main.py
+++ b/tests/hook_main.py
@@ -762,9 +762,6 @@ def speakers_call_post(transaction):
     :param transaction:
     :return:
     """
-    # Skip until docs for direct endpoints added
-    transaction['skip'] = True
-
     with stash['app'].app_context():
         event = EventFactoryBasic()
         db.session.add(event)