permissions_api 5.x-1.0

ebeyrent - October 14, 2008 - 01:29
Download Size md5 hash
permissions_api-5.x-1.0.tar.gz 7.44 KB f1c58d97379543d6ddef02d85bdac2ea
Official release from CVS tag: DRUPAL-5--1-0
Last updated: October 14, 2008 - 01:30

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
 
$rid = db_result(db_query('SELECT rid FROM {role} r WHERE r.name = \'some custom role\''));
  if(
$rid > 0){
   
$permissions = array(
     
'create some_content_type content',
     
'edit some_content_type content',
     
'edit own some_content_type content',
    );
   
permissions_grant_permissions($rid, $permissions); 
  }
}
?>

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

 
 

Drupal is a registered trademark of Dries Buytaert.