Index: domain.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain.admin.inc,v
retrieving revision 1.41
diff -u -p -r1.41 domain.admin.inc
--- domain.admin.inc   1 Nov 2009 18:20:19 -0000   1.41
+++ domain.admin.inc   16 Dec 2009 18:51:59 -0000
@@ -17,8 +17,16 @@
  */
 function domain_view() {
   global $_domain;
-  $output = t('<p>The following domains have been created for your site.  The currently active domain <b>is shown in boldface</b>.  You
+  // Output appropriate message, depending on permission
+  if (user_access('administer own domains') && !user_access('administer domains')) {
+    $output = t('<p>You have administrative access to the following domains.  The currently active domain <b>is shown in boldface</b>.  You
+                    may click on a domain to change the currently active domain.');
+  }
+  else {
+    $output = t('<p>The following domains have been created for your site.  The currently active domain <b>is shown in boldface</b>.  You
                     may click on a domain to change the currently active domain.  Your default domain has an ID of zero (0).</p>');
+  }
+  
   $header = array(
     array('data' => t('Id'), 'field' => 'd.domain_id'),
     array('data' => t('Domain'), 'field' => 'd.subdomain'),
@@ -36,14 +44,28 @@ function domain_view() {
   $actions = array();
   // Get any select sql from other modules.
   $select = module_invoke_all('domainview', 'select');
-  $select_sql = '';
+  // Add {domain_editor}, if needed
+  if (user_access('administer own domains') && !user_access('administer domains')) {
+    $select_sql = ', de.*';
+   }
+  else {
+    $select_sql = '';
+   }
+   
   if (!empty($select)) {
-    $select_sql = ', '. implode(', ', $select);
+    $select_sql = $select_sql.', '. implode(', ', $select);
     $select_sql = rtrim($select_sql, ',');
   }
 
   // Get any tablesort sql from other modules.
   $join = module_invoke_all('domainview', 'join');
+  
+  // Filter by own domains, if needed
+  if (user_access('administer own domains') && !user_access('administer domains')) {
+    global $user;
+    $join[] = ' LEFT JOIN {domain_editor} de ON d.domain_id = de.domain_id WHERE uid = '. $user->uid .' AND d.domain_id != 0';
+  }
+  
   $join_sql = '';
   if (!empty($join)) {
     $join_sql = ' '. implode(' ', $join);
@@ -74,7 +96,10 @@ function domain_view() {
     else {
       $actions = array();
       $actions[] = l(t('edit'), 'admin/build/domain/edit/'. $domain['domain_id']);
-      $actions[] = l(t('delete'), 'admin/build/domain/delete/'. $domain['domain_id']);
+      // Only show 'delete' link for 'administer domains' permission
+      if (user_access('administer domains')) {
+        $actions[] = l(t('delete'), 'admin/build/domain/delete/'. $domain['domain_id']);
+      }
     }
       // Add advanced settings from other modules.
       $items = array();
Index: domain.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain.module,v
retrieving revision 1.137
diff -u -p -r1.137 domain.module
--- domain.module   8 Dec 2009 16:59:03 -0000   1.137
+++ domain.module   16 Dec 2009 18:50:30 -0000
@@ -119,14 +119,14 @@ function domain_menu() {
   $admin = user_access('administer domains');
   $items['admin/build/domain'] = array(
     'title' => 'Domains',
-    'access arguments' => array('administer domains'),
+    'access callback' => 'domain_admin_access',
     'page callback' => 'domain_view',
     'file' => 'domain.admin.inc',
     'description' => 'Settings for the Domain Access module.',
   );
   $items['admin/build/domain/view'] = array(
     'title' => 'Domain list',
-    'access arguments' => array('administer domains'),
+    'access callback' => 'domain_admin_access',
     'type' => MENU_DEFAULT_LOCAL_TASK,
     'page callback' => 'domain_view',
     'file' => 'domain.admin.inc',
@@ -193,7 +193,8 @@ function domain_menu() {
   );
   $items['admin/build/domain/edit/%domain'] = array(
     'title' => 'Edit domain record',
-    'access arguments' => array('administer domains'),
+    'access callback' => 'domain_admin_access',
+    'access arguments' => array(4),
     'type' => MENU_CALLBACK,
     'page callback' => 'drupal_get_form',
     'page arguments' => array('domain_form', 4),
@@ -217,6 +218,7 @@ function domain_perm() {
   $perms = array(
     'access inactive domains',
     'administer domains',
+    'administer own domains',
     'assign domain editors',
     'delete domain nodes',
     'edit domain nodes',
@@ -2357,3 +2359,55 @@ function domain_db_rewrite_sql($query, $
   );
   return $return;
 }
+/**
+ * Access callback to allow multiple permissions to access domain_view() and domain sub-module functions
+ *
+ * @param $domain
+ *   An array containing the record from the {domain} table, passed from the menu item path.
+ 
+ * @return
+ *   TRUE if user has:
+ *     -'administer domains' permission; OR
+ *     -if user has 'administer own domains' permissions, AND either:
+ *       -no $domain was passed from the menu (i.e., /admin/build/domain), OR
+ *       -the user is an editor for $domain.
+ */
+function domain_admin_access($domain = NULL) {
+  return user_access('administer domains') || 
+  (user_access('administer own domains') &&
+  (!isset($domain) || domain_is_own_domain($domain)));
+}
+
+/**
+ * Function to generate a list of the domains where the current user is an editor
+ * 
+ * @return
+ *   Array of domains where the current user is an assigned editor
+ */
+function domain_own_domainlist() {
+  global $user;
+  $sql = 'SELECT d.*, de.* FROM {domain} d LEFT JOIN {domain_editor} de ON d.domain_id = de.domain_id WHERE uid = '. $user->uid .' AND d.domain_id != 0';
+  $result = db_query($sql);
+  while ($data = db_fetch_array($result)) {
+    $own_domains[] = $data;
+  }
+  return $own_domains;
+}
+
+/**
+ * Function to check if a domain is among the domains of which the current user is an editor
+ * 
+ * @param $domain
+ *   An array containing the record from the {domain} table, passed from the menu item path.
+ *
+ * @return
+ *   TRUE if the current user is an assigned editor of the domain passed by $domain.
+ */
+function domain_is_own_domain($domain = array()) {
+  $own_domains = domain_own_domainlist();
+  foreach ($own_domains as $own_domain) {
+    if ($own_domain[domain_id] == $domain[domain_id]) {
+     return TRUE;
+   };
+  }
+}

