Content Rules
Contents
Content Rules#
A content rule will automatically perform an action when a certain event, known as a trigger, takes place.
Content rules can perform routine tasks, including the following.
Move content from one folder to another when that content item is published.
Send email when a content item is deleted.
Delete content after a certain date.
See also
Note
These docs are generated by code tests, therefore you will see some test
rules appear here.
Available content rules in a Plone site can be listed and queried by accessing the /@content-rules
endpoint in any context.
Access requires the ManageContentRules
permission.
GET /plone/@content-rules HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
curl -i -X GET http://nohost/plone/@content-rules -H "Accept: application/json" --user admin:secret
http http://nohost/plone/@content-rules Accept:application/json -a admin:secret
requests.get('http://nohost/plone/@content-rules', headers={'Accept': 'application/json'}, auth=('admin', 'secret'))
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"
}
]
}
}
The API consumer can assign, unassign, enable, disable, apply to subfolders, or disable apply to subfolders any of the rules available in the portal.
Verb |
URL |
Action |
---|---|---|
|
|
Add rule to context |
|
|
Get acquired, assignable, and assigned rules |
|
|
enable or disable, |
apply to subfolders or disable apply to subfolders, move down or move up |
||
|
|
Unassign rule on context |
Assigning a new Content rule with POST
#
To assign a content rule to a context, send a POST
request to the <context>/@content-rules
endpoint:
POST /plone/@content-rules/rule-1 HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
curl -i -X POST http://nohost/plone/@content-rules/rule-1 -H "Accept: application/json" --user admin:secret
http POST http://nohost/plone/@content-rules/rule-1 Accept:application/json -a admin:secret
requests.post('http://nohost/plone/@content-rules/rule-1', headers={'Accept': 'application/json'}, auth=('admin', 'secret'))
Response:
HTTP/1.1 200 OK
Content-Type: application/json
{
"message": "Successfully assigned the rule rule-1"
}
Getting content rule for a context with GET
#
To get content rules that are assigned, assignable, or acquired for a context, send a GET
request to the <context>/@content-rules
endpoint:
GET /plone/@content-rules HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
curl -i -X GET http://nohost/plone/@content-rules -H "Accept: application/json" --user admin:secret
http http://nohost/plone/@content-rules Accept:application/json -a admin:secret
requests.get('http://nohost/plone/@content-rules', headers={'Accept': 'application/json'}, auth=('admin', 'secret'))
Response:
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"
}
]
}
}
Changing content rules for a context with PATCH
#
To make changes on content rule assignments for a context, send a PATCH
request to the <context>/@content-rules
endpoint:
Apply on subfolders#
PATCH /plone/@content-rules HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
Content-Type: application/json
{
"form.button.Bubble": true,
"rule_ids": [
"rule-1",
"rule-2"
]
}
curl -i -X PATCH http://nohost/plone/@content-rules -H "Accept: application/json" -H "Content-Type: application/json" --data-raw '{"form.button.Bubble": true, "rule_ids": ["rule-1", "rule-2"]}' --user admin:secret
echo '{
"form.button.Bubble": true,
"rule_ids": [
"rule-1",
"rule-2"
]
}' | http PATCH http://nohost/plone/@content-rules Accept:application/json Content-Type:application/json -a admin:secret
requests.patch('http://nohost/plone/@content-rules', headers={'Accept': 'application/json', 'Content-Type': 'application/json'}, json={'form.button.Bubble': True, 'rule_ids': ['rule-1', 'rule-2']}, auth=('admin', 'secret'))
Response:
HTTP/1.1 200 OK
Content-Type: application/json
{
"message": "Successfully applied ['rule-1', 'rule-2'] to subfolders"
}
Disable apply on subfolders#
PATCH /plone/@content-rules HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
Content-Type: application/json
{
"form.button.NoBubble": true,
"rule_ids": [
"rule-1",
"rule-2"
]
}
curl -i -X PATCH http://nohost/plone/@content-rules -H "Accept: application/json" -H "Content-Type: application/json" --data-raw '{"form.button.NoBubble": true, "rule_ids": ["rule-1", "rule-2"]}' --user admin:secret
echo '{
"form.button.NoBubble": true,
"rule_ids": [
"rule-1",
"rule-2"
]
}' | http PATCH http://nohost/plone/@content-rules Accept:application/json Content-Type:application/json -a admin:secret
requests.patch('http://nohost/plone/@content-rules', headers={'Accept': 'application/json', 'Content-Type': 'application/json'}, json={'form.button.NoBubble': True, 'rule_ids': ['rule-1', 'rule-2']}, auth=('admin', 'secret'))
Response:
HTTP/1.1 200 OK
Content-Type: application/json
{
"message": "Disabled apply to subfolders for ['rule-1', 'rule-2']"
}
Enable#
PATCH /plone/@content-rules HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
Content-Type: application/json
{
"form.button.Enable": true,
"rule_ids": [
"rule-1",
"rule-2"
]
}
curl -i -X PATCH http://nohost/plone/@content-rules -H "Accept: application/json" -H "Content-Type: application/json" --data-raw '{"form.button.Enable": true, "rule_ids": ["rule-1", "rule-2"]}' --user admin:secret
echo '{
"form.button.Enable": true,
"rule_ids": [
"rule-1",
"rule-2"
]
}' | http PATCH http://nohost/plone/@content-rules Accept:application/json Content-Type:application/json -a admin:secret
requests.patch('http://nohost/plone/@content-rules', headers={'Accept': 'application/json', 'Content-Type': 'application/json'}, json={'form.button.Enable': True, 'rule_ids': ['rule-1', 'rule-2']}, auth=('admin', 'secret'))
Response:
HTTP/1.1 200 OK
Content-Type: application/json
{
"message": "Successfully enabled rules ['rule-1', 'rule-2']"
}
Disable#
PATCH /plone/@content-rules HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
Content-Type: application/json
{
"form.button.Disable": true,
"rule_ids": [
"rule-1",
"rule-2"
]
}
curl -i -X PATCH http://nohost/plone/@content-rules -H "Accept: application/json" -H "Content-Type: application/json" --data-raw '{"form.button.Disable": true, "rule_ids": ["rule-1", "rule-2"]}' --user admin:secret
echo '{
"form.button.Disable": true,
"rule_ids": [
"rule-1",
"rule-2"
]
}' | http PATCH http://nohost/plone/@content-rules Accept:application/json Content-Type:application/json -a admin:secret
requests.patch('http://nohost/plone/@content-rules', headers={'Accept': 'application/json', 'Content-Type': 'application/json'}, json={'form.button.Disable': True, 'rule_ids': ['rule-1', 'rule-2']}, auth=('admin', 'secret'))
Response:
HTTP/1.1 200 OK
Content-Type: application/json
{
"message": "Successfully disabled rules ['rule-1', 'rule-2']"
}
Move up#
PATCH /plone/@content-rules HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
Content-Type: application/json
{
"operation": "move_up",
"rule_id": "rule-2"
}
curl -i -X PATCH http://nohost/plone/@content-rules -H "Accept: application/json" -H "Content-Type: application/json" --data-raw '{"operation": "move_up", "rule_id": "rule-2"}' --user admin:secret
echo '{
"operation": "move_up",
"rule_id": "rule-2"
}' | http PATCH http://nohost/plone/@content-rules Accept:application/json Content-Type:application/json -a admin:secret
requests.patch('http://nohost/plone/@content-rules', headers={'Accept': 'application/json', 'Content-Type': 'application/json'}, json={'operation': 'move_up', 'rule_id': 'rule-2'}, auth=('admin', 'secret'))
Response:
HTTP/1.1 200 OK
Content-Type: application/json
{
"message": "Successfully applied the move_up"
}
Move down#
PATCH /plone/@content-rules HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
Content-Type: application/json
{
"operation": "move_down",
"rule_id": "rule-1"
}
curl -i -X PATCH http://nohost/plone/@content-rules -H "Accept: application/json" -H "Content-Type: application/json" --data-raw '{"operation": "move_down", "rule_id": "rule-1"}' --user admin:secret
echo '{
"operation": "move_down",
"rule_id": "rule-1"
}' | http PATCH http://nohost/plone/@content-rules Accept:application/json Content-Type:application/json -a admin:secret
requests.patch('http://nohost/plone/@content-rules', headers={'Accept': 'application/json', 'Content-Type': 'application/json'}, json={'operation': 'move_down', 'rule_id': 'rule-1'}, auth=('admin', 'secret'))
Response:
HTTP/1.1 200 OK
Content-Type: application/json
{
"message": "Successfully applied the move_down"
}
Unassign content rules with DELETE
#
To unassign content rules on a context, send a DELETE
request to the <context>/@content-rules
endpoint:
DELETE /plone/@content-rules HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
Content-Type: application/json
{
"rule_ids": [
"rule-1"
]
}
curl -i -X DELETE http://nohost/plone/@content-rules -H "Accept: application/json" -H "Content-Type: application/json" --data-raw '{"rule_ids": ["rule-1"]}' --user admin:secret
echo '{
"rule_ids": [
"rule-1"
]
}' | http DELETE http://nohost/plone/@content-rules Accept:application/json Content-Type:application/json -a admin:secret
requests.delete('http://nohost/plone/@content-rules', headers={'Accept': 'application/json', 'Content-Type': 'application/json'}, json={'rule_ids': ['rule-1']}, auth=('admin', 'secret'))
Response:
HTTP/1.1 204 No Content
Content-Type: text/html;charset=utf-8