You are here

function secure_permissions_build_permissions in Secure Permissions 7

Same name and namespace in other branches
  1. 6 secure_permissions.module \secure_permissions_build_permissions()
  2. 7.2 secure_permissions.module \secure_permissions_build_permissions()

Build function to create the permissions arrays.

1 call to secure_permissions_build_permissions()
secure_permissions_rebuild in ./secure_permissions.module
Rebuild permissions, based on presets from the API.

File

./secure_permissions.module, line 230
Secure Permissions module file.

Code

function secure_permissions_build_permissions() {

  // Get the active roles on the site.
  $roles = secure_permissions_get_existing_roles();
  $admin_rid = variable_get('user_admin_role', 0);

  // Do not touch the administrative role.
  if (!empty($admin_rid) && isset($roles[$admin_rid])) {
    unset($roles[$admin_rid]);
  }

  // List all permissions.
  $permissions = array_keys(module_invoke_all('permission'));

  // Now set permissions per role, using our hook.
  $permissions_rebuilt = FALSE;
  foreach ($roles as $rid => $role) {
    $perms = array();
    $new_permissions = module_invoke_all('secure_permissions', $role);
    foreach ($permissions as $perm) {
      $perms[$perm] = FALSE;
      if (in_array($perm, $new_permissions)) {
        $perms[$perm] = TRUE;
        $permissions_rebuilt = TRUE;
      }
    }
    user_role_change_permissions($rid, $perms);
  }
  return $permissions_rebuilt;
}