| Download | Size | md5 hash |
|---|---|---|
| permissions_api-6.x-2.x-dev.tar.gz | 12.53 KB | 4585f7d8d286f5ae24f2c04c35075f50 |
| permissions_api-6.x-2.x-dev.zip | 14.88 KB | 2a1fc697c2c9924459d7adca700c18c6 |
Release notes
UPDATE: This version of the module has changed the first argument to all APIs defined by this module. In prior versions, the first argument was an integer representing a role id. This new version accepts a string representing the name of a role, and each API does a lookup to retrieve the proper role id.
The permissions_api module provides a method for adding and removing permissions from a given role. This module helps with the issue of staging a Drupal site across multiple environments, from development sandbox to production environment.
A specific example includes importing a CCK content type definition via hook_update in a custom module:
<?php
// Configure the path to the cck content type definition
$modulepath = drupal_get_path ('module', 'some_module');
$cck_definition_file = $modulepath.'/content_types/front_page_flash.php';
$values['type_name'] = '<create>';
$values['macro'] = file_get_contents($cck_definition_file);
include_once( drupal_get_path('module', 'node') .'/content_types.inc');
include_once( drupal_get_path('module', 'content') .'/content_admin.inc');
// Import the cck content type
drupal_execute("content_copy_import_form", $values);
?>This is great until you decide that you want members of specific roles to be able to do something with this content type. Currently, the only way to grant the permissions is to navigate through the access control page in the admin interface, which is completely unusable if you have a lot of roles and a lot of modules.
This module addresses that problem by providing two functions:
permissions_grant_permissions()
permissions_revoke_permissions()
Each function accepts a role id and an array of permissions. Sample usage would be:
<?php
function mymodule_update_1(){
// Handle roles and permissions
$permissions = array(
'create some_content_type content',
'edit some_content_type content',
'edit own some_content_type content',
);
permissions_grant_permissions('some role', $permissions);
}
?>This module also provides functions for granting all permissions defined by a given module to a given role, as well as granting all defined permissions to a given role, which is useful for creating admin-type roles. Sample usage would be:
<?php
function mymodule_update_2(){
// Create a "super-admin" role by granting all permissions
permissions_grant_all_permissions('some admin role');
}
?>The next example shows how to grant all permissions defined by a specific module to a specific role:
<?php
function mymodule_update_3(){
// Grant all permissions defined by a module's hook_perm implementation
permissions_grant_all_permissions_by_module('some role', 'some module')
}
?>INSTALLATION
------------
Install and enable the permissions_api Drupal module as you would any Drupal module.
CREDITS
-------
Developed and maintained by Erich Beyrent
Sponsored by CommonPlaces e-Solutions, LLC