Add asset restriction webhook API

This commit is contained in:
Mark Veidemanis 2023-02-10 22:04:01 +00:00
parent aa227c53ac
commit c283c6c192
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
5 changed files with 28 additions and 3 deletions

View File

@ -74,6 +74,11 @@ urlpatterns = [
path( path(
f"{settings.HOOK_PATH}/<str:hook_name>/", hooks.HookAPI.as_view(), name="hook" f"{settings.HOOK_PATH}/<str:hook_name>/", hooks.HookAPI.as_view(), name="hook"
), ),
path(
f"{settings.ASSET_PATH}/<str:webhook_id>/",
assets.AssetRestrictionAPI.as_view(),
name="asset",
),
path("signals/<str:type>/", signals.SignalList.as_view(), name="signals"), path("signals/<str:type>/", signals.SignalList.as_view(), name="signals"),
path( path(
"signals/<str:type>/create/", "signals/<str:type>/create/",

View File

@ -1,8 +1,9 @@
# Generated by Django 4.1.6 on 2023-02-10 21:07 # Generated by Django 4.1.6 on 2023-02-10 21:07
from django.db import migrations, models
import uuid import uuid
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -28,7 +28,7 @@
<td> <td>
<a <a
class="has-text-grey" class="has-text-grey"
onclick="window.prompt('Copy to clipboard: Ctrl+C, Enter', '{{settings.URL}}/{{settings.ASSET_PATH}}/{{ item.webhook_id }}');"> onclick="window.prompt('Copy to clipboard: Ctrl+C, Enter', '{{settings.URL}}/{{settings.ASSET_PATH}}/{{ item.webhook_id }}/');">
<span class="icon" data-tooltip="Copy to clipboard"> <span class="icon" data-tooltip="Copy to clipboard">
<i class="fa-solid fa-copy" aria-hidden="true"></i> <i class="fa-solid fa-copy" aria-hidden="true"></i>
</span> </span>

View File

@ -23,7 +23,7 @@
<td> <td>
<a <a
class="has-text-grey" class="has-text-grey"
onclick="window.prompt('Copy to clipboard: Ctrl+C, Enter', '{{settings.URL}}/{{settings.HOOK_PATH}}/{{ item.hook }}');"> onclick="window.prompt('Copy to clipboard: Ctrl+C, Enter', '{{settings.URL}}/{{settings.HOOK_PATH}}/{{ item.hook }}/');">
<span class="icon" data-tooltip="Copy to clipboard"> <span class="icon" data-tooltip="Copy to clipboard">
<i class="fa-solid fa-copy" aria-hidden="true"></i> <i class="fa-solid fa-copy" aria-hidden="true"></i>
</span> </span>

View File

@ -1,5 +1,9 @@
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponse
from mixins.views import AbortSave, ObjectCreate, ObjectDelete, ObjectList, ObjectUpdate from mixins.views import AbortSave, ObjectCreate, ObjectDelete, ObjectList, ObjectUpdate
from rest_framework import status
from rest_framework.parsers import JSONParser
from rest_framework.views import APIView
from core.forms import AssetGroupForm, AssetRestrictionForm from core.forms import AssetGroupForm, AssetRestrictionForm
from core.models import AssetGroup, AssetRestriction from core.models import AssetGroup, AssetRestriction
@ -99,3 +103,18 @@ class AssetRestrictionDelete(
LoginRequiredMixin, AssetRestrictionsPermissionMixin, ObjectDelete LoginRequiredMixin, AssetRestrictionsPermissionMixin, ObjectDelete
): ):
model = AssetRestriction model = AssetRestriction
class AssetRestrictionAPI(APIView):
parser_classes = [JSONParser]
def post(self, request, webhook_id):
log.debug(f"AssetAPI POST {webhook_id}: {request.data}")
try:
webhook = AssetRestriction.objects.get(webhook_id=webhook_id)
except AssetRestriction.DoesNotExist:
log.error(f"AssetRestriction {webhook_id} does not exist")
return HttpResponse(status=status.HTTP_404_NOT_FOUND)
return HttpResponse(status=status.HTTP_200_OK)