You are here

function hosting_add_permissions in Hosting 7.3

Same name and namespace in other branches
  1. 7.4 hosting.features.inc \hosting_add_permissions()

Add a Hosting Feature's permissions to the appropriate roles.

Parameters

string $module: The name of the Hosting Feature module whose permissions we're adding.

array $role_perms: An array of arrays keyed by the role name. The values are the permissions to enable.

1 call to hosting_add_permissions()
hosting_features_enable in ./hosting.features.inc
Enable one or more Hosting features.

File

./hosting.features.inc, line 553
Include for functionality related to Hosting module features.

Code

function hosting_add_permissions($module, $role_perms) {

  // Make sure permissions exist before adding them, since we might want to add
  // permissions from optional modules.
  $permissions = user_permission_get_modules();
  foreach ($role_perms as $role => $perms) {
    foreach ($perms as $i => $permission) {
      if (!isset($permissions[$permission])) {
        unset($role_perms[$role][$i]);
      }
    }
  }

  // The Aegir admin role automatically gets all permissions from any hosting module.
  if (function_exists($module . '_permission')) {
    $perms = module_invoke($module, 'permission');
    foreach (array_keys($perms) as $perm) {
      $role_perms['aegir administrator'][] = $perm;
    }
  }
  foreach (user_roles() as $rid => $name) {
    if (array_key_exists($name, $role_perms)) {
      user_role_grant_permissions($rid, $role_perms[$name]);
      drupal_set_message(t("The '%role' role was assigned the following permission!plural: '%perms'.", array(
        '%role' => $name,
        '%perms' => implode('\', \'', $role_perms[$name]),
        '!plural' => count($role_perms[$name]) > 1 ? 's' : '',
      )));
    }
  }
}