I posted this in the Rules group, and someone suggested coming here with this question. Is there a way to prevent node creation via Rules? I want to be able to prevent someone from creating node if certain conditions are true.
Right now, the best idea I've had for this is to create a special-purpose role that allows creation of my node types, and grant or remove that role via rules, but this feels clunky and really pollutes the admin/user/permissions page (since I need to do this for several node types).
Is there another way to do this? If not, is it in the roadmap?
Comments
Comment #1
mitchell commentedRules is so generalized that the main task in implementing this on your site is not by adding a special feature to rules but rather applying your imagination. Coincidentally, that's the part I like most about Drupal.
The current userpoints_rules.module has a userpoints_action_grant_points function, but I'm not sure if that can award negative points. If you could check into that, that might help in exploring this further.
Best of luck!
Comment #2
Charlie Sibbach commentedI just confirmed that it does allow you to award negative points, but only into the default ("uncategorized") tally. However, without a condition like you mention above (checking for userpoints), this isn't much better than the Nodes and Comments system already in place (which lets you assign a reward to different node types).
As to using your imagination, I agree, that is one of the most rewarding parts of Drupal. Between Rules and Views, I stay quite amused.
Comment #3
mitchell commentedNew opinion: if you just want to put a true/false next to a user for a certain permission, then use a non-global Flag. It's not all that different from roles or userpoints, but it's simple true/false, and it's a really good API with really tight #298109: Rules integration.
Comment #4
amitaibuYou can't prevent a node creation with Rules, but you can create a rule that will delete a newly created node.
Comment #6
mmilo commentedSorry, this seems like a silly bump.
I can't find how to delete a newly created node - it isn't in the list of actions. I'm using the latest dev version. This wouldn't be due to the fact that my event is 'After saving new content' is it?
Thanks!
Comment #7
fagohm, I think there is no action for deleting nodes yet.
Comment #8
mmilo commentedAre there any plans to have an action for deleting nodes / prevent the creation of a node?
Comment #9
fagoI do not have any plans, but I'd add an action for deleting content. Just roll a patch.
Comment #10
mitchell commentedChanging to feature request.
Comment #11
klausiTaking over.
Comment #12
klausiPatch is attached.
Comment #13
amitaibuMinor issues:
+ * We cannot use node_delete() because it does access checks and ouput.
ouput -> output. Maybe worth adding
@see node_delete()+ * Action "Delete content" - Label callback
Label -> label.
Comment #14
klausiGood idea, fixed.
Comment #15
fagothanks, committed. :)
Comment #17
v-a-1 commentedThis is in response to [amitaibu] above
Thats incorrect.
You can. Its really simple too.
Create rule of type "content is going to be saved"
Add condition "if content type is xxx"
And whatever other condition you require to return true or false.
Add action "system page redirect" and set configuration to redirect to the same page.
Set configuration of above action to "immediately issue redirect".
This will stop the process of node creation in its tracks and send the user back to the node creation page.
It is generally required that you issue an error notice to the user.
You can do this by adding a "set configurable system message" action BEFORE the page redirect action.
Hope this helps.