Index: modules/cvslog/cvs.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/cvslog/cvs.module,v retrieving revision 1.109 diff -u -F^f -r1.109 cvs.module --- modules/cvslog/cvs.module 16 Jun 2006 07:29:00 -0000 1.109 +++ modules/cvslog/cvs.module 18 Jun 2006 04:06:27 -0000 @@ -337,8 +337,16 @@ function cvs_nodeapi(&$node, $op, $arg = /** * Implementation of hook_form_alter(). + * + * For the project node form, add a fieldset for data related + * to the CVS repository of the project. + * + * For the issue node form, determine if the current user is a + * maintainer of the project, and if so expand the list of + * available issue assignees. */ function cvs_form_alter($form_id, &$form) { + global $user; if ($form_id == 'project_project_node_form') { $node = $form['#node']; $result = db_query("SELECT rid, name FROM {cvs_repositories}"); @@ -371,6 +379,37 @@ function cvs_form_alter($form_id, &$form '#required' => TRUE, ); } + else if ($node_id = 'project_issue_node_form') { + // First, we have to figure out what project this issue is + // associated with, so we can find the right cvs maintainers for it + if (isset($_POST['edit']['pid'])) { + $pid = $_POST['edit']['pid']; + } + elseif (isset($form['project_issue_form']['project_info']['pid']['#default_value'])) { + $pid = $form['project_issue_form']['project_info']['pid']['#default_value']; + } + // Only act if we found a project id and if the current user is a + // maintainer of that project. + if (isset($pid) && cvs_is_project_maintainer($pid, $user->uid)) { + $maintainers = array(); + $result = db_query("SELECT u.name, u.uid FROM {users} u INNER JOIN {cvs_project_maintainers} cpm ON u.uid = cpm.uid WHERE cpm.nid = %d", $pid); + while ($maintainer = db_fetch_object($result)) { + $maintainers[$maintainer->uid] = $maintainer->name; + } + $result = db_query("SELECT u.name, u.uid FROM {users} u INNER JOIN {node} n ON u.uid = n.uid WHERE n.nid = %d", $pid); + $owner = db_fetch_object($result); + $maintainers[$owner->uid] = $owner->name; + + // Unfortunately, the issue form will be nested 1 layer deeper + // if this is a followup to an existing issue. :( + if (isset($form['project_issue_form'])) { + $form['project_issue_form']['issue_info']['assigned']['#options'] = array_merge($form['project_issue_form']['issue_info']['assigned']['#options'], $maintainers); + } + else { + $form['issue_info']['assigned']['#options'] = array_merge($form['issue_info']['assigned']['#options'], $maintainers); + } + } + } } /** @@ -1655,6 +1694,26 @@ function cvs_project_delete_access_confi } /** + * Determine if a user is a maintainer of a given project. + * + * @param $nid + * The id of a project node. + * @param $uid + * A user id. + * @return + * Boolean, where TRUE means the user is an maintainer and FALSE means she/he is not. + */ +function cvs_is_project_maintainer($nid, $uid) { + $result = db_query("SELECT * FROM {node} n WHERE n.nid = %d AND n.uid = %d", $nid, $uid); + if (db_num_rows($result)) { + return TRUE; + } + $result = db_query("SELECT * FROM {users} u INNER JOIN {cvs_project_maintainers} cpm ON u.uid = cpm.uid WHERE cpm.nid = %d AND u.uid = %d", $nid, $uid); + $rval = db_num_rows($result); + return $rval ? TRUE : FALSE; +} + +/** * Returns a string of suggestions for users with CVS accounts, * formatted to be suitable for use with JS autocomplete fields. */