22from sqlalchemy .orm .exc import NoResultFound
33
44from app .api .bootstrap import api
5+ from flask import request
56from app .api .helpers .db import safe_query , get_count , save_to_db
67from app .api .helpers .exceptions import ForbiddenException , ConflictException , UnprocessableEntity
78from app .api .helpers .payment import StripePaymentsManager
89from app .api .helpers .permission_manager import has_access
910from app .api .helpers .permissions import jwt_required
1011from app .api .helpers .utilities import require_relationship
11- from app .api .schema .stripe_authorization import StripeAuthorizationSchema
12+ from app .api .schema .stripe_authorization import StripeAuthorizationSchema , StripeAuthorizationSchemaPublic
1213from app .models import db
1314from app .models .event import Event
1415from app .models .stripe_authorization import StripeAuthorization
@@ -69,7 +70,8 @@ def after_create_object(self, stripe_authorization, data, view_kwargs):
6970 save_to_db (event )
7071
7172 schema = StripeAuthorizationSchema
72- decorators = (jwt_required , )
73+ decorators = (api .has_permission ('is_coorganizer' , fetch = "event_id" ,
74+ fetch_as = "event_id" , model = StripeAuthorization ),)
7375 methods = ['POST' ]
7476 data_layer = {'session' : db .session ,
7577 'model' : StripeAuthorization ,
@@ -83,6 +85,20 @@ class StripeAuthorizationDetail(ResourceDetail):
8385 """
8486 Stripe Authorization Detail Resource by ID
8587 """
88+
89+ def before_get (self , args , kwargs ):
90+ """
91+ method for assigning schema based on access
92+ :param args:
93+ :param kwargs:
94+ :return:
95+ """
96+ kwargs = get_id (kwargs )
97+ if 'Authorization' in request .headers and has_access ('is_coorganizer' , event_id = kwargs ['id' ]):
98+ self .schema = StripeAuthorizationSchema
99+ else :
100+ self .schema = StripeAuthorizationSchemaPublic
101+
86102 def before_get_object (self , view_kwargs ):
87103 """
88104 method to get id of stripe authorization related to an event
@@ -107,8 +123,7 @@ def after_delete_object(self, stripe_authorization, view_kwargs):
107123 event .is_stripe_linked = False
108124 save_to_db (event )
109125
110- decorators = (api .has_permission ('is_coorganizer' , fetch = "event_id" ,
111- fetch_as = "event_id" , model = StripeAuthorization ),)
126+ decorators = (jwt_required ,)
112127 schema = StripeAuthorizationSchema
113128 data_layer = {'session' : db .session ,
114129 'model' : StripeAuthorization ,
@@ -123,8 +138,25 @@ class StripeAuthorizationRelationship(ResourceDetail):
123138 Stripe Authorization Relationship
124139 """
125140
126- decorators = (api .has_permission ('is_coorganizer' , fetch = "event_id" ,
127- fetch_as = "event_id" , model = StripeAuthorization ),)
141+ decorators = (jwt_required ,)
128142 schema = StripeAuthorizationSchema
129143 data_layer = {'session' : db .session ,
130144 'model' : StripeAuthorization }
145+
146+
147+ def get_id (view_kwargs ):
148+ """
149+ method to get the resource id for fetching details
150+ :param view_kwargs:
151+ :return:
152+ """
153+
154+ if view_kwargs .get ('event_identifier' ) is not None :
155+ event = safe_query (db , Event , 'identifier' , view_kwargs ['event_identifier' ], 'event_identifier' )
156+ if event .id is not None :
157+ view_kwargs ['event_id' ] = event .id
158+
159+ if view_kwargs .get ('event_id' ) is not None :
160+ stripe_authorization = safe_query (db , StripeAuthorization , 'event_id' , view_kwargs ['event_id' ], 'event_id' )
161+ view_kwargs ['id' ] = stripe_authorization .id
162+ return view_kwargs
0 commit comments