A proposition:
- Enable "Rules Sheduler" at
/admin/modules
.
- Go to
/admin/config/workflow/rules/components
and create a component
- Add new component:
- Component plugin =>
Action set
- "Continue"
- Component plugin:
- Specify the component name (e.g. Revoke node access component)
- choose in the table:
- Data type => Content
- Label =>
Node:Component
or Node
or what you want
- Machine name =>
node_component
or node
or what you want
- Usage =>
Parameter
- "Continue"
- Add actions:
- Select actions to add =>
Revoke access by role
- Data selector: is set as
node-component
by default; this is the selector name you have specified in the table in the step above
- In "Role-based access control settings" check roles you want to revoke access for view/edit/delete content
- "Save"
- Go to
admin/config/workflow/rules
and add new rule (Add new rule):
- Add new rule:
- specify the rule name (e.g. Revoke node access rule)
- React on event =>
After saving new content
- Restrict by type => optionally, choose a node type you want to apply this rule to
- "Save"
- Events:
- (optionally) you may also add here "After updating existing content" event if the rule has to triggered on existing nodes
- Conditions:
- (optionally) add your additional conditions here
- Actions:
- Add action
- Select the action to add =>
Schedule component evaluation
- Component: Select yor component you have already created (Revoke node access component)
- Continue
- Scheduled evaluation date:
- click the "Switch to data selection and specify" button and specify:
- Data selector:
node:created
(or other date-based condition)
- Add offset: optionally specfify an offset for the chosen data selector (e.g.
1 seconds
)
- Identifier: Specify an identifer ("A string used for identifying this task") which is visible (Rules) "Scheduler" (
/admin/config/workflow/rules/schedule
) and in "Recent log messages" (/admin/reports/dblog
). You may use tokens/replacement patterns.
- Node:Component:
- Data selector =>
node
- Save
What's this?
This solution triggers a rule after a new and/or existing node has been saved. The rule "schedules" the component with an action set - in our case, the action is to revoke node access to the checked user roles. After content has been added as new and or edited, the component revokes node access on nodes for specified roles as scheduled on cron run, e.g. adding new article now +1 sec makes it unaccessible (view/edit/delete) on next cron on > (node:created
+1 sec).
Hint:
It is also possible to add Schedule component evaluation
as an action into a component. For example: you want this rule to be triggered using node:changed
date, so every time you edit a node, the date for the action "Revoke node access" will be moved forward (e.g: node is changed now => the rule triggers in 1 day (offset in component settings); the node will be changed tomorrow, so the rule will be trigerred on tomorrow date +1 day and so on).
You can import and test the component:
{ "rules_revoke_node_access_component" : {
"LABEL" : "Revoke node access component",
"PLUGIN" : "action set",
"OWNER" : "rules",
"REQUIRES" : [ "content_access_rules" ],
"USES VARIABLES" : { "node_component" : { "label" : "Node:Component", "type" : "node" } },
"ACTION SET" : [
{ "content_access_action_revoke_node_permissions" : {
"node" : [ "node-component" ],
"permissions" : { "value" : [
"view:2",
"view:1",
"view:3",
"view_own:2",
"view_own:1",
"view_own:3",
"update:2",
"update:1",
"update:3",
"update_own:2",
"update_own:1",
"update_own:3",
"delete:2",
"delete:1",
"delete:3",
"delete_own:2",
"delete_own:1",
"delete_own:3"
]
}
}
}
]
}
}
You can import and test the rule:
{ "rules_revoke_node_access_rule" : {
"LABEL" : "Revoke node access rule",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "rules_scheduler" ],
"ON" : { "node_insert" : [], "node_update" : [] },
"DO" : [
{ "schedule" : {
"component" : "rules_revoke_node_access_component",
"date" : { "select" : "node:created", "date_offset" : { "value" : 1 } },
"identifier" : "Revoke node access",
"param_node_component" : [ "node" ]
}
}
]
}
}