Skip to content

Commit

Permalink
Merge pull request RedHatInsights#1250 from coderbydesign/require-par…
Browse files Browse the repository at this point in the history
…ent_id-on-workspace-create

Require "parent_id" field on Workspace POST
  • Loading branch information
coderbydesign authored Oct 22, 2024
2 parents c79186e + 6d32cde commit 19e22b2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
5 changes: 4 additions & 1 deletion docs/source/specs/typespec/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ namespace Workspaces {
name: string;
}

alias CreateWorkspaceRequest = BasicWorkspace;
model CreateWorkspaceRequest extends BasicWorkspace{
@doc("Parent UUID of Workspace A")
parent_id: UUID = "Parent UUID of Workspace A";
}

model CreateWorkspaceResponse extends Workspace{
@statusCode _: 201;
Expand Down
14 changes: 13 additions & 1 deletion docs/source/specs/v2/openapi.v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/Workspaces.BasicWorkspace'
$ref: '#/components/schemas/Workspaces.CreateWorkspaceRequest'
/workspaces/{uuid}/:
get:
tags:
Expand Down Expand Up @@ -643,6 +643,18 @@ components:
type: string
description: Description of Workspace A
default: Description of Workspace A
Workspaces.CreateWorkspaceRequest:
type: object
required:
- parent_id
properties:
parent_id:
allOf:
- $ref: '#/components/schemas/UUID'
description: Parent UUID of Workspace A
default: Parent UUID of Workspace A
allOf:
- $ref: '#/components/schemas/Workspaces.BasicWorkspace'
Workspaces.CreateWorkspaceResponse:
type: object
allOf:
Expand Down
2 changes: 1 addition & 1 deletion rbac/management/workspace/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

VALID_PATCH_FIELDS = ["name", "description", "parent_id"]
REQUIRED_PUT_FIELDS = ["name", "description", "parent_id"]
REQUIRED_CREATE_FIELDS = ["name"]
REQUIRED_CREATE_FIELDS = ["name", "parent_id"]
INCLUDE_ANCESTRY_KEY = "include_ancestry"
VALID_BOOLEAN_VALUES = ["true", "false"]

Expand Down
18 changes: 8 additions & 10 deletions tests/management/workspace/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,14 @@ def test_create_workspace_without_parent(self):
url = reverse("v2_management:workspace-list")
client = APIClient()
response = client.post(url, workspace, format="json", **self.headers)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
data = response.data
self.assertEqual(data.get("name"), "New Workspace")
self.assertNotEquals(data.get("uuid"), "")
self.assertIsNotNone(data.get("uuid"))
self.assertNotEquals(data.get("created"), "")
self.assertNotEquals(data.get("modified"), "")
self.assertEquals(data.get("description"), "Workspace")
self.assertEquals(data.get("type"), "standard")
self.assertEqual(response.get("content-type"), "application/json")
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
status_code = response.data.get("status")
detail = response.data.get("detail")
self.assertIsNotNone(detail)
self.assertEqual(detail, "Field 'parent_id' is required.")

self.assertEqual(status_code, 400)
self.assertEqual(response.get("content-type"), "application/problem+json")

def test_create_workspace_empty_body(self):
"""Test for creating a workspace."""
Expand Down

0 comments on commit 19e22b2

Please sign in to comment.