diff -urp old/content_access.module new/content_access.module
--- old/content_access.module	2008-01-15 16:27:18.000000000 +0530
+++ new/content_access.module	2008-04-19 17:44:09.843750000 +0530
@@ -3,7 +3,7 @@
 
 if (module_exists('workflow_ng')) {
   include_once(drupal_get_path('module', 'content_access') .'/content_access.workflow_ng.inc');
-}
+}
 
 /*
  * Implementation of hook_menu().
@@ -59,7 +59,19 @@ function content_access_perm() {
  */
 function content_access_node_grants($account, $op) {
   $return = array('content_access_rid' => array_keys($account->roles));
-  return $account->uid ? array('content_access_author' => array($account->uid)) + $return : $return;
+  $account->uid ? $return = $return + array('content_access_author' => array($account->uid)) : NULL;
+
+  // Return all groups user is admin.
+  if ($account->og_groups) {
+    $og = array();
+    foreach ($account->og_groups as $og_group) {
+      if ($og_group['is_admin']) {
+        $og[] = $og_group['nid'];
+      }
+    }
+    $return = $return + array('content_access_group_admin' => $og);
+  }
+  return $return;
 }
 
 /*
@@ -100,7 +112,14 @@ function content_access_page_form($defau
     if (!isset($defaults[$op])) $defaults[$op] = array();
   }
   
-  $roles = content_access_get_roles_and_author();
+  $roles = content_access_get_roles_and_arguments();
+  if (module_exists('og')) {
+    $form['og_explain'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Organic group'),
+      '#description' => t('"organic group admin" option has been added in order to control the permissions according to group admins.'),
+    );
+  }
   $form['settings'] = array(
     '#type' => 'fieldset', 
     '#title' => t('Role access control settings'),
@@ -184,14 +203,20 @@ function content_access_page_submit($for
  * Per content type administration page form.
  */
 function content_access_admin_settings($type) {
-  $roles = content_access_get_roles_and_author();
+  $roles = content_access_get_roles_and_arguments();
   // Per node:
+  $description = t('Optionally you can enable per node access control settings. '.
+    'Configure access to the per node access settings at drupal\'s access control permission page.');
+  if (module_exists('og')) {
+    $description .= '<br>' . '---';
+    $description .= '<br>' . t('Organic Groups module has been detected.');
+    $description .= '<br>' . t('"organic group admin" option has been added in order to control the permissions according to group admins.');
+  }
   $form['node'] = array(
     '#type' => 'fieldset',
     '#title' => t('Per node access control settings'),
     '#collapsible' => TRUE,
-    '#description' => t('Optionally you can enable per node access control settings. '.
-      'Configure access to the per node access settings at drupal\'s access control permission page.'),
+    '#description' => $description,
   );
   $form['node']['per_node'] = array(
     '#type' => 'checkbox',
@@ -292,23 +317,28 @@ function content_access_node_access_reco
     return;
   }
 
-  // Apply per node settings if necessary.
-  if (content_access_get_settings('per_node', $node->type)) {
-    $grants = array();
-    foreach (array('view', 'update', 'delete') as $op) {
-      foreach (content_access_per_node_setting($op, $node) as $rid) {
-        $grants[$rid]['grant_'. $op] = 1;
-      }
-    }
-    foreach ($grants as $rid => $grant) {
-      $grants[$rid] = content_access_proccess_grant($grant, $rid, $node);
-    }
-  }
-  else {
-    // Apply the content type defaults.
-    $grants = content_access_get_default_grant($node);
-  }
-
+  
+  if (!content_access_get_settings('per_node', $node->type) && !module_exists('og')) {
+    // Apply the content type defaults.
+    $grants =  content_access_get_default_grant($node);
+  }
+  else {
+    // Apply per node settings if necessary.
+    $grants = array();
+    foreach (array('view', 'update', 'delete') as $op) {
+      foreach (content_access_per_node_setting($op, $node) as $rid) {
+        $grants_raw[$rid]['grant_'. $op] = 1;
+      }
+    }
+    // Remove OG in case it was uninstalled.
+    // unset($grants_raw['organic group admin']);   
+    foreach ($grants_raw as $rid => $grant_raw) {
+      $grant = content_access_proccess_grant($grant_raw, $rid, $node);
+      if ($grant) {
+        $grants = $grants + $grant;  
+      }
+    }
+  }
   if (empty($grants)) {
     // This means we grant no access.
     $grants[] = array('grant_view' => 0, 'realm' => 'content_access_rid', 'gid' => 0);
@@ -445,10 +475,14 @@ function content_access_get_permission_a
 /*
  * Returns all possible roles with an added item "author."
  */
-function content_access_get_roles_and_author() {
+function content_access_get_roles_and_arguments() {
   static $roles;
   if (!isset($roles)) {
-    $roles = array('author' => t('author')) + user_roles();
+    $og = array();
+    if (module_exists('og')) {
+      $og = array('organic group admin' => t('organic group admin'));
+    }
+    $roles = array('author' => t('author')) + user_roles() + $og;
   }
   return $roles;
 }
@@ -461,15 +495,19 @@ function content_access_get_default_gran
 
   if (!isset($defaults[$node->type])) {
     $grants = array();  //apply the defaults
-    $roles = content_access_get_roles_and_author();
+    $roles = content_access_get_roles_and_arguments();
 
     foreach (array('view', 'update', 'delete') as $op) {
       foreach (content_access_get_settings($op, $node->type) as $rid) {
-        $grants[$rid]['grant_'. $op] = 1;
+        $grants_raw[$rid]['grant_'. $op] = 1;
       }
-    }
-    foreach ($grants as $rid => $grant) {
-      $grants[$rid] = content_access_proccess_grant($grant, $rid, $node);
+    }
+    // For default setings we diregard OG grants, so remove it.
+    unset($grants_raw['organic group admin']);
+    
+    foreach ($grants_raw as $rid => $grant_raw) {
+      $grant = content_access_proccess_grant($grant_raw, $rid, $node);
+      $grants = $grants + $grant;
     }
     $defaults[$node->type] = $grants;
   }
@@ -485,10 +523,29 @@ function content_access_get_default_gran
  * Process a grant, which means add priority, realm and other properties.
  */
 function content_access_proccess_grant($grant, $rid, $node) {
-  $grant['realm'] = ($rid == 'author') ? 'content_access_author' : 'content_access_rid';
-  $grant['gid'] = ($rid == 'author') ? $node->uid : $rid;
-  $grant['priority'] = content_access_get_settings('priority', $node->type);
-  return $grant;
+  switch ($rid) {
+    case 'author':
+      $realm = 'content_access_author';
+      $gids = array($node->uid);
+      break;
+    case 'organic group admin':
+      $realm = 'content_access_group_admin';
+      // If node doesn't belong to a group then give it gid of 0, just so it will appear in the node access.
+      $node->og_groups? $gids = $node->og_groups : $gids = array('0'); 
+      break;
+    default:
+      $realm = 'content_access_rid';
+      $gids = array($rid);
+      break;  
+  }
+  // OG integartion might return an array of groups the node belongs to.
+  foreach ($gids as $gid) {
+    $grants[$gid] = $grant; 
+    $grants[$gid]['realm'] = $realm;
+    $grants[$gid]['gid'] = $gid;
+    $grants[$gid]['priority'] = content_access_get_settings('priority', $node->type);
+  }
+  return $grants;  
 }
 
 
