From 80780d206dedfbb072f4fc40ff43127c71b7e07a Mon Sep 17 00:00:00 2001 From: Eric Park Date: Fri, 30 Dec 2022 23:08:38 +0900 Subject: [PATCH] api: add endpoint to list all maintainer details --- api/urls.py | 6 ++++++ api/views/__init__.py | 2 +- api/views/general.py | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/api/urls.py b/api/urls.py index c0cdaf2b..47924531 100644 --- a/api/urls.py +++ b/api/urls.py @@ -4,6 +4,7 @@ V1DownloadBuildCounter, V1GeneralBuildLatest, V1GeneralDeviceAll, + V1GeneralMaintainerAll, V1MaintainersChunkedUpload, V1UpdaterLOS, v1_download_count_all, @@ -74,6 +75,11 @@ V1GeneralDeviceAll.as_view(), name="v1_general_device_all", ), + path( + "v1/general/maintainer/all/", + V1GeneralMaintainerAll.as_view(), + name="v1_general_maintainer_all", + ), path( "v1/general/build/latest///", V1GeneralBuildLatest.as_view(), diff --git a/api/views/__init__.py b/api/views/__init__.py index d1750479..bfce3cc3 100644 --- a/api/views/__init__.py +++ b/api/views/__init__.py @@ -1,4 +1,4 @@ -from .general import V1GeneralBuildLatest, V1GeneralDeviceAll +from .general import V1GeneralBuildLatest, V1GeneralDeviceAll, V1GeneralMaintainerAll from .shippy import ( V1MaintainersChunkedUpload, v1_maintainers_build_enabled_status_modify, diff --git a/api/views/general.py b/api/views/general.py index fe791b77..0e3c11f3 100644 --- a/api/views/general.py +++ b/api/views/general.py @@ -1,6 +1,8 @@ import ast import html +from django.contrib.auth import get_user_model + from api.utils import variant_check from constance import config from django.http import Http404 @@ -12,6 +14,8 @@ from core.models import Build, Device +User = get_user_model() + class V1GeneralDeviceAll(APIView): """ General endpoint to list all devices in shipper @@ -38,6 +42,28 @@ def get(self, request): return Response(return_json, status=HTTP_200_OK) +class V1GeneralMaintainerAll(APIView): + """ + General endpoint to list all maintainer information registered with shipper + """ + + permission_classes = [AllowAny] + + # noinspection PyMethodMayBeStatic + def get(self, request): + return_json = {} + for user in User.objects.all(): + return_json[user.username] = { + "name": user.get_full_name(), + "bio": user.bio, + "profile_picture": user.profile_picture, + "contact_url": user.contact_url, + "devices": [device.codename for device in user.devices.all()], + } + + return Response(return_json, status=HTTP_200_OK) + + class V1GeneralBuildLatest(APIView): """ General endpoint for build information