Index: workflow.install =================================================================== --- workflow.install (revision 2480) +++ workflow.install (working copy) @@ -17,6 +17,7 @@ foreach (node_get_types() as $type => $name) { variable_del('workflow_'. $type); } + variable_del('workflow_user0_is_author'); drupal_uninstall_schema('workflow'); } Index: workflow_access.module =================================================================== --- workflow_access.module (revision 2480) +++ workflow_access.module (working copy) @@ -13,10 +13,9 @@ * roles as access lists, so rids translate directly to gids. */ function workflow_access_node_grants($account, $op) { - return array( - 'workflow_access' => array_keys($account->roles), - 'workflow_access_owner' => array($account->uid), - ); + $access['workflow_access'] = array_keys($account->roles); + if ($account->uid || variable_get('workflow_user0_is_author',0)) $access['workflow_access_owner'] =array($account->uid); + return $access; } /** @@ -30,15 +29,29 @@ // We have state information about this node, so get permissions for this state. if (is_numeric($sid)) { + $authors = workflow_get_authors($node); $result = db_query('SELECT * FROM {workflow_access} WHERE sid = %d', $sid); while ($grant = db_fetch_object($result)) { - $grants[] = array( - 'realm' => ($grant->rid == -1) ? 'workflow_access_owner' : 'workflow_access', - 'gid' => ($grant->rid == -1) ? $node->uid : $grant->rid, - 'grant_view' => $grant->grant_view, - 'grant_update' => $grant->grant_update, - 'grant_delete' => $grant->grant_delete - ); + if ($grant->rid == -1 ) { + foreach($authors as $uid) { + $grants[] = array( + 'realm' => 'workflow_access_owner' , + 'gid' => $uid, + 'grant_view' => $grant->grant_view, + 'grant_update' => $grant->grant_update, + 'grant_delete' => $grant->grant_delete + ); + } + } else { + $grants[] = array( + 'realm' =>'workflow_access', + 'gid' => $grant->rid, + 'grant_view' => $grant->grant_view, + 'grant_update' => $grant->grant_update, + 'grant_delete' => $grant->grant_delete + ); + } + } } Index: workflow.admin.inc =================================================================== --- workflow.admin.inc (revision 2480) +++ workflow.admin.inc (working copy) @@ -656,6 +656,12 @@ '#default_value' => variable_get('workflow_' . $type, array('node')), ); } + $form['workflow_user0_is_author'] = array( + '#title'=> 'Treat Anonymous as valid author', + '#default_value'=>variable_get('workflow_user0_is_author',0), + '#description' => 'This will treat all anonymous users as author when node author is anonymous.', + '#type'=>'checkbox', + ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save workflow mapping') @@ -677,6 +683,7 @@ $output = drupal_render($form['help']); $output .= theme('table', $header, $rows); return $output . drupal_render($form); + } /** @@ -686,6 +693,8 @@ */ function workflow_types_form_submit($form, &$form_state) { workflow_types_save($form_state['values']); + + variable_set('workflow_user0_is_author', $form_state['values']['workflow_user0_is_author']); drupal_set_message(t('The workflow mapping was saved.')); menu_rebuild(); $form_state['redirect'] = 'admin/build/workflow'; Index: workflow.module =================================================================== --- workflow.module (revision 2480) +++ workflow.module (working copy) @@ -107,6 +107,19 @@ return $items; } +function workflow_get_authors($node){ + $authors = array($node->uid => $node->uid); + drupal_alter('workflow_authors',$authors,$node) ; + if(is_array($authors)) return $authors; + else return array(); +} + +function workflow_workflow_authors_alter(&$authors,$node) { + if (!variable_get('workflow_user0_is_author',0)) { + $key = array_search(0,$authors); + if ($key !== false) unset($authors[$key]); + } +} /** * Menu access control callback. Determine access to Workflow tab. */ @@ -118,9 +131,11 @@ return FALSE; } $roles = array_keys($user->roles); - if ($node->uid == $user->uid) { + $authors = workflow_get_authors($node); + if (in_array($user->uid,$authors)) { $roles = array_merge(array('author'), $roles); } + $workflow = db_fetch_object(db_query("SELECT * FROM {workflows} WHERE wid = %d", $wid)); $allowed_roles = $workflow->tab_roles ? explode(',', $workflow->tab_roles) : array(); @@ -683,7 +698,8 @@ $current_sid = workflow_node_current_state($node); // If user is node author or this is a new page, give the authorship role. - if (($user->uid == $node->uid && $node->uid > 0) || (arg(0) == 'node' && arg(1) == 'add')) { + $authors = workflow_get_authors($node); + if ((in_array($user->uid,$authors)) || (arg(0) == 'node' && arg(1) == 'add')) { $roles += array('author' => 'author'); } if ($user->uid == 1) {