Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/origin_save.py
# Copyright (C) 2018-2019 The Software Heritage developers | # Copyright (C) 2018-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from swh.web.api.apidoc import api_doc, format_docstring | from swh.web.api.apidoc import api_doc, format_docstring | ||||
from swh.web.api.apiurls import api_route | from swh.web.api.apiurls import api_route | ||||
from swh.web.auth.utils import SWH_AMBASSADOR_PERMISSION | |||||
from swh.web.common.origin_save import ( | from swh.web.common.origin_save import ( | ||||
create_save_origin_request, | create_save_origin_request, | ||||
get_save_origin_requests, | get_save_origin_requests, | ||||
) | ) | ||||
@api_route( | @api_route( | ||||
r"/origin/save/(?P<visit_type>.+)/url/(?P<origin_url>.+)/", | r"/origin/save/(?P<visit_type>.+)/url/(?P<origin_url>.+)/", | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | .. http:post:: /api/1/origin/save/(visit_type)/url/(origin_url)/ | ||||
:statuscode 200: no error | :statuscode 200: no error | ||||
:statuscode 400: an invalid visit type or origin url has been provided | :statuscode 400: an invalid visit type or origin url has been provided | ||||
:statuscode 403: the provided origin url is blacklisted | :statuscode 403: the provided origin url is blacklisted | ||||
:statuscode 404: no save requests have been found for a given origin | :statuscode 404: no save requests have been found for a given origin | ||||
""" | """ | ||||
if request.method == "POST": | if request.method == "POST": | ||||
sor = create_save_origin_request(visit_type, origin_url) | bypass_pending_review = request.user.is_authenticated and request.user.has_perm( | ||||
SWH_AMBASSADOR_PERMISSION | |||||
) | |||||
sor = create_save_origin_request(visit_type, origin_url, bypass_pending_review) | |||||
del sor["id"] | del sor["id"] | ||||
else: | else: | ||||
sor = get_save_origin_requests(visit_type, origin_url) | sor = get_save_origin_requests(visit_type, origin_url) | ||||
for s in sor: | for s in sor: | ||||
del s["id"] | del s["id"] | ||||
return sor | return sor |