? 646586-project-maintainer-check
Index: project_cvs_instructions.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_cvs_instructions/project_cvs_instructions.module,v
retrieving revision 1.5
diff -u -p -r1.5 project_cvs_instructions.module
--- project_cvs_instructions.module	18 Mar 2009 18:37:02 -0000	1.5
+++ project_cvs_instructions.module	14 Jul 2010 12:25:22 -0000
@@ -46,12 +46,41 @@ function project_cvs_instructions_projec
   return implode("\n", $content);
 }
 
+/**
+ * Checks if a user is a maintainer for a project.
+ */
+function project_cvs_instructions_maintainer($project, $account) {
+  if (!project_use_cvs($project)) {
+    return FALSE;
+  }
+
+  // Check if the user CVS account is approved.
+  if (!db_result(db_query("SELECT COUNT(*) FROM {cvs_accounts} WHERE uid = %d AND status = %d", $account->uid, CVS_APPROVED))) {
+    return FALSE;
+  }
+
+  // Check if the user is a maintainer for the project.
+  if (!user_access('maintain projects')) {
+    return FALSE;
+  }
+
+  if ($account->uid == $project->uid) {
+     return TRUE;
+  }
+
+  if (db_result(db_query("SELECT COUNT(*) FROM {cvs_project_maintainers} WHERE uid = %d AND nid = %d", $user->uid, $project->nid))) {
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
 function project_cvs_instructions_checkout($project, $version) {
   $content = array();
 
   global $user;
 
-  $is_maintainer = node_access('update', $project);
+  $is_maintainer = project_cvs_instructions_maintainer($project, $user);
   
   $dir = check_plain(drupal_urlencode($project->project['uri'])) . '-' . check_plain($version);
 
