Index: gallery_roles.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gallery/gallery_roles.inc,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 gallery_roles.inc
--- gallery_roles.inc	17 Jul 2006 11:09:37 -0000	1.1.2.1
+++ gallery_roles.inc	30 Jan 2007 18:14:23 -0000
@@ -12,18 +12,6 @@
 function gallery_sync_groups_for_user($user) {
   // Take this opportunity to sync the Drupal roles and Gallery groups
   gallery_sync_groups();
-  // Find the Ids for the 2 special Drupal roles (from user.module code)
-  $authenticated_role =  db_result(db_query("SELECT rid FROM {role} WHERE name = 'authenticated user'"));
-  $anonymous_role =  db_result(db_query("SELECT rid FROM {role} WHERE name = 'anonymous user'"));
-  
-  // Find the Ids for the special G2 groups 
-  list ($ret, $g2_gid_everybodyGroup) = GalleryCoreApi::getPluginParameter('module', 'core',
-    'id.everybodyGroup');
-  if ($ret) {
-    $msg = t('Error retrieving Gallery group Id for \'Everybody\' group');
-    gallery_error($msg, $ret);
-    return;
-  }
   
   // Get the Gallery groups for this user
   // First get the G2 Id from the Drupal uid
@@ -35,7 +23,7 @@
     return;
   }
   // Then get the groups for this user currently set in G2
-  list ($ret, $g2_cur_groups) = GalleryCoreApi::fetchGroupsForUser($g2_user->getId());
+  list ($ret, $g2_user_groups) = GalleryCoreApi::fetchGroupsForUser($g2_user->getId());
   if ($ret) {
     $msg = t('Error getting Gallery group info for user');
     $msg .= ' ' . t('Drupal User Id: ') . $user->uid;        
@@ -43,6 +31,8 @@
     return;
   }
   // Now convert the new Drupal role Ids into Gallery Group Ids(for comparison)
+  $user->roles[DRUPAL_ANONYMOUS_RID] = DRUPAL_ANONYMOUS_RID;
+  $user->roles[DRUPAL_AUTHENTICATED_RID] = DRUPAL_AUTHENTICATED_RID;
   foreach ($user->roles as $rid=>$role_name) { 
     list ($ret, $g2_group) = GalleryCoreApi::loadEntityByExternalId($rid, 'GalleryGroup');
     if ($ret) {
@@ -51,12 +41,12 @@
       gallery_error($msg, $ret);
       return;
     }
-    $g2_rid[$rid] = $g2_group->getId();
+    $g2_rid_map[$rid] = $g2_group->getId();
   }
   // Find if the user needs to be deleted from any G2 groups (only mapped groups)
   $g2_mapped_groups = gallery_get_mapped_groups();
-  foreach ($g2_cur_groups as $gid=>$gname) {
-    if (!in_array($gid, $g2_rid) && ($gid != $g2_gid_everybodyGroup) && in_array($gid, $g2_mapped_groups)) {
+  foreach ($g2_user_groups as $gid=>$gname) {
+    if (!in_array($gid, $g2_rid_map) && in_array($gid, $g2_mapped_groups)) {
       $delete_list[] = $gid;
       $ret = GalleryCoreApi::removeUserFromGroup($g2_user->getId(), $gid);
       if ($ret) {
@@ -68,8 +58,8 @@
     }
   }
   // Find if the user needs to be added to any G2 groups
-  foreach ($g2_rid as $rid=>$gid) {
-    if (!isset($g2_cur_groups[$gid])) {
+  foreach ($g2_rid_map as $rid=>$gid) {
+    if (!isset($g2_user_groups[$gid])) {
       $add_list[] = $gid;
       $ret = GalleryCoreApi::addUserToGroup($g2_user->getId(), $gid);
       if ($ret) {
@@ -79,7 +69,7 @@
         return;
       }
     }
-  }  
+  }
 }
 
 /**
@@ -90,9 +80,6 @@
 function gallery_sync_groups() {
   // Check if the Drupal role <-> G2 group mapping exists
   $roles = user_roles();
-  // Find the Ids for the 2 special Drupal groups (from user.module code)
-  $authenticated_role =  db_result(db_query("SELECT rid FROM {role} WHERE name = 'authenticated user'"));
-  $anonymous_role =  db_result(db_query("SELECT rid FROM {role} WHERE name = 'anonymous user'"));
   // Go through each role and add or delete the gallery group if needed
   foreach ($roles as $rid => $role_name) {
     // Add Drupal<->G2 mapping if needed
@@ -101,7 +88,7 @@
     // Need to add the mapping
       switch ($rid) {
         // Add mapping for Anonymous and get the G2 group Id
-        case $anonymous_role:
+        case DRUPAL_ANONYMOUS_RID:
           list ($ret, $g2_gid) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.everybodyGroup');
           if ($ret) {
             $msg = t('Error retrieving Gallery group Id for \'Everybody\' group');
@@ -117,7 +104,7 @@
           }
           break;
         // Add mapping for authenticated users role and get the G2 group Id
-        case $authenticated_role:
+        case DRUPAL_AUTHENTICATED_RID:
           list ($ret, $g2_gid) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.allUserGroup');
           if ($ret) {
             $msg = t('Error retrieving Gallery group Id for \'Registered Users\' group');
@@ -222,4 +209,4 @@
   }
   return $g2_mapped_groups;
 }
-?>
\ No newline at end of file
+?>
Index: gallery_user.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gallery/gallery_user.inc,v
retrieving revision 1.2.2.4
diff -u -r1.2.2.4 gallery_user.inc
--- gallery_user.inc	27 Nov 2006 11:55:21 -0000	1.2.2.4
+++ gallery_user.inc	30 Jan 2007 18:18:33 -0000
@@ -58,7 +58,7 @@
   $user->status = ($edit['status']) ? $edit['status'] : $user->status;
   $user->mail = ($edit['mail']) ? $edit['mail'] : $user->mail;
   // Note: $user->roles is organized as [$rid]=>[$role_name], but edit['roles'] is [$rid]=>[$position]
-  $user->roles = ($edit['roles']) ? $edit['roles'] : $user->roles;
+  $user->roles = isset($edit['roles']) ? $edit['roles'] : $user->roles;
   // Use full name from profile if it exists 
   $fullnamefield = variable_get('gallery_profile_full_name_field', 'profile_full_name');
   $usefullname = variable_get('gallery_use_full_name', 0) && module_exist('profile');
