You are here

function secure_permissions_build_permissions in Secure Permissions 6

Same name and namespace in other branches
  1. 7.2 secure_permissions.module \secure_permissions_build_permissions()
  2. 7 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 189
Secure Permissions module file.

Code

function secure_permissions_build_permissions() {

  // Get the active roles on the site.
  $roles = user_roles();

  // List all permissions.
  $permissions = array_values(module_invoke_all('perm'));

  // Now set permissions per role, using our hook.
  foreach ($roles as $rid => $role) {
    $new_permissions = module_invoke_all('secure_permissions', $role);
    if (empty($new_permissions)) {
      return FALSE;
    }

    // Revoke all permissions.
    db_query("DELETE FROM {permission} WHERE rid = %d", $rid);
    permissions_grant_permissions($role, $new_permissions);
  }
  return TRUE;
}