On this page
- Step by Step
- Step One: Create the user roles
- Step Two: Create the Department taxonomy
- Step Three: Add Department fields
- Step Four: Create the Department access policy
- Step Five: Create some content restricted by department
- Step Six: View the content as an employee
- Step Seven: Create Term department access policy
- Step Eight: Turn on manual mode for taxonomy terms.
- Step Nine: Restrict terms by department
Group content by department
In this tutorial we’re going to use the Access Policy module to create sections of content based on department. Each section will have one or more Content managers. Employees can view all the content in their respective department without being able to edit it.
Step by Step
Step One: Create the user roles
Add the Content manager role
This role is responsible for managing the content, they’ll be able to edit and view all the content in their department.
- Go to /admin/people/roles
- Create a new Role called “Content manager” with the following permissions
- View published content
- Access the Content overview page
- View own unpublished content
- Basic page: Create new content
- Basic page: Edit any content
- Basic page: Delete any content
- Basic page: Delete own content
- Basic page: Edit own content
- Use the toolbar
- View the administration theme
- Create a new Role called “Employee” with the following permissions
- View published content
- Access the Content overview page
- Use the toolbar
Now we have our roles, however Content managers can still edit all basic pages. We don’t want that! So let’s start to restrict content by department.
Step Two: Create the Department taxonomy
- Go to /admin/structure/taxonomy
- Create a new Vocabulary called “Department”
- Add the following terms
- Marketing
- Operations
- Finance
Step Three: Add Department fields
- Add a new Taxonomy term entity reference field to the Basic page
- Give it the label “Department”
- Leave allowed number of values set to 1
- Choose the Department vocabulary and click Save settings.
- Go to /admin/config/people/accounts/fields
- Add a new Taxonomy term entity reference field to the user
- Give it the label “Department”
- Leave allowed number of values set to 1
- Choose the Department vocabulary and click Save settings.
We’ve set up our fields, now let’s get them talking to each other!
Step Four: Create the Department access policy
- If you haven’t already, download and install the Access policy module.
- Enable the access_policy_ui sub module.
- Go to /admin/people/access-policies
- Add a new Access policy called “Department”
- Edit the permissions for the Employee role and grant the following permission:
- Department: View any content assigned this access policy
- Edit the permissions for the Content manager role the and grant the following permissions:
- Department: Assign to any content
- Department: Delete any content assigned this access policy
- Department: Edit any content assigned this access policy.
- Department: View any content assigned this access policy.
- Department: View any unpublished content assigned this access policy.
- Click Add access rule
- Search for and select “Compare Department with user”
- Note that you can also choose “Compare Department with user (with depth)” if you want to support hierarchy!
- For the operator choose “Is one of”
- For user field choose “Department”
- This will compare the node’s department with the user’s department and ensure that they match.
- Leave all other options as they are and click save.
- Go to Manage selection
- Click Add selection rule
- Select Department > Click add rule
- Under operator choose Is not empty
- Under field access settings change it to Permission and leave the default permission selected.
- Save the selection rule
- We add a selection rule in order to do two things: Limit this access policy to only nodes that have the Department field, and tell it to assign this policy when that field has a value.
Now with the Department access policy in place, you can create sections of content for each department. Let’s do that now!
Step Five: Create some content restricted by department
- Log in as a Content Manager whose department is set to “Finance”
- Create a new Basic page
- Note on the right column that Access is currently set to Unrestricted. Let’s change that.
- From the Department field, change it to “Finance” and save the node.
- Right now all content managers can restrict content to any department (yikes!). That's ok though, we'll take care of that.
- Edit the node again
- Observe that Access has changed to “Department”
Step Six: View the content as an employee
- Create a new employee with Department set to Operations
- Log in as that employee
- Go to /admin/content
- Observe that no content is available for that employee.
- Change their Department to Finance
- Go back to /admin/content
- Observe that they can now see the content!
And that’s it! You can now serve content for different departments!
However, we do have one security issue that we mentioned earlier. Content managers can assign content to any department. That's not good! Let's start restricting those terms now.
Step Seven: Create Term department access policy
Access policy supports more than just content. You can restrict taxonomy terms, media, block content and even paragraphs! For the rest of this tutorial we're going to lock down taxonomy terms so that authors can't assign the wrong ones.
- Go to /admin/people/access-policies
- Add a new Access policy called “Term department”
- For Entity type choose "Taxonomy term"
- Edit the permissions for the Content manager role and grant the following permission:
- Term department: View any taxonomy term assigned this access policy
- Click Add access rule
- Search for and add the access rule: Current user: Has reference to this taxonomy term
- Go to Manage selection
- Click Add selection rule
- Select Vocabulary > Click add rule
- For Value choose "Department"
- Save the selection settings.
Step Eight: Turn on manual mode for taxonomy terms.
Managing access on taxonomy terms is easier with Manual mode turned on. Let's do that now!
- Go to /admin/people/access-policies
- Click Taxonomy term settings
- Under Selection mode choose “Manual”
- Enable "Show operations link"
- For Default policy choose "First available"
- Save the settings
- Clear the Drupal cache.
Step Nine: Restrict terms by department
- Go to /admin/structure/taxonomy/manage/department/overview
- Change the access for each of the terms to "Term department"
Now Content managers will only have access to the terms assigned to them!
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.