Skip to content

Commit 1d8a62a

Browse files
committed
Remove the obligation to provide an assignee in REST API context #345
Signed-off-by: tdruez <[email protected]>
1 parent fb8791a commit 1d8a62a

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

docs/integrations-rest-api.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ Required fields:
126126

127127
- **title** (string): A short, descriptive title of the request.
128128
- **request_template** (string): URI of the template to use.
129-
- **assignee** (string): Username of the person assigned.
130129

131130
Optional fields:
132131

133132
- **status** (string): ``open``, ``closed``, or ``draft``. Default is ``open``.
133+
- **assignee** (string): Username of the person assigned.
134134
- **priority** (string|null): Priority level.
135135
- **product_context** (string|null): URI of a product context.
136136
- **notes** (string): Notes related to the request.
@@ -150,8 +150,7 @@ Example of minimal JSON payload::
150150

151151
{
152152
"title": "New vulnerability found",
153-
"request_template": "Address Vulnerabilities in Product Packages",
154-
"assignee": "username"
153+
"request_template": "Address Vulnerabilities in Product Packages"
155154
}
156155

157156
Example using cURL::
@@ -160,8 +159,7 @@ Example using cURL::
160159
headers="Authorization: Token abcdef123456"
161160
data='{
162161
"title": "New vulnerability found",
163-
"request_template": "Address Vulnerabilities in Product Packages",
164-
"assignee": "username"
162+
"request_template": "Address Vulnerabilities in Product Packages"
165163
}'
166164

167165
curl -X POST "$api_url" -H "$headers" -d "$data"

workflow/api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,12 @@ class RequestSerializer(DataspacedSerializer):
165165
)
166166
request_template_name = serializers.StringRelatedField(source="request_template.name")
167167
requester = serializers.StringRelatedField()
168-
assignee = DataspacedSlugRelatedField(slug_field="username")
168+
assignee = DataspacedSlugRelatedField(
169+
slug_field="username",
170+
# Not required in the REST API context to simplify external integrations.
171+
allow_null=True,
172+
required=False,
173+
)
169174
priority = DataspacedSlugRelatedField(
170175
slug_field="label",
171176
allow_null=True,

workflow/tests/test_api.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,16 @@ def test_api_request_endpoint_create(self):
361361
expected = {
362362
"title": ["This field is required."],
363363
"request_template": ["This field may not be null."],
364-
"assignee": ["This field may not be null."],
365364
}
366365
self.assertEqual(expected, response.json())
367366

367+
data = {
368+
"title": "Title",
369+
"request_template": self.request_template1_detail_url,
370+
}
371+
response = self.client.post(self.request_list_url, data)
372+
self.assertEqual(status.HTTP_201_CREATED, response.status_code)
373+
368374
data = {
369375
"title": "Title",
370376
"request_template": self.request_template1_detail_url,

0 commit comments

Comments
 (0)