Repository: fossasia/open-event-server

Issue:
Stripe-Authorization: Add related endpoints to docs and dredd tests
Parent issue #4009.


Discussion:

Resolving patch:
diff --git a/app/api/__init__.py b/app/api/__init__.py
--- a/app/api/__init__.py
+++ b/app/api/__init__.py
@@ -1,6 +1,6 @@
 from app.api.bootstrap import api
-from app.api.stripe_authorization import StripeAuthorizationList, StripeAuthorizationDetail, \
-    StripeAuthorizationRelationship, StripeAuthorizationListPost
+from app.api.stripe_authorization import StripeAuthorizationDetail, StripeAuthorizationRelationship, \
+    StripeAuthorizationListPost
 from app.api.ticket_fees import TicketFeeList, TicketFeeDetail
 from app.api.users import UserList, UserDetail, UserRelationship
 from app.api.notifications import NotificationList, NotificationListAdmin, NotificationDetail, NotificationRelationship
@@ -426,8 +426,6 @@
 
 # Stripe Authorization API
 api.route(StripeAuthorizationListPost, 'stripe_authorization_list_post', '/stripe-authorization')
-api.route(StripeAuthorizationList, 'stripe_authorization_list', '/events/<int:event_id>/stripe-authorization',
-          '/events/<event_identifier>/stripe-authorization')
 api.route(StripeAuthorizationDetail, 'stripe_authorization_detail',  '/stripe-authorization/<int:id>',
           '/events/<int:event_id>/stripe-authorization', '/events/<event_identifier>/stripe-authorization')
 api.route(StripeAuthorizationRelationship, 'stripe_authorization_event',
diff --git a/app/api/stripe_authorization.py b/app/api/stripe_authorization.py
--- a/app/api/stripe_authorization.py
+++ b/app/api/stripe_authorization.py
@@ -31,55 +31,42 @@ def before_create_object(self, data, view_kwargs):
             raise ConflictException({'pointer': '/data/relationships/event'},
                                     "Stripe Authorization already exists for this event")
 
-    def before_get(self, args, kwargs):
-        if not has_access('is_super_admin'):
-            raise ForbiddenException({'source': ''}, "Super Admin Access Required")
-
     schema = StripeAuthorizationSchema
     decorators = (jwt_required, )
+    methods = ['POST']
     data_layer = {'session': db.session,
                   'model': StripeAuthorization}
 
 
-class StripeAuthorizationList(ResourceList):
+class StripeAuthorizationDetail(ResourceDetail):
     """
-    Stripe Authorization List Resource
+    Stripe Authorization Detail Resource by ID
     """
+    def before_get_object(self, view_kwargs):
+        """
+        method to get id of stripe authorization related to an event
+        :param view_kwargs:
+        :return:
+        """
+        if view_kwargs.get('event_identifier'):
+            event = safe_query(self, Event, 'identifier', view_kwargs['event_identifier'], 'event_identifier')
+            view_kwargs['event_id'] = event.id
 
-    def query(self, view_kwargs):
-        query_ = self.session.query(StripeAuthorization)
         if view_kwargs.get('event_id'):
-            event = safe_query(self, Event, 'id', view_kwargs['event_id'], 'event_id')
-            query_ = query_.filter_by(event_id=event.id)
-
-        if view_kwargs.get('event_identifier'):
-            event = safe_query(self, Event, 'identifier', view_kwargs['identifier'], 'event_identifier')
-            query_ = query_.filter_by(event_id=event.id)
-        return query_
+            stripe_authorization = self.session.query(StripeAuthorization).\
+                filter_by(event_id=view_kwargs['event_id']).one()
+            view_kwargs['id'] = stripe_authorization.id
 
-    view_kwargs = True
-    methods = ['GET', ]
-    decorators = (api.has_permission('is_organizer', fetch="event_id", fetch_as="event_id"), )
+    decorators = (api.has_permission('is_coorganizer', fetch="event_id",
+                                     fetch_as="event_id", model=StripeAuthorization),)
     schema = StripeAuthorizationSchema
     data_layer = {'session': db.session,
                   'model': StripeAuthorization,
                   'methods': {
-                      'query': query
+                      'before_get_object': before_get_object
                   }}
 
 
-class StripeAuthorizationDetail(ResourceDetail):
-    """
-    Stripe Authorization Detail Resource by ID
-    """
-
-    decorators = (api.has_permission('is_coorganizer', fetch="event_id",
-                                     fetch_as="event_id", model=StripeAuthorization),)
-    schema = StripeAuthorizationSchema
-    data_layer = {'session': db.session,
-                  'model': StripeAuthorization}
-
-
 class StripeAuthorizationRelationship(ResourceDetail):
     """
     Stripe Authorization Relationship


Test patch:
diff --git a/tests/hook_main.py b/tests/hook_main.py
--- a/tests/hook_main.py
+++ b/tests/hook_main.py
@@ -3027,23 +3027,10 @@ def user_permission_delete(transaction):
 
 
 # ------------------------- Stripe Authorizations -------------------------
-@hooks.before("StripeAuthorization > StripeAuthorization Collection > List all Stripe Authorizations")
-def stripe_authorization_get_list(transaction):
-    """
-    GET /events/1/stripe
-    :param transaction:
-    :return:
-    """
-    with stash['app'].app_context():
-        stripe = StripeAuthorizationFactory()
-        db.session.add(stripe)
-        db.session.commit()
-
-
 @hooks.before("StripeAuthorization > StripeAuthorization Collection > Create Stripe Authorization")
 def stripe_authorization_post(transaction):
     """
-    POST /events/1/stripe
+    POST /stripe-authorization
     :param transaction:
     :return:
     """
@@ -3092,6 +3079,19 @@ def stripe_authorization_delete(transaction):
         db.session.commit()
 
 
+@hooks.before("StripeAuthorization > Stripe Authorization for an Event > Get Stripe Authorization Details of an Event")
+def event_stripe_authorization_get_detail(transaction):
+    """
+    GET /events/1/stripe-authorization
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        stripe = StripeAuthorizationFactory()
+        db.session.add(stripe)
+        db.session.commit()
+
+
 # ------------------------- Export -------------------------
 @hooks.before(
     "Event Export > Start Event Export > Start a Task to Export an Event")