/[drupal]/contributions/modules/workflow/workflow_access.module
ViewVC logotype

Diff of /contributions/modules/workflow/workflow_access.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.2, Wed Jul 9 18:27:50 2008 UTC revision 1.1.2.3, Fri Oct 23 15:08:26 2009 UTC
# Line 1  Line 1 
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    
# Line 18  function workflow_access_enable() { Line 18  function workflow_access_enable() {
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() {
# Line 73  function workflow_access_node_access_rec Line 73  function workflow_access_node_access_rec
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    
# Line 83  function workflow_access_node_access_rec Line 83  function workflow_access_node_access_rec
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) {
# Line 92  function workflow_access_form_alter($for Line 92  function workflow_access_form_alter($for
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,
# Line 110  function workflow_access_form_alter($for Line 110  function workflow_access_form_alter($for
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);
# Line 136  function workflow_access_form_alter($for Line 136  function workflow_access_form_alter($for
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      );      );
# Line 179  function workflow_access_form_submit($fo Line 179  function workflow_access_form_submit($fo
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();

Legend:
Removed from v.1.1.2.2  
changed lines
  Added in v.1.1.2.3

  ViewVC Help
Powered by ViewVC 1.1.2