Implement storing asset restriction callbacks

This commit is contained in:
2023-02-10 23:26:30 +00:00
parent c283c6c192
commit 010aba7f81
5 changed files with 78 additions and 8 deletions

View File

@@ -8,6 +8,7 @@ from rest_framework.views import APIView
from core.forms import AssetGroupForm, AssetRestrictionForm
from core.models import AssetGroup, AssetRestriction
from core.util import logs
import json
log = logs.get_logger(__name__)
@@ -109,12 +110,35 @@ class AssetRestrictionAPI(APIView):
parser_classes = [JSONParser]
def post(self, request, webhook_id):
log.debug(f"AssetAPI POST {webhook_id}: {request.data}")
# log.debug(f"AssetAPI POST {webhook_id}: {request.data}")
print(json.dumps(request.data, indent=2))
try:
webhook = AssetRestriction.objects.get(webhook_id=webhook_id)
restriction = AssetRestriction.objects.get(webhook_id=webhook_id)
except AssetRestriction.DoesNotExist:
log.error(f"AssetRestriction {webhook_id} does not exist")
log.error(f"Asset restriction {webhook_id} does not exist")
return HttpResponse(status=status.HTTP_404_NOT_FOUND)
return HttpResponse(status=status.HTTP_200_OK)
if restriction.group is not None:
group = restriction.group
else:
log.error(f"Asset restriction {restriction} has no group")
return HttpResponse(status=status.HTTP_404_NOT_FOUND)
# if group.strategy_set.exists() is not None:
# strategies = group.strategy_set.all()
# else:
# log.error(f"Asset group {group} has no strategy")
# return HttpResponse(status=status.HTTP_404_NOT_FOUND)
# log.debug(f"Asset API {webhook_id} matched to strategies {strategies}")
if "meta" in request.data:
if "is_match" in request.data["meta"]:
is_match = request.data["meta"]["is_match"]
if isinstance(restriction.pairs_parsed, list):
for pair in restriction.pairs_parsed:
group.allowed[pair] = is_match
group.save()
return HttpResponse(status=status.HTTP_200_OK)
return HttpResponse(status=status.HTTP_400_BAD_REQUEST)