Limit node creation based on user roles

Events happening in the community are now at Drupal community events on www.drupal.org.
anithegregorian's picture

Im trying to limit the creation of nodes by user roles for eg. Subscriber (can create only 2 nodes) while Contributors (can create upto 5 nodes) by using Rules for D7.

So far its turned out pretty good but only upto displaying a message before saving node content. Instead what I am rolling over my head is to decide what user is currently logged in (particularly his role) and how many nodes he has created, then matching that node count with a fixed number, if the condition evaluates to TRUE then deny any further node creation.

On D6 this becomes a cakewalk with Node Limit module. Here is the export of Ruleset I currently have which is not much :(

{ "rules_limit_subscriber_submission" : {
    "LABEL" : "Limit Subscriber Submission",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "REQUIRES" : [ "rules", "php" ],
    "ON" : [ "node_presave" ],
    "IF" : [
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "5" : "5" } }
        }
      }
    ],
    "DO" : [
      { "php_eval" : { "code" : "global $user;\r\n$limit_message = 'You are not allowed to enter more than 2 entry!';\r\ndrupal_set_message($limit_message, 'warning', FALSE);\r\nprint_r($user);" } }
    ]
  }
}

Comments

How is that rule used?

dlirit's picture

Do you put it in a module?

SOLVED: Rules Based Solution

wOOge's picture

This post gave me a head start on what I needed to make this work — I've created a tutorial to accomplish this:

http://drupal.org/node/1893978

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week