diff --git a/swh/web/api/urls.py b/swh/web/api/urls.py --- a/swh/web/api/urls.py +++ b/swh/web/api/urls.py @@ -4,6 +4,7 @@ # See top-level LICENSE file for more information from swh.web.api.apiurls import APIUrls +import swh.web.api.views.add_forge_now # noqa import swh.web.api.views.content # noqa import swh.web.api.views.directory # noqa import swh.web.api.views.graph # noqa diff --git a/swh/web/api/views/add_forge_now.py b/swh/web/api/views/add_forge_now.py new file mode 100644 --- /dev/null +++ b/swh/web/api/views/add_forge_now.py @@ -0,0 +1,108 @@ +# Copyright (C) 2022 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU Affero General Public License version 3, or any later version +# See top-level LICENSE file for more information + +import json +from typing import Union + +from django.core.exceptions import ObjectDoesNotExist +from django.forms import ModelForm +from django.http.request import HttpRequest +from django.http.response import HttpResponse, HttpResponseForbidden +from rest_framework import serializers +from rest_framework.request import Request +from rest_framework.response import Response + +from swh.web.add_forge_now.models import Request as AddForgeRequest +from swh.web.api.apidoc import api_doc, format_docstring +from swh.web.api.apiurls import api_route +from swh.web.common.exc import BadInputExc + + +class AddForgeNowRequestForm(ModelForm): + class Meta: + model = AddForgeRequest + fields = ( + "forge_type", + "forge_url", + "forge_contact_email", + "forge_contact_name", + "forge_contact_comment", + ) + + +class AddForgeNowRequestSerializer(serializers.ModelSerializer): + class Meta: + model = AddForgeRequest + fields = "__all__" + + +@api_route( + r"/add-forge/request/create", "api-1-add-forge-request-create", methods=["POST"], +) +@api_doc("/add-forge/request/create") +@format_docstring() +def api_add_forge_request_create(request: Union[HttpRequest, Request]) -> HttpResponse: + """ + .. http:post:: /api/1/add-forge/request/create/ + + Create a new request to add a forge to the list of those crawled regularly + by Software Heritage. + + .. warning:: + That endpoint is not publicly available and requires authentication + in order to be able to request it. + + {common_headers} + + : HttpResponse: @@ -84,6 +85,7 @@ url: URL to check response status_code: expected HTTP status code content_type: expected response content type + request_content_type: content type of request body data: optional POST data Returns: @@ -93,7 +95,7 @@ response=client.post( url, data=data, - content_type="application/json", + content_type=request_content_type, HTTP_ACCEPT=content_type, HTTP_ORIGIN=http_origin, ),