diff --git a/cms/settings.py b/cms/settings.py index 075c2518..c6205cd5 100644 --- a/cms/settings.py +++ b/cms/settings.py @@ -498,6 +498,9 @@ ALLOW_VIDEO_TRIMMER = True ALLOW_CUSTOM_MEDIA_URLS = False +# Whether to allow anonymous users to list all users +ALLOW_ANONYMOUS_USER_LISTING = True + # ffmpeg options FFMPEG_DEFAULT_PRESET = "medium" # see https://trac.ffmpeg.org/wiki/Encode/H.264 diff --git a/docs/admins_docs.md b/docs/admins_docs.md index fc353855..b9de5704 100644 --- a/docs/admins_docs.md +++ b/docs/admins_docs.md @@ -500,6 +500,16 @@ By default `CAN_COMMENT = "all"` means that all registered users can add comment - **advancedUser**, only users that are marked as advanced users can add comment. Admins or MediaCMS managers can make users advanced users by editing their profile and selecting advancedUser. +### 5.26 Control whether anonymous users can list all users + +By default, anonymous users can view the list of all users on the platform. To restrict this to authenticated users only, set: + +``` +ALLOW_ANONYMOUS_USER_LISTING = False +``` + +When set to False, only logged-in users will be able to access the user listing API endpoint. + ## 6. Manage pages to be written diff --git a/users/views.py b/users/views.py index 61dbf8fe..355aee31 100644 --- a/users/views.py +++ b/users/views.py @@ -188,8 +188,12 @@ Sender email: %s\n class UserList(APIView): - permission_classes = (permissions.IsAuthenticatedOrReadOnly,) parser_classes = (JSONParser, MultiPartParser, FormParser, FileUploadParser) + + def get_permissions(self): + if not settings.ALLOW_ANONYMOUS_USER_LISTING: + return [permissions.IsAuthenticated()] + return [permissions.IsAuthenticatedOrReadOnly()] @swagger_auto_schema( manual_parameters=[