Put users on probation period based on roles using Drupal rules (trial period)

The below instructions will show you how to put all newly created user accounts in a probationary period for 30 days using Drupal 7 Rules and Rule Scheduler Modules. During this 30 days when a new user creates any content, it will be unpublished until a admin publishes it.  Administrators will receive an email letting them know that a probationary user has created content and it needs attention.  This email will provide the administrators with a link to the newly created content so they can publish it.  After 30 days the "probation" role will be automatically removed and the user will be able to post without restriction. 

 

 

1. Create User Role - Create the user role to be assigned for a probation period.  In my case, it will be for for new users so I will create a rule that attaches the role after saving their profile.

  1. In the administration menu, click the People tab
  2. Click PERMISSIONS tab
  3. Under that click the Roles button
  4. Name your Role, in my case I called it "Probation"
  5. Click Add role
  6. Then click edit permissions
  7. Assign the permissions you would like to give this user role.  In my case I am only giving the user permissions to view published content, create forum topics and post comments.

2. Create rule to add the role to a user.  In this case, it will be all new users.

  1. In the top admin menu click Configuration
  2. In the Workflow section click Rules
  3. Click Add new rule
  4. Name your rule and select the react on event from the drop down menu.  In this case the event is "After saving a new user account" in the User section.
  5. Click save
  6. Click Add action
  7. Select the action to add: Select the "Add user role"
  8.  Leave default Data selector: account
  9. Under Roles section, select the role you would like added.
  10. Save

3. Create Rule to restrict "Probation" role from publishing new content. In this case, post new forum topics.

  1. In the top admin menu click Configuration
  2. In the Workflow section click Rules
  3. Click Add new rule
  4. Name your rule and select the react on event from the drop down menu.  In this case the event is "After saving a new content" in the Node section.
  5. I use restrict by type- Select the content type you would like. (I am using forum topic)
  6. Click save
  7. Click Add Condition
  8. Select "User has role(s)"
  9. In the Data selector enter: site:current-user
  10. Under the ROLES section select the role you want the rule applied to. (Mine is probation)
  11. Click Save
  12. Click Add action
  13. Select the action to add: Select the "Unpublish content" in the Node section
  14.  Leave default Data selector: node
  15. Save

4. Make a page for a re-direct after "probation" user saves new content.  The thought process here is that you want to let the user know that their post will need to be approved by an Admin before it is published to the website.  You can just create a Basic page for this and add the text you would like for the body.

 

5. Create Rule for the re-direct after a new user creates content.

  1. In the top admin menu click Configuration
  2. In the Workflow section click Rules
  3. Click Add new rule
  4. Name your rule and select the react on event from the drop down menu. The event is "After saving a new content" in the Node section.
  5. Restrict by type- Select the content type you would like. ( forum topic)
  6. Click save
  7. Click Add Condition
  8. Select "User has role(s)"
  9. In the Data selector enter: site:current-user
  10. Under the ROLES section select the role you want the rule applied to. (Mine is probation)
  11. Click Save
  12. Click Add action
  13. Select the action to add: Select the "Page redirect" in the System section
  14.  In the URL section put the URL of the page you created in Step 4
  15. Save

6.  Remove the "Probation" role after 30 days.  This is a little different from the rules above. For this we need to create a Component called an Action set.

  1. In the Rules page select the tab on the right labeled "Components"
  2. Click Add new component
  3. Select Rule Set from the drop down
  4. Name your Rule set.  I named mine "Expire Probation Role {rule_set}"
  5. Under DATA TYPE select User, then label it "User {argument}", machine name "user_argument"
  6. In the Section USAGE, leave this as Parameter
  7. Click continue
  8. Add Rule 
  9. Name this Rule IE: Expire action {rule}
  10. Add action
  11. Select Remove user role 
  12. Data selector should be: user_argument
  13. Under ROLES select the role you would like to remove.
  14. Go back to the Rules UI (User Interface/ the Rules page)
  15. Add new rule
  16. Name your rule.  I named mine "Remove Probation Role {trigger rule}"
  17. React on event is After saving new user account
  18. Add action
  19. Select the action to add = Schedule component evaluation
  20. Under the Value drop down select the component you created above (Expire action {rule})
  21. Click continue
  22. Under SCHEDULE EVALUATION DATE click switch to data selection
  23. Under DATA SELECTOR enter account:created
  24. In the ADD OFFSET enter the time in which you would like the probation to end. In this case it is 30 days.
  25. In the IDENTIFIER enter "Remove User role [account:roles] "
  26. In the USER {ARGUMENT} section enter account.
  27. Click save

 

Some of these Rules can be combined but for this post, I kept them all separated.

Please excuse all typos... I am surprise I can see half the time. :)

~Drupal Rules!

Pieced together from-
References and many thanks to:

https://drupalize.me/videos/using-fields-setting-evaluation-time?p=1157 -Johan Falk 

https://www.drupal.org/node/1228560 - Alastair Moore (welly)