api: add proxy wcs trigger api endpoint (#75908)
This commit is contained in:
parent
cddd4635c7
commit
51ad64b477
|
@ -16,7 +16,7 @@
|
|||
|
||||
from django.conf.urls import re_path
|
||||
|
||||
from .views import TrackingCodeView, redirect_crypto_url, tracking_code_search
|
||||
from .views import TrackingCodeView, TriggerProxyView, redirect_crypto_url, tracking_code_search
|
||||
|
||||
urlpatterns = [
|
||||
re_path(r'^tracking-code/$', TrackingCodeView.as_view(), name='wcs-tracking-code'),
|
||||
|
@ -26,4 +26,5 @@ urlpatterns = [
|
|||
redirect_crypto_url,
|
||||
name='wcs-redirect-crypto-url',
|
||||
),
|
||||
re_path(r'^api/wcs/trigger/$', TriggerProxyView.as_view(), name='wcs-trigger-proxy'),
|
||||
]
|
||||
|
|
|
@ -26,6 +26,9 @@ from django.http import HttpResponseBadRequest, HttpResponseForbidden, HttpRespo
|
|||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.generic import View
|
||||
from rest_framework import authentication, permissions
|
||||
from rest_framework.generics import GenericAPIView
|
||||
from rest_framework.response import Response
|
||||
|
||||
from combo.utils import DecryptionError, aes_hex_decrypt, requests, sign_url
|
||||
from combo.utils.misc import get_known_service_for_url, is_url_from_known_service
|
||||
|
@ -154,3 +157,13 @@ def redirect_crypto_url(request, session_key, crypto_url):
|
|||
real_url += '&orig=%s' % service['orig']
|
||||
redirect_url = sign_url(real_url, service['secret'], nonce=False)
|
||||
return HttpResponseRedirect(redirect_url)
|
||||
|
||||
|
||||
class TriggerProxyView(GenericAPIView):
|
||||
permission_classes = (permissions.AllowAny,)
|
||||
authentication_classes = (authentication.SessionAuthentication,)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
trigger_url = request.data['trigger-url']
|
||||
response = requests.post(trigger_url, remote_service='auto', user=request.user)
|
||||
return Response(response.json())
|
||||
|
|
Loading…
Reference in New Issue