Skip to content

Commit 22574d5

Browse files
authored
Remove data and schema from non-schema-based control panels (#1933)
* Remove data and schema from non-schema-based control panels * Update docs
1 parent 910b610 commit 22574d5

9 files changed

Lines changed: 37 additions & 46 deletions

File tree

docs/source/endpoints/controlpanels.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ The following fields are returned:
127127
- `@id`: hypermedia link to the control panel
128128
- `title`: title of the control panel
129129
- `group`: group name of the control panel
130-
- `schema`: JSON Schema of the control panel
131-
- `data`: current values of the control panel
132130
- `items`: list of configurable content types
133131

134132

news/1927.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In the `@controlpanels` service, removed empty `data` and `schema` from special control panels that do not use a schema (`dexterity-types` and `rules`). @davisagli

src/plone/restapi/controlpanels/rules.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
@adapter(Interface, IControlpanelLayer)
2020
@implementer(IContentRulesControlpanel, IBrowserPublisher)
2121
class ContentRulesControlpanel(RegistryConfigletPanel):
22-
schema = Interface
2322
configlet_id = "ContentRules"
2423
configlet_category_id = "plone-content"
2524

src/plone/restapi/controlpanels/types.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
@adapter(Interface, IControlpanelLayer)
2020
@implementer(IDexterityTypesControlpanel)
2121
class DexterityTypesControlpanel(RegistryConfigletPanel):
22-
schema = Interface
2322
configlet_id = "dexterity-types"
2423
configlet_category_id = "plone-content"
2524

src/plone/restapi/deserializer/controlpanels/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ def __init__(self, controlpanel):
3535
self.request = self.controlpanel.request
3636

3737
def __call__(self, mask_validation_errors=True):
38+
if self.schema is None:
39+
return
40+
3841
data = json_body(self.controlpanel.request)
3942

4043
proxy = self.registry.forInterface(self.schema, prefix=self.schema_prefix)

src/plone/restapi/serializer/controlpanels/__init__.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -78,38 +78,41 @@ def __init__(self, controlpanel):
7878
self.registry = getUtility(IRegistry)
7979

8080
def __call__(self):
81-
json_schema = get_jsonschema_for_controlpanel(
82-
self.controlpanel, self.controlpanel.context, self.controlpanel.request
83-
)
84-
85-
proxy = self.registry.forInterface(self.schema, prefix=self.schema_prefix)
86-
87-
# Temporarily provide IDexterityContent, so we can use DX field
88-
# serializers
89-
alsoProvides(proxy, IDexterityContent)
90-
91-
json_data = {}
92-
for name, field in zope.schema.getFields(self.schema).items():
93-
serializer = queryMultiAdapter(
94-
(field, proxy, self.controlpanel.request), IFieldSerializer
95-
)
96-
if serializer:
97-
value = serializer()
98-
else:
99-
value = getattr(proxy, name, None)
100-
json_data[json_compatible(name)] = value
101-
102-
noLongerProvides(proxy, IDexterityContent)
103-
104-
# JSON schema
105-
return {
81+
result = {
10682
"@id": "{}/{}/{}".format(
10783
self.controlpanel.context.absolute_url(),
10884
SERVICE_ID,
10985
self.controlpanel.__name__,
11086
),
11187
"title": self.controlpanel.title,
11288
"group": self.controlpanel.group,
113-
"schema": json_schema,
114-
"data": json_data,
11589
}
90+
91+
if self.schema is not None:
92+
json_schema = get_jsonschema_for_controlpanel(
93+
self.controlpanel, self.controlpanel.context, self.controlpanel.request
94+
)
95+
result["schema"] = json_schema
96+
97+
proxy = self.registry.forInterface(self.schema, prefix=self.schema_prefix)
98+
99+
# Temporarily provide IDexterityContent, so we can use DX field
100+
# serializers
101+
alsoProvides(proxy, IDexterityContent)
102+
103+
json_data = {}
104+
for name, field in zope.schema.getFields(self.schema).items():
105+
serializer = queryMultiAdapter(
106+
(field, proxy, self.controlpanel.request), IFieldSerializer
107+
)
108+
if serializer:
109+
value = serializer()
110+
else:
111+
value = getattr(proxy, name, None)
112+
json_data[json_compatible(name)] = value
113+
114+
noLongerProvides(proxy, IDexterityContent)
115+
116+
result["data"] = json_data
117+
118+
return result

src/plone/restapi/tests/http-examples/controlpanels_get_contentrules.resp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Content-Type: application/json
33

44
{
55
"@id": "http://localhost:55001/plone/@controlpanels/content-rules",
6-
"data": {},
76
"group": "Content",
87
"items": [
98
[
@@ -29,11 +28,5 @@ Content-Type: application/json
2928
}
3029
]
3130
],
32-
"schema": {
33-
"fieldsets": [],
34-
"properties": {},
35-
"required": [],
36-
"type": "object"
37-
},
3831
"title": "Content Rules"
3932
}

src/plone/restapi/tests/http-examples/controlpanels_get_dexterity.resp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Content-Type: application/json
33

44
{
55
"@id": "http://localhost:55001/plone/@controlpanels/dexterity-types",
6-
"data": {},
76
"group": "Content",
87
"items": [
98
{
@@ -97,11 +96,5 @@ Content-Type: application/json
9796
"title": "DX Test Document"
9897
}
9998
],
100-
"schema": {
101-
"fieldsets": [],
102-
"properties": {},
103-
"required": [],
104-
"type": "object"
105-
},
10699
"title": "Content Types"
107100
}

src/plone/restapi/tests/test_services_controlpanels.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ def test_update_all(self):
9393
response = self.api_session.get(item["@id"])
9494

9595
# store the outputted data
96-
response = self.api_session.patch(item["@id"], json=response.json()["data"])
96+
response = self.api_session.patch(
97+
item["@id"], json=response.json().get("data", {})
98+
)
9799
self.assertEqual(
98100
204,
99101
response.status_code,

0 commit comments

Comments
 (0)