We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Impossible to create a learner account on a second (imported) facility?
## Observed behavior
I managed to replicate this on 2 separate Android devices. My Windows 7 server device has 2 facilities, one created during the server setup (**Win7new**), and the second one imported from another VM (**imported-from-Win11**). This second one has several classes, and I have been using it exclusively during this past week. 

1. At first I tried to create a new learner account from the Huawei Android 8 tablet on the second facility, and got an error (_Whoops!_). I retried and the field validation was saying ``Username already exists``, which did not make sense, since I searched users on that second facility on the server VM and the username I was trying to create was not there. I moved on, imported another user and went on testing something else.
2. Some times after I was setting up another LoD (on the Motorola phone), tried again to create (not import) a new user on the second facility, and got the same message that the ``Username already exists``. After the initial confusion I had a hunch and went to check the first facility (the one I never really used for class interactions during this testing), and lo and behold, the user I was trying to create did exist there, probably from the above setup on Huawei tablet. And this is not my fat finger miss-touching the wrong radio button during the facility selection, it actually seems that the option to create a new user is somehow _bound_ to the first facility on the device, and would not _obey_ the user's selection of the second facility.

LoD | Win7 facility users | imported-from-Win11 facility users
-- | -- | --
![2024_02_02_00 48 43](https://github.com/learningequality/kolibri/assets/1457929/12ff9470-914b-4d3a-aed5-fe5720075a70) | ![2024-02-02_00-49-04](https://github.com/learningequality/kolibri/assets/1457929/3c01cd95-e57b-4ad8-a390-37cdcbab757e) | ![2024-02-02_00-49-46](https://github.com/learningequality/kolibri/assets/1457929/0c81133a-9a13-46a6-88dc-58e1a2776cdb)

## Errors and logs
[Windows 7 home folder](https://drive.google.com/file/d/1QaHEZON_yL3hnLRsW2PEURY76MVEL9JT/view?usp=drive_link) (without content)

## Expected behavior
User needs to be able to select the facility they need to create their new learner account.

## User-facing consequences
Impossible to create a new learner account on a desired facility.

## Steps to reproduce
You will need a server with 2 facilities, try setting up an LoD by creating a new account on the second one. 

## Context

 * Kolibri version: 0.16b13
 * Operating system: Windows 7

cc @pcenov to try to replicate

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `kolibri/plugins/setup_wizard/api.py`
Content:
```
1 import requests
2 from django.urls import reverse
3 from rest_framework import decorators
4 from rest_framework.exceptions import AuthenticationFailed
5 from rest_framework.exceptions import NotFound
6 from rest_framework.exceptions import PermissionDenied
7 from rest_framework.exceptions import ValidationError
8 from rest_framework.permissions import BasePermission
9 from rest_framework.response import Response
10 from rest_framework.viewsets import ViewSet
11 
12 from kolibri.core.auth.constants import user_kinds
13 from kolibri.core.auth.models import Facility
14 from kolibri.core.auth.models import FacilityUser
15 from kolibri.core.auth.utils.users import get_remote_users_info
16 from kolibri.core.device.models import DevicePermissions
17 
18 
19 # Basic class that makes these endpoints unusable if device is provisioned
20 class HasPermissionDuringSetup(BasePermission):
21     def has_permission(self, request, view):
22         from kolibri.core.device.utils import device_provisioned
23 
24         return not device_provisioned()
25 
26 
27 class HasPermissionDuringLODSetup(BasePermission):
28     def has_permission(self, request, view):
29         from kolibri.core.device.utils import get_device_setting
30 
31         return get_device_setting("subset_of_users_device")
32 
33 
34 class SetupWizardResource(ViewSet):
35     """
36     Generic endpoints for use during various setup wizard onboarding flows
37     """
38 
39     permission_classes = (HasPermissionDuringSetup,)
40 
41     @decorators.action(methods=["post"], detail=False)
42     def createuseronremote(self, request):
43         facility_id = request.data.get("facility_id", None)
44         username = request.data.get("username", None)
45         password = request.data.get("password", None)
46         full_name = request.data.get("full_name", "")
47         baseurl = request.data.get("baseurl", None)
48 
49         api_url = reverse("kolibri:core:publicsignup-list")
50 
51         url = "{}{}".format(baseurl, api_url)
52 
53         payload = {
54             "facility_id": facility_id,
55             "username": username,
56             "password": password,
57             "full_name": full_name,
58         }
59 
60         r = requests.post(url, data=payload)
61         return Response({"status": r.status_code, "data": r.content})
62 
63 
64 class FacilityImportViewSet(ViewSet):
65     """
66     A group of endpoints that are used by the SetupWizard to import a facility
67     and create a superuser
68     """
69 
70     permission_classes = (HasPermissionDuringSetup,)
71 
72     @decorators.action(methods=["get"], detail=False)
73     def facilityadmins(self, request):
74         # The filter is very loose, since we are assuming that the only
75         # users are from the new facility
76         queryset = FacilityUser.objects.filter(roles__kind__contains="admin")
77         response_data = [
78             {"full_name": user.full_name, "username": user.username, "id": user.id}
79             for user in queryset
80         ]
81         return Response(response_data)
82 
83     @decorators.action(methods=["post"], detail=False)
84     def grantsuperuserpermissions(self, request):
85         """
86         Given a user ID and credentials, create a superuser DevicePermissions record
87         """
88         user_id = request.data.get("user_id", "")
89         password = request.data.get("password", "")
90 
91         # Get the Facility User object
92         try:
93             facilityuser = FacilityUser.objects.get(id=user_id)
94         except (Exception, FacilityUser.DoesNotExist):
95             raise NotFound()
96 
97         # Test for password and admin role
98         if (
99             not facilityuser.check_password(password)
100             or user_kinds.ADMIN not in facilityuser.session_data["kind"]
101         ):
102             raise PermissionDenied()
103 
104         # If it succeeds, create a DevicePermissions model for the user
105         DevicePermissions.objects.update_or_create(
106             user=facilityuser,
107             defaults={"is_superuser": True, "can_manage_content": True},
108         )
109 
110         # Finally: return a simple 200 so UI can continue on
111         return Response({"user_id": user_id})
112 
113     @decorators.action(methods=["post"], detail=False)
114     def createsuperuser(self, request):
115         """
116         Given a username, full name and password, create a superuser attached
117         to the facility that was imported (or create a facility with given facility_name)
118         """
119         facility_name = request.data.get("facility_name", None)
120 
121         # Get the imported facility (assuming its the only one at this point)
122         if Facility.objects.count() == 0:
123             the_facility = Facility.objects.create(name=facility_name)
124         else:
125             the_facility = Facility.objects.get()
126             if facility_name:
127                 the_facility.name = facility_name
128                 the_facility.save()
129 
130         try:
131             superuser = FacilityUser.objects.create_superuser(
132                 request.data.get("username"),
133                 request.data.get("password"),
134                 facility=the_facility,
135                 full_name=request.data.get("full_name"),
136             )
137             return Response({"username": superuser.username})
138 
139         except ValidationError:
140             raise ValidationError(detail="duplicate", code="duplicate_username")
141 
142     @decorators.action(methods=["post"], detail=False)
143     def listfacilitylearners(self, request):
144         """
145         If the request is done by an admin user  it will return a list of the users of the
146         facility
147 
148         :param baseurl: First part of the url of the server that's going to be requested
149         :param facility_id: Id of the facility to authenticate and get the list of users
150         :param username: Username of the user that's going to authenticate
151         :param password: Password of the user that's going to authenticate
152         :return: List of the learners of the facility.
153         """
154         facility_id = request.data.get("facility_id")
155         baseurl = request.data.get("baseurl")
156         password = request.data.get("password")
157         username = request.data.get("username")
158         try:
159             facility_info = get_remote_users_info(
160                 baseurl, facility_id, username, password
161             )
162         except AuthenticationFailed:
163             raise PermissionDenied()
164         user_info = facility_info["user"]
165         roles = user_info["roles"]
166         admin_roles = (user_kinds.ADMIN, user_kinds.SUPERUSER)
167         if not any(role in roles for role in admin_roles):
168             raise PermissionDenied()
169         students = [u for u in facility_info["users"] if not u["roles"]]
170         return Response({"students": students, "admin": facility_info["user"]})
171
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/kolibri/plugins/setup_wizard/api.py b/kolibri/plugins/setup_wizard/api.py
--- a/kolibri/plugins/setup_wizard/api.py
+++ b/kolibri/plugins/setup_wizard/api.py
@@ -9,6 +9,7 @@
 from rest_framework.response import Response
 from rest_framework.viewsets import ViewSet
 
+from kolibri.core.auth.backends import FACILITY_CREDENTIAL_KEY
 from kolibri.core.auth.constants import user_kinds
 from kolibri.core.auth.models import Facility
 from kolibri.core.auth.models import FacilityUser
@@ -51,7 +52,9 @@
         url = "{}{}".format(baseurl, api_url)
 
         payload = {
-            "facility_id": facility_id,
+            # N.B. facility is keyed by facility not facility_id on the signup
+            # viewset serializer.
+            FACILITY_CREDENTIAL_KEY: facility_id,
             "username": username,
             "password": password,
             "full_name": full_name,

{"golden_diff": "diff --git a/kolibri/plugins/setup_wizard/api.py b/kolibri/plugins/setup_wizard/api.py\n--- a/kolibri/plugins/setup_wizard/api.py\n+++ b/kolibri/plugins/setup_wizard/api.py\n@@ -9,6 +9,7 @@\n from rest_framework.response import Response\n from rest_framework.viewsets import ViewSet\n \n+from kolibri.core.auth.backends import FACILITY_CREDENTIAL_KEY\n from kolibri.core.auth.constants import user_kinds\n from kolibri.core.auth.models import Facility\n from kolibri.core.auth.models import FacilityUser\n@@ -51,7 +52,9 @@\n         url = \"{}{}\".format(baseurl, api_url)\n \n         payload = {\n-            \"facility_id\": facility_id,\n+            # N.B. facility is keyed by facility not facility_id on the signup\n+            # viewset serializer.\n+            FACILITY_CREDENTIAL_KEY: facility_id,\n             \"username\": username,\n             \"password\": password,\n             \"full_name\": full_name,\n", "issue": "Impossible to create a learner account on a second (imported) facility?\n## Observed behavior\r\nI managed to replicate this on 2 separate Android devices. My Windows 7 server device has 2 facilities, one created during the server setup (**Win7new**), and the second one imported from another VM (**imported-from-Win11**). This second one has several classes, and I have been using it exclusively during this past week. \r\n\r\n1. At first I tried to create a new learner account from the Huawei Android 8 tablet on the second facility, and got an error (_Whoops!_). I retried and the field validation was saying ``Username already exists``, which did not make sense, since I searched users on that second facility on the server VM and the username I was trying to create was not there. I moved on, imported another user and went on testing something else.\r\n2. Some times after I was setting up another LoD (on the Motorola phone), tried again to create (not import) a new user on the second facility, and got the same message that the ``Username already exists``. After the initial confusion I had a hunch and went to check the first facility (the one I never really used for class interactions during this testing), and lo and behold, the user I was trying to create did exist there, probably from the above setup on Huawei tablet. And this is not my fat finger miss-touching the wrong radio button during the facility selection, it actually seems that the option to create a new user is somehow _bound_ to the first facility on the device, and would not _obey_ the user's selection of the second facility.\r\n\r\nLoD | Win7 facility users | imported-from-Win11 facility users\r\n-- | -- | --\r\n![2024_02_02_00 48 43](https://github.com/learningequality/kolibri/assets/1457929/12ff9470-914b-4d3a-aed5-fe5720075a70) | ![2024-02-02_00-49-04](https://github.com/learningequality/kolibri/assets/1457929/3c01cd95-e57b-4ad8-a390-37cdcbab757e) | ![2024-02-02_00-49-46](https://github.com/learningequality/kolibri/assets/1457929/0c81133a-9a13-46a6-88dc-58e1a2776cdb)\r\n\r\n## Errors and logs\r\n[Windows 7 home folder](https://drive.google.com/file/d/1QaHEZON_yL3hnLRsW2PEURY76MVEL9JT/view?usp=drive_link) (without content)\r\n\r\n## Expected behavior\r\nUser needs to be able to select the facility they need to create their new learner account.\r\n\r\n## User-facing consequences\r\nImpossible to create a new learner account on a desired facility.\r\n\r\n## Steps to reproduce\r\nYou will need a server with 2 facilities, try setting up an LoD by creating a new account on the second one. \r\n\r\n## Context\r\n\r\n * Kolibri version: 0.16b13\r\n * Operating system: Windows 7\r\n\r\ncc @pcenov to try to replicate\n", "before_files": [{"content": "import requests\nfrom django.urls import reverse\nfrom rest_framework import decorators\nfrom rest_framework.exceptions import AuthenticationFailed\nfrom rest_framework.exceptions import NotFound\nfrom rest_framework.exceptions import PermissionDenied\nfrom rest_framework.exceptions import ValidationError\nfrom rest_framework.permissions import BasePermission\nfrom rest_framework.response import Response\nfrom rest_framework.viewsets import ViewSet\n\nfrom kolibri.core.auth.constants import user_kinds\nfrom kolibri.core.auth.models import Facility\nfrom kolibri.core.auth.models import FacilityUser\nfrom kolibri.core.auth.utils.users import get_remote_users_info\nfrom kolibri.core.device.models import DevicePermissions\n\n\n# Basic class that makes these endpoints unusable if device is provisioned\nclass HasPermissionDuringSetup(BasePermission):\n    def has_permission(self, request, view):\n        from kolibri.core.device.utils import device_provisioned\n\n        return not device_provisioned()\n\n\nclass HasPermissionDuringLODSetup(BasePermission):\n    def has_permission(self, request, view):\n        from kolibri.core.device.utils import get_device_setting\n\n        return get_device_setting(\"subset_of_users_device\")\n\n\nclass SetupWizardResource(ViewSet):\n    \"\"\"\n    Generic endpoints for use during various setup wizard onboarding flows\n    \"\"\"\n\n    permission_classes = (HasPermissionDuringSetup,)\n\n    @decorators.action(methods=[\"post\"], detail=False)\n    def createuseronremote(self, request):\n        facility_id = request.data.get(\"facility_id\", None)\n        username = request.data.get(\"username\", None)\n        password = request.data.get(\"password\", None)\n        full_name = request.data.get(\"full_name\", \"\")\n        baseurl = request.data.get(\"baseurl\", None)\n\n        api_url = reverse(\"kolibri:core:publicsignup-list\")\n\n        url = \"{}{}\".format(baseurl, api_url)\n\n        payload = {\n            \"facility_id\": facility_id,\n            \"username\": username,\n            \"password\": password,\n            \"full_name\": full_name,\n        }\n\n        r = requests.post(url, data=payload)\n        return Response({\"status\": r.status_code, \"data\": r.content})\n\n\nclass FacilityImportViewSet(ViewSet):\n    \"\"\"\n    A group of endpoints that are used by the SetupWizard to import a facility\n    and create a superuser\n    \"\"\"\n\n    permission_classes = (HasPermissionDuringSetup,)\n\n    @decorators.action(methods=[\"get\"], detail=False)\n    def facilityadmins(self, request):\n        # The filter is very loose, since we are assuming that the only\n        # users are from the new facility\n        queryset = FacilityUser.objects.filter(roles__kind__contains=\"admin\")\n        response_data = [\n            {\"full_name\": user.full_name, \"username\": user.username, \"id\": user.id}\n            for user in queryset\n        ]\n        return Response(response_data)\n\n    @decorators.action(methods=[\"post\"], detail=False)\n    def grantsuperuserpermissions(self, request):\n        \"\"\"\n        Given a user ID and credentials, create a superuser DevicePermissions record\n        \"\"\"\n        user_id = request.data.get(\"user_id\", \"\")\n        password = request.data.get(\"password\", \"\")\n\n        # Get the Facility User object\n        try:\n            facilityuser = FacilityUser.objects.get(id=user_id)\n        except (Exception, FacilityUser.DoesNotExist):\n            raise NotFound()\n\n        # Test for password and admin role\n        if (\n            not facilityuser.check_password(password)\n            or user_kinds.ADMIN not in facilityuser.session_data[\"kind\"]\n        ):\n            raise PermissionDenied()\n\n        # If it succeeds, create a DevicePermissions model for the user\n        DevicePermissions.objects.update_or_create(\n            user=facilityuser,\n            defaults={\"is_superuser\": True, \"can_manage_content\": True},\n        )\n\n        # Finally: return a simple 200 so UI can continue on\n        return Response({\"user_id\": user_id})\n\n    @decorators.action(methods=[\"post\"], detail=False)\n    def createsuperuser(self, request):\n        \"\"\"\n        Given a username, full name and password, create a superuser attached\n        to the facility that was imported (or create a facility with given facility_name)\n        \"\"\"\n        facility_name = request.data.get(\"facility_name\", None)\n\n        # Get the imported facility (assuming its the only one at this point)\n        if Facility.objects.count() == 0:\n            the_facility = Facility.objects.create(name=facility_name)\n        else:\n            the_facility = Facility.objects.get()\n            if facility_name:\n                the_facility.name = facility_name\n                the_facility.save()\n\n        try:\n            superuser = FacilityUser.objects.create_superuser(\n                request.data.get(\"username\"),\n                request.data.get(\"password\"),\n                facility=the_facility,\n                full_name=request.data.get(\"full_name\"),\n            )\n            return Response({\"username\": superuser.username})\n\n        except ValidationError:\n            raise ValidationError(detail=\"duplicate\", code=\"duplicate_username\")\n\n    @decorators.action(methods=[\"post\"], detail=False)\n    def listfacilitylearners(self, request):\n        \"\"\"\n        If the request is done by an admin user  it will return a list of the users of the\n        facility\n\n        :param baseurl: First part of the url of the server that's going to be requested\n        :param facility_id: Id of the facility to authenticate and get the list of users\n        :param username: Username of the user that's going to authenticate\n        :param password: Password of the user that's going to authenticate\n        :return: List of the learners of the facility.\n        \"\"\"\n        facility_id = request.data.get(\"facility_id\")\n        baseurl = request.data.get(\"baseurl\")\n        password = request.data.get(\"password\")\n        username = request.data.get(\"username\")\n        try:\n            facility_info = get_remote_users_info(\n                baseurl, facility_id, username, password\n            )\n        except AuthenticationFailed:\n            raise PermissionDenied()\n        user_info = facility_info[\"user\"]\n        roles = user_info[\"roles\"]\n        admin_roles = (user_kinds.ADMIN, user_kinds.SUPERUSER)\n        if not any(role in roles for role in admin_roles):\n            raise PermissionDenied()\n        students = [u for u in facility_info[\"users\"] if not u[\"roles\"]]\n        return Response({\"students\": students, \"admin\": facility_info[\"user\"]})\n", "path": "kolibri/plugins/setup_wizard/api.py"}], "after_files": [{"content": "import requests\nfrom django.urls import reverse\nfrom rest_framework import decorators\nfrom rest_framework.exceptions import AuthenticationFailed\nfrom rest_framework.exceptions import NotFound\nfrom rest_framework.exceptions import PermissionDenied\nfrom rest_framework.exceptions import ValidationError\nfrom rest_framework.permissions import BasePermission\nfrom rest_framework.response import Response\nfrom rest_framework.viewsets import ViewSet\n\nfrom kolibri.core.auth.backends import FACILITY_CREDENTIAL_KEY\nfrom kolibri.core.auth.constants import user_kinds\nfrom kolibri.core.auth.models import Facility\nfrom kolibri.core.auth.models import FacilityUser\nfrom kolibri.core.auth.utils.users import get_remote_users_info\nfrom kolibri.core.device.models import DevicePermissions\n\n\n# Basic class that makes these endpoints unusable if device is provisioned\nclass HasPermissionDuringSetup(BasePermission):\n    def has_permission(self, request, view):\n        from kolibri.core.device.utils import device_provisioned\n\n        return not device_provisioned()\n\n\nclass HasPermissionDuringLODSetup(BasePermission):\n    def has_permission(self, request, view):\n        from kolibri.core.device.utils import get_device_setting\n\n        return get_device_setting(\"subset_of_users_device\")\n\n\nclass SetupWizardResource(ViewSet):\n    \"\"\"\n    Generic endpoints for use during various setup wizard onboarding flows\n    \"\"\"\n\n    permission_classes = (HasPermissionDuringSetup,)\n\n    @decorators.action(methods=[\"post\"], detail=False)\n    def createuseronremote(self, request):\n        facility_id = request.data.get(\"facility_id\", None)\n        username = request.data.get(\"username\", None)\n        password = request.data.get(\"password\", None)\n        full_name = request.data.get(\"full_name\", \"\")\n        baseurl = request.data.get(\"baseurl\", None)\n\n        api_url = reverse(\"kolibri:core:publicsignup-list\")\n\n        url = \"{}{}\".format(baseurl, api_url)\n\n        payload = {\n            # N.B. facility is keyed by facility not facility_id on the signup\n            # viewset serializer.\n            FACILITY_CREDENTIAL_KEY: facility_id,\n            \"username\": username,\n            \"password\": password,\n            \"full_name\": full_name,\n        }\n\n        r = requests.post(url, data=payload)\n        return Response({\"status\": r.status_code, \"data\": r.content})\n\n\nclass FacilityImportViewSet(ViewSet):\n    \"\"\"\n    A group of endpoints that are used by the SetupWizard to import a facility\n    and create a superuser\n    \"\"\"\n\n    permission_classes = (HasPermissionDuringSetup,)\n\n    @decorators.action(methods=[\"get\"], detail=False)\n    def facilityadmins(self, request):\n        # The filter is very loose, since we are assuming that the only\n        # users are from the new facility\n        queryset = FacilityUser.objects.filter(roles__kind__contains=\"admin\")\n        response_data = [\n            {\"full_name\": user.full_name, \"username\": user.username, \"id\": user.id}\n            for user in queryset\n        ]\n        return Response(response_data)\n\n    @decorators.action(methods=[\"post\"], detail=False)\n    def grantsuperuserpermissions(self, request):\n        \"\"\"\n        Given a user ID and credentials, create a superuser DevicePermissions record\n        \"\"\"\n        user_id = request.data.get(\"user_id\", \"\")\n        password = request.data.get(\"password\", \"\")\n\n        # Get the Facility User object\n        try:\n            facilityuser = FacilityUser.objects.get(id=user_id)\n        except (Exception, FacilityUser.DoesNotExist):\n            raise NotFound()\n\n        # Test for password and admin role\n        if (\n            not facilityuser.check_password(password)\n            or user_kinds.ADMIN not in facilityuser.session_data[\"kind\"]\n        ):\n            raise PermissionDenied()\n\n        # If it succeeds, create a DevicePermissions model for the user\n        DevicePermissions.objects.update_or_create(\n            user=facilityuser,\n            defaults={\"is_superuser\": True, \"can_manage_content\": True},\n        )\n\n        # Finally: return a simple 200 so UI can continue on\n        return Response({\"user_id\": user_id})\n\n    @decorators.action(methods=[\"post\"], detail=False)\n    def createsuperuser(self, request):\n        \"\"\"\n        Given a username, full name and password, create a superuser attached\n        to the facility that was imported (or create a facility with given facility_name)\n        \"\"\"\n        facility_name = request.data.get(\"facility_name\", None)\n\n        # Get the imported facility (assuming its the only one at this point)\n        if Facility.objects.count() == 0:\n            the_facility = Facility.objects.create(name=facility_name)\n        else:\n            the_facility = Facility.objects.get()\n            if facility_name:\n                the_facility.name = facility_name\n                the_facility.save()\n\n        try:\n            superuser = FacilityUser.objects.create_superuser(\n                request.data.get(\"username\"),\n                request.data.get(\"password\"),\n                facility=the_facility,\n                full_name=request.data.get(\"full_name\"),\n            )\n            return Response({\"username\": superuser.username})\n\n        except ValidationError:\n            raise ValidationError(detail=\"duplicate\", code=\"duplicate_username\")\n\n    @decorators.action(methods=[\"post\"], detail=False)\n    def listfacilitylearners(self, request):\n        \"\"\"\n        If the request is done by an admin user  it will return a list of the users of the\n        facility\n\n        :param baseurl: First part of the url of the server that's going to be requested\n        :param facility_id: Id of the facility to authenticate and get the list of users\n        :param username: Username of the user that's going to authenticate\n        :param password: Password of the user that's going to authenticate\n        :return: List of the learners of the facility.\n        \"\"\"\n        facility_id = request.data.get(\"facility_id\")\n        baseurl = request.data.get(\"baseurl\")\n        password = request.data.get(\"password\")\n        username = request.data.get(\"username\")\n        try:\n            facility_info = get_remote_users_info(\n                baseurl, facility_id, username, password\n            )\n        except AuthenticationFailed:\n            raise PermissionDenied()\n        user_info = facility_info[\"user\"]\n        roles = user_info[\"roles\"]\n        admin_roles = (user_kinds.ADMIN, user_kinds.SUPERUSER)\n        if not any(role in roles for role in admin_roles):\n            raise PermissionDenied()\n        students = [u for u in facility_info[\"users\"] if not u[\"roles\"]]\n        return Response({\"students\": students, \"admin\": facility_info[\"user\"]})\n", "path": "kolibri/plugins/setup_wizard/api.py"}]}