Skip to content

Commit 001a0c7

Browse files
authored
[fix] Added CSV batch download endpoint to REST API docs #373
Closes #373
1 parent 2646a5c commit 001a0c7

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

docs/user/rest-api.rst

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -861,16 +861,13 @@ Batch CSV Download
861861

862862
.. code-block:: text
863863
864-
/api/v1/radius/organization/<organization-slug>/batch/<id>/csv/<filename>
864+
/api/v1/radius/organization/<organization-slug>/batch/<id>/csv/
865865
866-
Responds only to **GET**.
866+
Responds only to **GET**. Allows downloading the CSV file used to import
867+
users for a specific batch user creation operation. Example:
867868

868-
Parameters:
869+
.. code-block:: shell
869870
870-
======== ===========
871-
Param Description
872-
======== ===========
873-
slug string
874-
id string
875-
filename string
876-
======== ===========
871+
curl -X GET \
872+
'http://127.0.0.1:8000/api/v1/radius/organization/default/batch/f4943c8a-462e-40ba-89b6-91a2541c9cf4/csv/' \
873+
-H 'Authorization: Bearer your-token-here'

openwisp_radius/private_storage/urls.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88

99
def get_private_store_urls():
1010
return [
11+
path(
12+
urljoin(
13+
app_settings.CSV_URL_PATH,
14+
"<slug:slug>/batch/<uuid:pk>/csv/",
15+
),
16+
views.rad_batch_csv_download_api_view,
17+
name="radius_organization_batch_csv_read",
18+
),
1119
path(
1220
# Use "path" URL kwarg to make it consistent with
1321
# django-private-storage. Otherwise, the S3 reverse
@@ -16,5 +24,5 @@ def get_private_store_urls():
1624
urljoin(app_settings.CSV_URL_PATH, "<path:path>"),
1725
views.rad_batch_csv_download_view,
1826
name="serve_private_file",
19-
)
27+
),
2028
]

openwisp_radius/private_storage/views.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
from django.utils.translation import gettext_lazy as _
2+
from drf_yasg import openapi
3+
from drf_yasg.utils import swagger_auto_schema
14
from private_storage.views import PrivateStorageDetailView
5+
from rest_framework.views import APIView
26

37
from ..settings import PRIVATE_STORAGE_INSTANCE
48
from ..utils import load_model
@@ -10,6 +14,7 @@ class RadiusBatchCsvDownloadView(PrivateStorageDetailView):
1014
model_file_field = "csvfile"
1115
slug_field = "csvfile"
1216
slug_url_kwarg = "path"
17+
pk_url_kwarg = "pk"
1318

1419
def can_access_file(self, private_file):
1520
user = private_file.request.user
@@ -19,3 +24,24 @@ def can_access_file(self, private_file):
1924

2025

2126
rad_batch_csv_download_view = RadiusBatchCsvDownloadView.as_view()
27+
28+
29+
class RadiusBatchCsvDownloadAPIView(APIView):
30+
@swagger_auto_schema(
31+
operation_id="radius_organization_batch_csv_read",
32+
operation_description=_(
33+
"Allows downloading the CSV file used to import users for a "
34+
"specific batch user creation operation."
35+
),
36+
responses={
37+
200: openapi.Response(
38+
description=_("CSV file"), schema=openapi.Schema(type=openapi.TYPE_FILE)
39+
),
40+
},
41+
tags=["radius"],
42+
)
43+
def get(self, request, _slug, pk, *args, **kwargs):
44+
return rad_batch_csv_download_view(request, pk=pk, **kwargs)
45+
46+
47+
rad_batch_csv_download_api_view = RadiusBatchCsvDownloadAPIView.as_view()

0 commit comments

Comments
 (0)