Commit 57320b83 authored by Sriram Karra's avatar Sriram Karra

Do not indiscriminately apply GC group membership

When one google accont is synched to another account (directly
or through an intermediary db) we need to process the 'gids'
(i.e. group membership info) a little carefully, otherwise
we will attempt to allocate membership to groups that are actually
in another google account altogether.

parent d6d69bec
......@@ -176,6 +176,14 @@ class GCContact(Contact):
return ret
def get_curr_gmail_userid (self):
gid = self.get_folder().get_itemid()
return self.get_gid_gmail_userid(gid)
def get_gid_gmail_userid (self, group_uri):
m ='/groups/([^/]*)/', group_uri)
return if m else None
## Internal functions that are not inteded to be called from outside.
......@@ -537,6 +545,8 @@ class GCContact(Contact):
"""Append the group IDs that denote group membership to the specified
ContactEntry object."""
gmail_owner = self.get_curr_gmail_userid()
gid = self.get_folder().get_itemid()
gidm =
......@@ -547,9 +557,19 @@ class GCContact(Contact):
js = self.get_custom('gids')
js = js.replace('\\', '')
gids = demjson.decode(js)
retained_gids = []
for gid in gids:
gidm =
gid_owner = self.get_gid_gmail_userid(gid)
if gid_owner == gmail_owner:
gidm =
logging.debug(('Skipped mismatched membership in gid: %s; ' +
'Current Owner: %s'), gid, gmail_owner)
self.update_custom({'gids' : demjson.encode(retained_gids)})
def _add_emails_to_gce (self, gce):
"""Append the email addresses from the current Contact object to the
......@@ -781,7 +801,7 @@ class GCContact(Contact):
for key, val in self.get_custom().iteritems():
# We skip certain keys that have been processed already and
# populated into other elements of the contact entry.
if val and not key in ['gids']:
if val and not key in []:
ud =
ud.key = key
val = val.isoformat() if isinstance(val, datetime) else val
......@@ -741,9 +741,7 @@ class BatchState:
if op == 'insert' or op == 'update':
name = self.get_con(bid).name
except Exception, e:
name = self.get_con(bid).get_name()
name = self.get_con(bid).get_disp_name()
except Exception, e:
name = "WTH!"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment