diff --git a/chris_backend/config/settings/local.py b/chris_backend/config/settings/local.py index d391a394..c5828db1 100755 --- a/chris_backend/config/settings/local.py +++ b/chris_backend/config/settings/local.py @@ -155,6 +155,7 @@ COMPUTE_RESOURCE_URL = 'http://pfcon.remote:30005/api/v1/' + # corsheaders # ------------------------------------------------------------------------------ CORS_ALLOW_ALL_ORIGINS = True @@ -204,3 +205,7 @@ 'users.models.CustomLDAPBackend', 'django.contrib.auth.backends.ModelBackend', ) + + +# Setting to enable/disable user creation through an API endpoint +DISABLE_USER_ACCOUNT_CREATION = False diff --git a/chris_backend/config/settings/production.py b/chris_backend/config/settings/production.py index 3ea8d946..7420cabb 100755 --- a/chris_backend/config/settings/production.py +++ b/chris_backend/config/settings/production.py @@ -181,3 +181,7 @@ def get_secret(setting, secret_type=env): 'users.models.CustomLDAPBackend', 'django.contrib.auth.backends.ModelBackend', ) + + +# ENABLE/DISABLE USER CREATION THROUGH AN API ENDPOINT +DISABLE_USER_ACCOUNT_CREATION = get_secret('DISABLE_USER_ACCOUNT_CREATION', env.bool) diff --git a/chris_backend/users/views.py b/chris_backend/users/views.py index 51cdf29c..49e47fac 100755 --- a/chris_backend/users/views.py +++ b/chris_backend/users/views.py @@ -1,6 +1,7 @@ from django.contrib.auth.models import User, Group from django.shortcuts import get_object_or_404 +from django.conf import settings from rest_framework import generics, permissions, serializers from rest_framework.reverse import reverse from rest_framework.response import Response @@ -13,7 +14,8 @@ class UserCreate(generics.ListCreateAPIView): - http_method_names = ['get', 'post'] + http_method_names = ['get'] if settings.DISABLE_USER_ACCOUNT_CREATION else ['get', + 'post'] queryset = User.objects.all() serializer_class = UserSerializer @@ -22,6 +24,10 @@ def list(self, request, *args, **kwargs): Overriden to append a collection+json write template. """ response = services.get_list_response(self, []) + + if settings.DISABLE_USER_ACCOUNT_CREATION: + return response + template_data = {"username": "", "password": "", "email": ""} return services.append_collection_template(response, template_data)