mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-24 07:19:36 +02:00
Add users get and list views
This commit is contained in:
parent
711b974add
commit
ee249fd682
3 changed files with 41 additions and 3 deletions
|
@ -4,7 +4,7 @@ from django.views.generic import RedirectView, TemplateView
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.conf.urls.static import static
|
from django.conf.urls.static import static
|
||||||
from adventures import urls as adventures
|
from adventures import urls as adventures
|
||||||
from users.views import ChangeEmailView, IsRegistrationDisabled
|
from users.views import ChangeEmailView, IsRegistrationDisabled, PublicUserListView, PublicUserDetailView
|
||||||
from .views import get_csrf_token
|
from .views import get_csrf_token
|
||||||
from drf_yasg.views import get_schema_view
|
from drf_yasg.views import get_schema_view
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@ urlpatterns = [
|
||||||
|
|
||||||
path('auth/change-email/', ChangeEmailView.as_view(), name='change_email'),
|
path('auth/change-email/', ChangeEmailView.as_view(), name='change_email'),
|
||||||
path('auth/is-registration-disabled/', IsRegistrationDisabled.as_view(), name='is_registration_disabled'),
|
path('auth/is-registration-disabled/', IsRegistrationDisabled.as_view(), name='is_registration_disabled'),
|
||||||
|
path('auth/users', PublicUserListView.as_view(), name='public-user-list'),
|
||||||
|
path('auth/user/<uuid:user_id>', PublicUserDetailView.as_view(), name='public-user-detail'),
|
||||||
|
|
||||||
path('csrf/', get_csrf_token, name='get_csrf_token'),
|
path('csrf/', get_csrf_token, name='get_csrf_token'),
|
||||||
re_path(r'^$', TemplateView.as_view(
|
re_path(r'^$', TemplateView.as_view(
|
||||||
|
|
|
@ -174,7 +174,7 @@ class CustomUserDetailsSerializer(UserDetailsSerializer):
|
||||||
|
|
||||||
class Meta(UserDetailsSerializer.Meta):
|
class Meta(UserDetailsSerializer.Meta):
|
||||||
model = CustomUser
|
model = CustomUser
|
||||||
fields = UserDetailsSerializer.Meta.fields + ('profile_pic',)
|
fields = UserDetailsSerializer.Meta.fields + ('profile_pic', 'uuid', 'public_profile')
|
||||||
|
|
||||||
def to_representation(self, instance):
|
def to_representation(self, instance):
|
||||||
representation = super().to_representation(instance)
|
representation = super().to_representation(instance)
|
||||||
|
|
|
@ -6,6 +6,11 @@ from .serializers import ChangeEmailSerializer
|
||||||
from drf_yasg.utils import swagger_auto_schema
|
from drf_yasg.utils import swagger_auto_schema
|
||||||
from drf_yasg import openapi
|
from drf_yasg import openapi
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from .serializers import CustomUserDetailsSerializer as PublicUserSerializer
|
||||||
|
|
||||||
|
User = get_user_model()
|
||||||
|
|
||||||
class ChangeEmailView(APIView):
|
class ChangeEmailView(APIView):
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
|
@ -42,3 +47,34 @@ class IsRegistrationDisabled(APIView):
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
return Response({"is_disabled": settings.DISABLE_REGISTRATION, "message": settings.DISABLE_REGISTRATION_MESSAGE}, status=status.HTTP_200_OK)
|
return Response({"is_disabled": settings.DISABLE_REGISTRATION, "message": settings.DISABLE_REGISTRATION_MESSAGE}, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
class PublicUserListView(APIView):
|
||||||
|
# Allow the listing of all public users
|
||||||
|
permission_classes = []
|
||||||
|
|
||||||
|
@swagger_auto_schema(
|
||||||
|
responses={
|
||||||
|
200: openapi.Response('List of public users'),
|
||||||
|
400: 'Bad Request'
|
||||||
|
},
|
||||||
|
operation_description="List public users."
|
||||||
|
)
|
||||||
|
def get(self, request):
|
||||||
|
users = User.objects.filter(public_profile=True).exclude(id=request.user.id)
|
||||||
|
serializer = PublicUserSerializer(users, many=True)
|
||||||
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
class PublicUserDetailView(APIView):
|
||||||
|
# Allow the retrieval of a single public user
|
||||||
|
permission_classes = []
|
||||||
|
|
||||||
|
@swagger_auto_schema(
|
||||||
|
responses={
|
||||||
|
200: openapi.Response('Public user information'),
|
||||||
|
400: 'Bad Request'
|
||||||
|
},
|
||||||
|
operation_description="Get public user information."
|
||||||
|
)
|
||||||
|
def get(self, request, user_id):
|
||||||
|
user = get_object_or_404(User, uuid=user_id, public_profile=True)
|
||||||
|
serializer = PublicUserSerializer(user)
|
||||||
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue