Skip to content

Commit fb8596c

Browse files
authored
fix(api): make REST Services settings and sub_fields optional again DEV-1288 (#6480)
### 📣 Summary Restore optional behavior for the settings and sub_fields fields in REST Services endpoints. ### 📖 Description This fix reverts a regression where the `settings` and `sub_fields` fields in REST Services became required. These fields are now optional again, restoring backward compatibility and preventing validation errors when creating or updating REST Services without them.
1 parent 4805001 commit fb8596c

File tree

6 files changed

+22
-17
lines changed

6 files changed

+22
-17
lines changed

jsapp/js/api/models/hook.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export interface Hook {
2929
/** @nullable */
3030
payload_template?: string | null
3131
readonly pending_count: number
32-
settings: HookSettings
33-
subset_fields: string[]
32+
settings?: HookSettings
33+
subset_fields?: string[]
3434
readonly success_count: number
3535
readonly uid: string
3636
readonly url: string

kobo/apps/hook/serializers/v2/hook.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323

2424
class HookSerializer(serializers.ModelSerializer):
2525

26-
payload_template = serializers.CharField(required=False, allow_blank=True,
27-
allow_null=True)
26+
payload_template = serializers.CharField(
27+
required=False, allow_blank=True, allow_null=True
28+
)
2829

29-
settings = JSONFieldWithSchemaField(SettingsField)
30-
subset_fields = ListFieldWithSchemaField(SubsetFieldsField)
30+
settings = JSONFieldWithSchemaField(SettingsField, required=False)
31+
subset_fields = ListFieldWithSchemaField(SubsetFieldsField, required=False)
3132

3233
class Meta:
3334
model = Hook

kobo/apps/hook/tests/test_api_hook.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ def test_anonymous_access(self):
6363
def test_create_hook(self):
6464
self._create_hook()
6565

66+
def test_create_minimal_hook(self):
67+
self._create_hook(minimal=True)
68+
6669
def test_editor_access(self):
6770
hook = self._create_hook()
6871

kobo/apps/hook/utils/tests/mixins.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,23 @@ def _create_hook(self, return_response_only=False, **kwargs):
2828
self._add_submissions()
2929

3030
url = reverse('hook-list', args=(self.asset.uid,))
31+
3132
data = {
3233
'name': kwargs.get('name', 'some external service with token'),
3334
'endpoint': kwargs.get('endpoint', 'http://external.service.local/'),
34-
'settings': kwargs.get(
35-
'settings', {'custom_headers': {'X-Token': '1234abcd'}}
36-
),
37-
'export_type': format_type,
38-
'active': kwargs.get('active', True),
39-
'subset_fields': kwargs.get('subset_fields', []),
40-
'payload_template': kwargs.get('payload_template', None),
4135
}
4236

37+
if not kwargs.get('minimal', False):
38+
data.update({
39+
'settings': kwargs.get(
40+
'settings', {'custom_headers': {'X-Token': '1234abcd'}}
41+
),
42+
'active': kwargs.get('active', True),
43+
'export_type': format_type,
44+
'subset_fields': kwargs.get('subset_fields', []),
45+
'payload_template': kwargs.get('payload_template', None),
46+
})
47+
4348
response = self.client.post(url, data, format='json')
4449
if return_response_only:
4550
return response

static/openapi/schema_v2.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14734,8 +14734,6 @@
1473414734
"logs_url",
1473514735
"name",
1473614736
"pending_count",
14737-
"settings",
14738-
"subset_fields",
1473914737
"success_count",
1474014738
"uid",
1474114739
"url"

static/openapi/schema_v2.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10513,8 +10513,6 @@ components:
1051310513
- logs_url
1051410514
- name
1051510515
- pending_count
10516-
- settings
10517-
- subset_fields
1051810516
- success_count
1051910517
- uid
1052010518
- url

0 commit comments

Comments
 (0)