From 7ffaa5f38acdbaacd5a8b38d962468964cc61bbd Mon Sep 17 00:00:00 2001 From: irtisamsajin Date: Mon, 7 Apr 2025 19:11:18 +0600 Subject: [PATCH] 1901: added @id to @content-rules endpoint and made it consistent with other endpoints --- news/1901.bugfix | 1 + src/plone/restapi/services/rules/get.py | 9 ++-- .../tests/http-examples/rules_get.resp | 51 +++++++++---------- 3 files changed, 30 insertions(+), 31 deletions(-) create mode 100644 news/1901.bugfix diff --git a/news/1901.bugfix b/news/1901.bugfix new file mode 100644 index 0000000000..60506a0c68 --- /dev/null +++ b/news/1901.bugfix @@ -0,0 +1 @@ +Changed the structure of the @content-rules endpoint response to return a flat format with @id at the top level, making it consistent with other REST API endpoints. @irtisamsajin \ No newline at end of file diff --git a/src/plone/restapi/services/rules/get.py b/src/plone/restapi/services/rules/get.py index 53cb5979ff..6efc306bec 100644 --- a/src/plone/restapi/services/rules/get.py +++ b/src/plone/restapi/services/rules/get.py @@ -23,9 +23,8 @@ def reply(self): assignable_rules = manage_assignments.assignable_rules() return { - "content-rules": { - "acquired_rules": acquired_rules, - "assigned_rules": assigned_rules, - "assignable_rules": assignable_rules, - } + "@id": f"{self.context.absolute_url()}/@content-rules", + "acquired_rules": acquired_rules, + "assigned_rules": assigned_rules, + "assignable_rules": assignable_rules, } diff --git a/src/plone/restapi/tests/http-examples/rules_get.resp b/src/plone/restapi/tests/http-examples/rules_get.resp index b506028ffb..22dd66a71e 100644 --- a/src/plone/restapi/tests/http-examples/rules_get.resp +++ b/src/plone/restapi/tests/http-examples/rules_get.resp @@ -2,30 +2,29 @@ HTTP/1.1 200 OK Content-Type: application/json { - "content-rules": { - "acquired_rules": [], - "assignable_rules": [], - "assigned_rules": [ - { - "bubbles": true, - "description": "First rule added in the testing setup", - "enabled": true, - "global_enabled": true, - "id": "rule-1", - "title": "First test rule", - "trigger": "Comment added", - "url": "http://localhost:55001/plone/++rule++rule-1/@@manage-elements" - }, - { - "bubbles": true, - "description": "Second rule added in the testing setup", - "enabled": true, - "global_enabled": true, - "id": "rule-2", - "title": "Second test rule", - "trigger": "Comment added", - "url": "http://localhost:55001/plone/++rule++rule-2/@@manage-elements" - } - ] - } + "@id": "http://localhost:55001/plone/@content-rules", + "acquired_rules": [], + "assignable_rules": [], + "assigned_rules": [ + { + "bubbles": true, + "description": "First rule added in the testing setup", + "enabled": true, + "global_enabled": true, + "id": "rule-1", + "title": "First test rule", + "trigger": "Comment added", + "url": "http://localhost:55001/plone/++rule++rule-1/@@manage-elements" + }, + { + "bubbles": true, + "description": "Second rule added in the testing setup", + "enabled": true, + "global_enabled": true, + "id": "rule-2", + "title": "Second test rule", + "trigger": "Comment added", + "url": "http://localhost:55001/plone/++rule++rule-2/@@manage-elements" + } + ] }