<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[11959] CalendarServer/branches/users/sagen/groupcacher</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/11959">11959</a></dd>
<dt>Author</dt> <dd>gaya@apple.com</dd>
<dt>Date</dt> <dd>2013-11-15 21:15:04 -0800 (Fri, 15 Nov 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix UUID issues in group cacher and delegates</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserssagengroupcachertwextwhotesttest_delegatespy">CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_delegates.py</a></li>
<li><a href="#CalendarServerbranchesuserssagengroupcachertwextwhotesttest_groupspy">CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_groups.py</a></li>
<li><a href="#CalendarServerbranchesuserssagengroupcachertxdavcommondatastoresqlpy">CalendarServer/branches/users/sagen/groupcacher/txdav/common/datastore/sql.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserssagengroupcachertwextwhotesttest_delegatespy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_delegates.py (11958 => 11959)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_delegates.py        2013-11-15 23:31:07 UTC (rev 11958)
+++ CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_delegates.py        2013-11-16 05:15:04 UTC (rev 11959)
</span><span class="lines">@@ -22,10 +22,11 @@
</span><span class="cx">     addDelegate, removeDelegate, delegatesOf, delegatedTo, allGroupDelegates
</span><span class="cx"> )
</span><span class="cx"> from twext.who.groups import GroupCacher
</span><ins>+from twext.who.idirectory import RecordType
</ins><span class="cx"> from twext.who.test.test_xml import xmlService
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks
</span><span class="cx"> from twistedcaldav.test.util import StoreTestCase
</span><del>-from twext.who.idirectory import RecordType
</del><ins>+from uuid import UUID
</ins><span class="cx"> 
</span><span class="cx"> class DelegationTest(StoreTestCase):
</span><span class="cx"> 
</span><span class="lines">@@ -112,11 +113,11 @@
</span><span class="cx">         groups = (yield allGroupDelegates(txn))
</span><span class="cx">         self.assertEquals(
</span><span class="cx">             set([
</span><del>-                &quot;49b350c69611477b94d95516b13856ab&quot;,
-                &quot;86144f73345a409782f1b782672087c7&quot;
</del><ins>+                UUID(&quot;49b350c69611477b94d95516b13856ab&quot;),
+                UUID(&quot;86144f73345a409782f1b782672087c7&quot;)
</ins><span class="cx">                 ]), set(groups))
</span><span class="cx"> 
</span><del>-        # Delegate to a user who is already indirectly delegated-to 
</del><ins>+        # Delegate to a user who is already indirectly delegated-to
</ins><span class="cx">         yield addDelegate(txn, delegator, delegate1, True)
</span><span class="cx">         delegates = (yield delegatesOf(txn, delegator, True))
</span><span class="cx">         self.assertEquals(set([&quot;sagen&quot;, &quot;cdaboo&quot;, &quot;glyph&quot;]),
</span><span class="lines">@@ -128,8 +129,8 @@
</span><span class="cx">             record = (yield self.xmlService.recordWithShortName(RecordType.user,
</span><span class="cx">                 name))
</span><span class="cx">             newSet.add(record.guid)
</span><del>-        groupID, name, membershipHash = (yield txn.groupByGUID(group1.guid))
-        numAdded, numRemoved = (yield self.groupCacher.synchronizeMembers(txn,
</del><ins>+        groupID, name, membershipHash = (yield txn.groupByGUID(group1.guid)) #@UnusedVariable
+        numAdded, numRemoved = (yield self.groupCacher.synchronizeMembers(txn, #@UnusedVariable
</ins><span class="cx">             groupID, newSet))
</span><span class="cx">         delegates = (yield delegatesOf(txn, delegator, True))
</span><span class="cx">         self.assertEquals(set([&quot;sagen&quot;, &quot;cdaboo&quot;, &quot;glyph&quot;, &quot;dre&quot;]),
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagengroupcachertwextwhotesttest_groupspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_groups.py (11958 => 11959)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_groups.py        2013-11-15 23:31:07 UTC (rev 11958)
+++ CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_groups.py        2013-11-16 05:15:04 UTC (rev 11959)
</span><span class="lines">@@ -19,11 +19,12 @@
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx"> from twext.who.groups import GroupCacher, _expandedMembers
</span><ins>+from twext.who.idirectory import RecordType
</ins><span class="cx"> from twext.who.test.test_xml import xmlService
</span><del>-from twext.who.idirectory import RecordType
</del><span class="cx"> from twisted.internet.defer import inlineCallbacks
</span><span class="cx"> from twistedcaldav.test.util import StoreTestCase
</span><span class="cx"> from txdav.common.icommondatastore import NotFoundError
</span><ins>+from uuid import UUID
</ins><span class="cx"> 
</span><span class="cx"> class GroupCacherTest(StoreTestCase):
</span><span class="cx"> 
</span><span class="lines">@@ -73,19 +74,19 @@
</span><span class="cx">         yield self.groupCacher.refreshGroup(txn, record.guid)
</span><span class="cx"> 
</span><span class="cx">         groupID, name, membershipHash = (yield txn.groupByGUID(record.guid))
</span><del>-        self.assertEquals(membershipHash, &quot;e90052eb63d47f32d5b03df0073f7854&quot;)
</del><ins>+        self.assertEquals(membershipHash, &quot;4b0e162f2937f0f3daa6d10e5a6a6c33&quot;)
</ins><span class="cx"> 
</span><span class="cx">         groupGUID, name, membershipHash = (yield txn.groupByID(groupID))
</span><span class="cx">         self.assertEquals(groupGUID, record.guid)
</span><span class="cx">         self.assertEquals(name, &quot;Top Group 1&quot;)
</span><del>-        self.assertEquals(membershipHash, &quot;e90052eb63d47f32d5b03df0073f7854&quot;)
</del><ins>+        self.assertEquals(membershipHash, &quot;4b0e162f2937f0f3daa6d10e5a6a6c33&quot;)
</ins><span class="cx"> 
</span><span class="cx">         members = (yield txn.membersOfGroup(groupID))
</span><span class="cx">         self.assertEquals(
</span><del>-            set([&quot;9064df911dbc4e079c2b6839b0953876&quot;,
-                 &quot;4ad155cbae9b475f986ce08a7537893e&quot;,
-                 &quot;3bdcb95484d54f6d8035eac19a6d6e1f&quot;,
-                 &quot;7d45cb10479e456bb54d528958c5734b&quot;]),
</del><ins>+            set([UUID(&quot;9064df911dbc4e079c2b6839b0953876&quot;),
+                 UUID(&quot;4ad155cbae9b475f986ce08a7537893e&quot;),
+                 UUID(&quot;3bdcb95484d54f6d8035eac19a6d6e1f&quot;),
+                 UUID(&quot;7d45cb10479e456bb54d528958c5734b&quot;)]),
</ins><span class="cx">             members
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="lines">@@ -108,9 +109,9 @@
</span><span class="cx">         txn = store.newTransaction()
</span><span class="cx"> 
</span><span class="cx">         # Refresh the group so it's assigned a group_id
</span><del>-        guid = &quot;49b350c69611477b94d95516b13856ab&quot;
</del><ins>+        guid = UUID(&quot;49b350c69611477b94d95516b13856ab&quot;)
</ins><span class="cx">         yield self.groupCacher.refreshGroup(txn, guid)
</span><del>-        groupID, name, membershipHash = (yield txn.groupByGUID(guid))
</del><ins>+        groupID, name, membershipHash = (yield txn.groupByGUID(guid)) #@UnusedVariable
</ins><span class="cx"> 
</span><span class="cx">         # Remove two members, and add one member
</span><span class="cx">         newSet = set()
</span><span class="lines">@@ -146,10 +147,10 @@
</span><span class="cx">         # Non-existent groupID
</span><span class="cx">         self.failUnlessFailure(txn.groupByID(42), NotFoundError)
</span><span class="cx"> 
</span><del>-        guid = &quot;49b350c69611477b94d95516b13856ab&quot;
-        hash = &quot;e90052eb63d47f32d5b03df0073f7854&quot;
</del><ins>+        guid = UUID(&quot;49b350c69611477b94d95516b13856ab&quot;)
+        hash = &quot;4b0e162f2937f0f3daa6d10e5a6a6c33&quot;
</ins><span class="cx">         yield self.groupCacher.refreshGroup(txn, guid)
</span><del>-        groupID, name, membershipHash = (yield txn.groupByGUID(guid))
</del><ins>+        groupID, name, membershipHash = (yield txn.groupByGUID(guid)) #@UnusedVariable
</ins><span class="cx">         results = (yield txn.groupByID(groupID))
</span><span class="cx">         self.assertEquals([guid, &quot;Top Group 1&quot;, hash], results)
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagengroupcachertxdavcommondatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/groupcacher/txdav/common/datastore/sql.py (11958 => 11959)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/groupcacher/txdav/common/datastore/sql.py        2013-11-15 23:31:07 UTC (rev 11958)
+++ CalendarServer/branches/users/sagen/groupcacher/txdav/common/datastore/sql.py        2013-11-16 05:15:04 UTC (rev 11959)
</span><span class="lines">@@ -961,6 +961,8 @@
</span><span class="cx">     def groupByID(self, groupID):
</span><span class="cx">         try:
</span><span class="cx">             results = (yield self._groupByID.on(self, groupID=groupID))[0]
</span><ins>+            if results:
+                results = [UUID(&quot;urn:uuid:&quot; + results[0])] + results[1:]
</ins><span class="cx">             returnValue(results)
</span><span class="cx">         except IndexError:
</span><span class="cx">             raise NotFoundError
</span><span class="lines">@@ -980,6 +982,7 @@
</span><span class="cx">         return Insert({gm.GROUP_ID: Parameter(&quot;groupID&quot;),
</span><span class="cx">                        gm.MEMBER_GUID: Parameter(&quot;memberGUID&quot;)})
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx">     @classproperty
</span><span class="cx">     def _removeMemberFromGroupQuery(cls): #@NoSelf
</span><span class="cx">         gm = schema.GROUP_MEMBERSHIP
</span><span class="lines">@@ -1023,7 +1026,7 @@
</span><span class="cx">         results = (yield self._selectGroupMembersQuery.on(self,
</span><span class="cx">             groupID=groupID))
</span><span class="cx">         for row in results:
</span><del>-            members.add(row[0])
</del><ins>+            members.add(UUID(&quot;urn:uuid:&quot; + row[0]))
</ins><span class="cx">         returnValue(members)
</span><span class="cx"> 
</span><span class="cx">     # End of Group Members
</span><span class="lines">@@ -1189,7 +1192,7 @@
</span><span class="cx">         @type readWrite: C{boolean}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         return self._removeDelegateQuery.on(self, delegator=str(delegator),
</span><del>-            delegate=delegate, readWrite=1 if readWrite else 0)
</del><ins>+            delegate=str(delegate), readWrite=1 if readWrite else 0)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def removeDelegateGroup(self, delegator, delegateGroupID, readWrite):
</span><span class="lines">@@ -1232,13 +1235,13 @@
</span><span class="cx">         results = (yield self._selectDelegatesQuery.on(self,
</span><span class="cx">             delegator=str(delegator), readWrite=1 if readWrite else 0))
</span><span class="cx">         for row in results:
</span><del>-            delegates.add(row[0])
</del><ins>+            delegates.add(UUID(&quot;urn:uuid:&quot; + row[0]))
</ins><span class="cx"> 
</span><span class="cx">         # Finally get those who are in groups which have been delegated to
</span><span class="cx">         results = (yield self._selectIndirectDelegatesQuery.on(self,
</span><span class="cx">             delegator=str(delegator), readWrite=1 if readWrite else 0))
</span><span class="cx">         for row in results:
</span><del>-            delegates.add(row[0])
</del><ins>+            delegates.add(UUID(&quot;urn:uuid:&quot; + row[0]))
</ins><span class="cx"> 
</span><span class="cx">         returnValue(delegates)
</span><span class="cx"> 
</span><span class="lines">@@ -1262,16 +1265,16 @@
</span><span class="cx"> 
</span><span class="cx">         # First get the direct delegators
</span><span class="cx">         results = (yield self._selectDirectDelegatorsQuery.on(self,
</span><del>-            delegate=delegate, readWrite=1 if readWrite else 0))
</del><ins>+            delegate=str(delegate), readWrite=1 if readWrite else 0))
</ins><span class="cx">         for row in results:
</span><del>-            delegators.add(row[0])
</del><ins>+            delegators.add(UUID(&quot;urn:uuid:&quot; + row[0]))
</ins><span class="cx"> 
</span><span class="cx">         # Finally get those who have delegated to groups the delegate
</span><span class="cx">         # is a member of
</span><span class="cx">         results = (yield self._selectIndirectDelegatorsQuery.on(self,
</span><del>-            delegate=delegate, readWrite=1 if readWrite else 0))
</del><ins>+            delegate=str(delegate), readWrite=1 if readWrite else 0))
</ins><span class="cx">         for row in results:
</span><del>-            delegators.add(row[0])
</del><ins>+            delegators.add(UUID(&quot;urn:uuid:&quot; + row[0]))
</ins><span class="cx"> 
</span><span class="cx">         returnValue(delegators)
</span><span class="cx"> 
</span><span class="lines">@@ -1296,7 +1299,7 @@
</span><span class="cx">         ).on(self))
</span><span class="cx">         delegates = set()
</span><span class="cx">         for row in results:
</span><del>-            delegates.add(row[0])
</del><ins>+            delegates.add(UUID(&quot;urn:uuid:&quot; + row[0]))
</ins><span class="cx"> 
</span><span class="cx">         returnValue(delegates)
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>