forked from CGM_Public/pretix_original
* Add require_live flag to event_view decorator Refs #330 * Use new require_live flag in stripe webhook
This commit is contained in:
committed by
Raphael Michel
parent
9bce339575
commit
7a8493cae3
@@ -84,13 +84,14 @@ view if you want pretix's default behavior::
|
|||||||
from pretix.presale.utils import event_view
|
from pretix.presale.utils import event_view
|
||||||
|
|
||||||
@event_view
|
@event_view
|
||||||
def event_view(request, *args, **kwargs):
|
def some_event_view(request, *args, **kwargs):
|
||||||
...
|
...
|
||||||
|
|
||||||
This decorator will check the URL arguments for their ``event`` and ``organizer`` parameters and
|
This decorator will check the URL arguments for their ``event`` and ``organizer`` parameters and
|
||||||
correctly ensure that:
|
correctly ensure that:
|
||||||
|
|
||||||
* The requested event exists and is activated
|
* The requested event exists
|
||||||
|
* The requested event is activated (can be overridden by decorating with ``@event_view(require_live=False)``)
|
||||||
* The event is accessed via the domain it should be accessed
|
* The event is accessed via the domain it should be accessed
|
||||||
* The ``request.event`` attribute contains the correct ``Event`` object
|
* The ``request.event`` attribute contains the correct ``Event`` object
|
||||||
* The ``request.organizer`` attribute contains the correct ``Organizer`` object
|
* The ``request.organizer`` attribute contains the correct ``Organizer`` object
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ logger = logging.getLogger('pretix.plugins.stripe')
|
|||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
@require_POST
|
@require_POST
|
||||||
@event_view
|
@event_view(require_live=False)
|
||||||
def webhook(request, *args, **kwargs):
|
def webhook(request, *args, **kwargs):
|
||||||
event_json = json.loads(request.body.decode('utf-8'))
|
event_json = json.loads(request.body.decode('utf-8'))
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ from pretix.multidomain.urlreverse import get_domain
|
|||||||
from pretix.presale.signals import process_request, process_response
|
from pretix.presale.signals import process_request, process_response
|
||||||
|
|
||||||
|
|
||||||
def _detect_event(request):
|
def _detect_event(request, require_live=True):
|
||||||
url = resolve(request.path_info)
|
url = resolve(request.path_info)
|
||||||
try:
|
try:
|
||||||
if hasattr(request, 'organizer'):
|
if hasattr(request, 'organizer'):
|
||||||
@@ -58,7 +58,7 @@ def _detect_event(request):
|
|||||||
# Restrict locales to the ones available for this event
|
# Restrict locales to the ones available for this event
|
||||||
LocaleMiddleware().process_request(request)
|
LocaleMiddleware().process_request(request)
|
||||||
|
|
||||||
if not request.event.live:
|
if require_live and not request.event.live:
|
||||||
if not request.user.is_authenticated or not EventPermission.objects.filter(
|
if not request.user.is_authenticated or not EventPermission.objects.filter(
|
||||||
event=request.event, user=request.user).exists():
|
event=request.event, user=request.user).exists():
|
||||||
raise PermissionDenied(_('The selected ticket shop is currently not available.'))
|
raise PermissionDenied(_('The selected ticket shop is currently not available.'))
|
||||||
@@ -73,9 +73,10 @@ def _detect_event(request):
|
|||||||
raise Http404(_('The selected organizer was not found.'))
|
raise Http404(_('The selected organizer was not found.'))
|
||||||
|
|
||||||
|
|
||||||
def event_view(func):
|
def event_view(function=None, require_live=True):
|
||||||
|
def event_view_wrapper(func, require_live=require_live):
|
||||||
def wrap(request, *args, **kwargs):
|
def wrap(request, *args, **kwargs):
|
||||||
ret = _detect_event(request)
|
ret = _detect_event(request, require_live=require_live)
|
||||||
if ret:
|
if ret:
|
||||||
return ret
|
return ret
|
||||||
else:
|
else:
|
||||||
@@ -84,3 +85,7 @@ def event_view(func):
|
|||||||
response = r
|
response = r
|
||||||
return response
|
return response
|
||||||
return wrap
|
return wrap
|
||||||
|
|
||||||
|
if function:
|
||||||
|
return event_view_wrapper(function, require_live=require_live)
|
||||||
|
return event_view_wrapper
|
||||||
|
|||||||
Reference in New Issue
Block a user