Skip to main content

Change Permissions for Roles in Open Atrium

Today I was working on an intranet site using Open Atrium. Our client wanted to post their employee handbook on the intranet using the atrium notebook module. The problem is that, by default, all authenticated users are able to post a handbook item. Obviously, this wouldn't work with an employee being able to modify the employee handbook online.

First, I went to the 'admin/user/permissions' page and disallowed the 'create new books' and 'add content to books' permissions for my newly created 'Employee' role. Upon testing an employee user, they were still able to add book content. Hmmm?

After further investigation I discovered this article that basically said that the permissions are set using the Features module and to change them would require using a hook provided by the features module.

Enter hook_user_default_permissions_alter()

Using hook_user_default_permissions_alter() in a custom module, I was able to add the roles I wanted to the book permissions, excluding the 'employee' role. This code allows users in the 'Employee' role to view the book pages and prevents them from adding/editing/deleting books. Perfect!

The finished code looks like this:

  1. /*
  2.  * Implements hook_user_default_permissions_alter()
  3.  * 
  4.  */
  5. function MYMODULE_user_default_permissions_alter(&$permissions) {
  6.   //  Give 'add content to books' permissions to all roles except 'employee'.
  7.   $permissions['add content to books'] = array(
  8.     'name' => 'add content to books',
  9.     'roles' => array(
  10.       'administrator',
  11.       'manager',
  12.       'committee member',
  13.     ),
  14.   );
  15.   //  Give 'create book content' permissions to all roles except 'employee'.  
  16.   $permissions['create book content'] = array(
  17.     'name' => 'create book content',
  18.     'roles' => array(
  19.       'administrator',
  20.       'manager',
  21.       'committee member',
  22.     ),
  23.   );
  24.   //  Give 'create new books' permissions to all roles except 'employee'.
  25.   $permissions['create new books'] = array(
  26.     'name' => 'create new books',
  27.     'roles' => array(
  28.       'administrator',
  29.       'manager',
  30.       'committee member',
  31.     ),
  32.   );
  33.   //  Give 'edit any book content' permissions to all roles except 'employee'.  
  34.   $permissions['edit any book content'] = array(
  35.     'name' => 'edit any book content',
  36.     'roles' => array(
  37.       'administrator',
  38.       'manager',
  39.       'committee member',
  40.     ),
  41.   );
  42.   //  Give 'delete any book content' permissions to all roles except 'employee'.  
  43.   $permissions['delete any book content'] = array(
  44.     'name' => 'delete any book content',
  45.     'roles' => array(
  46.       'administrator',
  47.       'manager',
  48.       'committee member',
  49.     ),
  50.   );
  51.   //  Give 'delete own book content' permissions to all roles except 'employee'.  
  52.   $permissions['delete own book content'] = array(
  53.     'name' => 'delete own book content',
  54.     'roles' => array(
  55.       'administrator',
  56.       'manager',
  57.       'committee member',
  58.     ),
  59.   );
  60.   //  Give 'administer book outlines' permissions to all roles except 'employee'.  
  61.   $permissions['administer book outlines'] = array(
  62.     'name' => 'administer book outlines',
  63.     'roles' => array(
  64.       'administrator',
  65.       'manager',
  66.       'committee member',
  67.     ),
  68.   );
  69. }


Comments