diff --git a/src/meshapi/permissions.py b/src/meshapi/permissions.py index 2ed82abb..6a4c1084 100644 --- a/src/meshapi/permissions.py +++ b/src/meshapi/permissions.py @@ -111,7 +111,7 @@ def has_permission(self, request, view): return True -class NewNodePermissions(permissions.BasePermission): +class NetworkNumberAssignmentPermissions(permissions.BasePermission): def has_permission(self, request, view): if not (request.user.is_superuser or is_admin(request.user) or is_installer(request.user)): raise PermissionDenied(perm_denied_generic_msg) diff --git a/src/meshapi/tests/test_nn.py b/src/meshapi/tests/test_nn.py index 11696cfd..5c6790aa 100644 --- a/src/meshapi/tests/test_nn.py +++ b/src/meshapi/tests/test_nn.py @@ -26,7 +26,7 @@ def setUp(self): def test_nn_valid_building_id(self): response = self.admin_c.post( - "/api/v1/new-node/", {"meshapi_building_id": self.building_id}, content_type="application/json" + "/api/v1/nn-assign/", {"meshapi_building_id": self.building_id}, content_type="application/json" ) code = 200 @@ -46,7 +46,7 @@ def test_nn_valid_building_id(self): def test_nn_invalid_building_id(self): response = self.admin_c.post( - "/api/v1/new-node/", {"meshapi_building_id": 69420}, content_type="application/json" + "/api/v1/nn-assign/", {"meshapi_building_id": 69420}, content_type="application/json" ) code = 404 @@ -58,7 +58,7 @@ def test_nn_invalid_building_id(self): def test_nn_bad_request(self): response = self.admin_c.post( - "/api/v1/new-node/", {"meshapi_building_id": "chom"}, content_type="application/json" + "/api/v1/nn-assign/", {"meshapi_building_id": "chom"}, content_type="application/json" ) code = 404 @@ -68,7 +68,7 @@ def test_nn_bad_request(self): f"status code incorrect for test_nn_invalid_building_id. Should be {code}, but got {response.status_code}", ) - response = self.admin_c.post("/api/v1/new-node/", "Tell me your secrets >:)", content_type="application/json") + response = self.admin_c.post("/api/v1/nn-assign/", "Tell me your secrets >:)", content_type="application/json") code = 400 self.assertEqual( @@ -125,7 +125,7 @@ def test_nn_search_for_new_number(self): for b_id, nn in [(self.b2_bid, 111), (self.b3_bid, 112), (self.b4_bid, 130)]: response = self.admin_c.post( - "/api/v1/new-node/", {"meshapi_building_id": b_id}, content_type="application/json" + "/api/v1/nn-assign/", {"meshapi_building_id": b_id}, content_type="application/json" ) code = 200 diff --git a/src/meshapi/urls.py b/src/meshapi/urls.py index 8160764a..284b82e0 100644 --- a/src/meshapi/urls.py +++ b/src/meshapi/urls.py @@ -16,7 +16,7 @@ path("requests/", views.RequestList.as_view(), name="meshapi-v1-request-list"), path("requests//", views.RequestDetail.as_view(), name="meshapi-v1-request-detail"), path("join/", views.join_form, name="meshapi-v1-join"), - path("new-node/", views.new_node, name="meshapi-v1-new-node"), + path("nn-assign/", views.network_number_assignment, name="meshapi-v1-nn-assign"), ] urlpatterns = format_suffix_patterns(urlpatterns) diff --git a/src/meshapi/views.py b/src/meshapi/views.py index c951a5ce..d04b18a7 100644 --- a/src/meshapi/views.py +++ b/src/meshapi/views.py @@ -22,7 +22,7 @@ MemberRetrieveUpdateDestroyPermissions, InstallListCreatePermissions, InstallRetrieveUpdateDestroyPermissions, - NewNodePermissions, + NetworkNumberAssignmentPermissions, RequestListCreatePermissions, RequestRetrieveUpdateDestroyPermissions, ) @@ -319,13 +319,13 @@ def join_form(request): @dataclass -class NewNodeRequest: +class NetworkNumberAssignmentRequest: meshapi_building_id: int @api_view(["POST"]) -@permission_classes([NewNodePermissions]) -def new_node(request): +@permission_classes([NetworkNumberAssignmentPermissions]) +def network_number_assignment(request): """ Takes in an existing building ID (not an NYC BIN, one of ours), and assigns it a network number, deduping using the other buildings in our database. @@ -334,7 +334,7 @@ def new_node(request): try: request_json = json.loads(request.body) - r = NewNodeRequest(**request_json) + r = NetworkNumberAssignmentRequest(**request_json) except (TypeError, JSONDecodeError) as e: print(f"NN Request failed. Could not decode request: {e}") return Response({"Got incomplete request"}, status=status.HTTP_400_BAD_REQUEST)