| 1 |
<?php |
<?php |
| 2 |
// $Id: workflow_access.module,v 1.1.2.1 2007/04/26 16:02:17 mfredrickson Exp $ |
// $Id: workflow_access.module,v 1.1.2.2 2008/07/09 18:27:50 jvandyk Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 6 |
* Provides node access permissions based on workflow states. |
* Provides node access permissions based on workflow states. |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 18 |
/** |
/** |
| 19 |
* Implementation of hook_disable(). |
* Implementation of hook_disable(). |
| 20 |
* |
* |
| 21 |
* Force a rebuild of the node access table when disabled to ensure |
* Force a rebuild of the node access table when disabled to ensure |
| 22 |
* that our entries are removed from the table. |
* that our entries are removed from the table. |
| 23 |
*/ |
*/ |
| 24 |
function workflow_access_disable() { |
function workflow_access_disable() { |
| 73 |
'grant_view' => $grant->grant_view, |
'grant_view' => $grant->grant_view, |
| 74 |
'grant_update' => $grant->grant_update, |
'grant_update' => $grant->grant_update, |
| 75 |
'grant_delete' => $grant->grant_delete |
'grant_delete' => $grant->grant_delete |
| 76 |
); |
); |
| 77 |
} |
} |
| 78 |
} |
} |
| 79 |
|
|
| 83 |
/** |
/** |
| 84 |
* Implementation of hook_form_alter(). |
* Implementation of hook_form_alter(). |
| 85 |
* |
* |
| 86 |
* Add a "three dimensional" (state, role, permission type) configuration |
* Add a "three dimensional" (state, role, permission type) configuration |
| 87 |
* interface to the workflow edit form. |
* interface to the workflow edit form. |
| 88 |
*/ |
*/ |
| 89 |
function workflow_access_form_alter($form_id, &$form) { |
function workflow_access_form_alter($form_id, &$form) { |
| 92 |
return; |
return; |
| 93 |
} |
} |
| 94 |
|
|
| 95 |
// A list of roles available on the site and our |
// A list of roles available on the site and our |
| 96 |
// special -1 role used to represent the node author. |
// special -1 role used to represent the node author. |
| 97 |
// TODO i think there is an API call for this -- user_roles() perhaps? |
// TODO i think there is an API call for this -- user_roles() perhaps? |
| 98 |
$rids = array('-1' => t('author')); |
$rids = array('-1' => t('author')); |
| 99 |
$result = db_query("SELECT r.rid, r.name FROM {role} r ORDER BY r.name"); |
$result = db_query("SELECT r.rid, r.name FROM {role} r ORDER BY r.name"); |
| 100 |
while ($obj = db_fetch_object($result)) { |
while ($obj = db_fetch_object($result)) { |
| 101 |
$rids[$obj->rid] = $obj->name; |
$rids[$obj->rid] = check_plain($obj->name); |
| 102 |
} |
} |
| 103 |
|
|
| 104 |
$form['workflow_access'] = array('#type' => 'fieldset', |
$form['workflow_access'] = array('#type' => 'fieldset', |
| 105 |
'#title' => t('Access control'), |
'#title' => t('Access control'), |
| 106 |
'#collapsible' => TRUE, |
'#collapsible' => TRUE, |
| 107 |
'#tree' => TRUE, |
'#tree' => TRUE, |
| 110 |
// Add a table for every workflow state. |
// Add a table for every workflow state. |
| 111 |
$states = workflow_get_states($form['wid']['#value']); |
$states = workflow_get_states($form['wid']['#value']); |
| 112 |
foreach ($states as $sid => $state) { |
foreach ($states as $sid => $state) { |
| 113 |
|
|
| 114 |
if (workflow_is_system_state($state)) { |
if (workflow_is_system_state($state)) { |
| 115 |
continue; // no need to set perms on creation |
continue; // no need to set perms on creation |
| 116 |
} |
} |
| 117 |
|
|
| 118 |
$view = $update = $delete = array(); |
$view = $update = $delete = array(); |
| 119 |
|
|
| 120 |
$result = db_query("SELECT * from {workflow_access} where sid = %d", $sid); |
$result = db_query("SELECT * from {workflow_access} where sid = %d", $sid); |
| 121 |
|
|
| 122 |
// Allow view grants by default for anonymous and authenticated users, |
// Allow view grants by default for anonymous and authenticated users, |
| 123 |
// if no grants were set up earlier. |
// if no grants were set up earlier. |
| 124 |
if (db_num_rows($result) == 0) { |
if (db_num_rows($result) == 0) { |
| 125 |
$view = array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID); |
$view = array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID); |
| 136 |
$delete[] = $access->rid; |
$delete[] = $access->rid; |
| 137 |
} |
} |
| 138 |
} |
} |
| 139 |
|
|
| 140 |
// TODO better tables using a #theme function instead of direct #prefixing |
// TODO better tables using a #theme function instead of direct #prefixing |
| 141 |
$form['workflow_access'][$sid] = array( |
$form['workflow_access'][$sid] = array( |
| 142 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 143 |
'#title' => $state, |
'#title' => check_plain(t($state)), |
| 144 |
'#collapsible' => TRUE, |
'#collapsible' => TRUE, |
| 145 |
'#tree' => TRUE, |
'#tree' => TRUE, |
| 146 |
); |
); |
| 179 |
foreach ($form_values['workflow_access'] as $sid => $access) { |
foreach ($form_values['workflow_access'] as $sid => $access) { |
| 180 |
// Ignore irrelevant keys. |
// Ignore irrelevant keys. |
| 181 |
if (!is_numeric($sid)) { |
if (!is_numeric($sid)) { |
| 182 |
continue; |
continue; |
| 183 |
} |
} |
| 184 |
|
|
| 185 |
$grants = array(); |
$grants = array(); |