[CalendarServer-changes] [13189] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Mon Apr 7 20:04:33 PDT 2014
Revision: 13189
http://trac.calendarserver.org//changeset/13189
Author: sagen at apple.com
Date: 2014-04-07 20:04:33 -0700 (Mon, 07 Apr 2014)
Log Message:
-----------
Adds print-group-info to csmp to print cached group information; fixes recordWithCalendarUserAddress( ) to honor the hasCalendar field
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/principals.py
CalendarServer/trunk/txdav/common/datastore/sql.py
CalendarServer/trunk/txdav/who/delegates.py
CalendarServer/trunk/txdav/who/directory.py
CalendarServer/trunk/txdav/who/groups.py
CalendarServer/trunk/txdav/who/test/test_delegates.py
CalendarServer/trunk/txdav/who/test/test_directory.py
CalendarServer/trunk/txdav/who/test/test_groups.py
Modified: CalendarServer/trunk/calendarserver/tools/principals.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/principals.py 2014-04-08 02:05:39 UTC (rev 13188)
+++ CalendarServer/trunk/calendarserver/tools/principals.py 2014-04-08 03:04:33 UTC (rev 13189)
@@ -130,6 +130,7 @@
"remove",
"search=",
"list-principal-types",
+ "print-group-info",
"list-principals=",
"list-read-proxies",
"list-write-proxies",
@@ -162,6 +163,7 @@
listPrincipalTypes = False
listPrincipals = None
searchPrincipals = None
+ printGroupInfo = False
principalActions = []
verbose = False
@@ -188,6 +190,9 @@
elif opt in ("", "--list-principal-types"):
listPrincipalTypes = True
+ elif opt in ("", "--print-group-info"):
+ printGroupInfo = True
+
elif opt in ("", "--list-principals"):
listPrincipals = arg
@@ -269,6 +274,10 @@
function = runListPrincipalTypes
params = ()
+ elif printGroupInfo:
+ function = printGroupCacherInfo
+ params = ()
+
elif addType:
try:
@@ -763,6 +772,44 @@
)
+ at inlineCallbacks
+def printGroupCacherInfo(service, store):
+ """
+ Print all groups that have been delegated to, their cached members, and
+ who delegated to those groups.
+ """
+ directory = store.directoryService()
+ txn = store.newTransaction()
+ groupUIDs = yield txn.allGroupDelegates()
+ for groupUID in groupUIDs:
+ groupID, name, membershipHash, modified = yield txn.groupByUID(
+ groupUID
+ )
+ print("Group: \"{name} ({uid})".format(name=name, uid=groupUID))
+
+ for txt, readWrite in (("read-only", False), ("read-write", True)):
+ delegatorUIDs = yield txn.delegatorsToGroup(groupID, readWrite)
+ for delegatorUID in delegatorUIDs:
+ delegator = yield directory.recordWithUID(delegatorUID)
+ print(
+ "...has {rw} access to {rec}".format(
+ rw=txt, rec=prettyRecord(delegator)
+ )
+ )
+
+ print("Group members:")
+ memberUIDs = yield txn.membersOfGroup(groupID)
+ for memberUID in memberUIDs:
+ record = yield directory.recordWithUID(memberUID)
+ print(prettyRecord(record))
+
+ print("Last cached: {} GMT".format(modified))
+ print()
+
+ yield txn.commit()
+
+
+
def abort(msg, status=1):
sys.stdout.write("%s\n" % (msg,))
try:
Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py 2014-04-08 02:05:39 UTC (rev 13188)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py 2014-04-08 03:04:33 UTC (rev 13189)
@@ -957,7 +957,7 @@
def _groupByUID(cls):
gr = schema.GROUPS
return Select(
- [gr.GROUP_ID, gr.NAME, gr.MEMBERSHIP_HASH],
+ [gr.GROUP_ID, gr.NAME, gr.MEMBERSHIP_HASH, gr.MODIFIED],
From=gr,
Where=(gr.GROUP_GUID == Parameter("groupUID"))
)
@@ -1020,7 +1020,7 @@
@type groupUID: C{unicode}
@return: Deferred firing with tuple of group ID C{str}, group name
- C{unicode}, and membership hash C{str}
+ C{unicode}, membership hash C{str}, and modified timestamp
"""
results = (
yield self._groupByUID.on(
@@ -1032,6 +1032,7 @@
results[0][0], # group id
results[0][1].decode("utf-8"), # name
results[0][2], # membership hash
+ results[0][3], # modified timestamp
))
else:
savepoint = SavepointAction("groupByUID")
@@ -1050,6 +1051,7 @@
results[0][0], # group id
results[0][1].decode("utf-8"), # name
results[0][2], # membership hash
+ results[0][3], # modified timestamp
))
else:
raise
@@ -1065,6 +1067,7 @@
results[0][0], # group id
results[0][1].decode("utf-8"), # name
results[0][2], # membership hash
+ results[0][3], # modified timestamp
))
else:
raise
@@ -1173,15 +1176,15 @@
@inlineCallbacks
def membersOfGroup(self, groupID):
"""
- Returns the cached set of GUIDs for members of the given groupID.
+ Returns the cached set of UIDs for members of the given groupID.
Sub-groups are not returned in the results but their members are,
because the group membership has already been expanded/flattened
before storing in the db.
@param groupID: the group ID
@type groupID: C{int}
- @return: the set of member GUIDs
- @rtype: a Deferred which fires with a set() of C{str} GUIDs
+ @return: the set of member UIDs
+ @rtype: a Deferred which fires with a set() of C{str} UIDs
"""
members = set()
results = (yield self._selectGroupMembersQuery.on(self, groupID=groupID))
@@ -1306,6 +1309,20 @@
@classproperty
+ def _selectDelegatorsToGroupQuery(cls):
+ dg = schema.DELEGATE_GROUPS
+ return Select(
+ [dg.DELEGATOR],
+ From=dg,
+ Where=(
+ dg.GROUP_ID == Parameter("delegateGroup")
+ ).And(
+ dg.READ_WRITE == Parameter("readWrite")
+ )
+ )
+
+
+ @classproperty
def _selectDelegateGroupsQuery(cls):
ds = schema.DELEGATE_GROUPS
gr = schema.GROUPS
@@ -1621,7 +1638,7 @@
@param readWrite: the access-type to check for; read and write
access if True, otherwise read-only access
@type readWrite: C{boolean}
- @returns: the GUIDs of the delegators (for the specified access
+ @returns: the UIDs of the delegators (for the specified access
type)
@rtype: a Deferred resulting in a set
"""
@@ -1654,6 +1671,35 @@
@inlineCallbacks
+ def delegatorsToGroup(self, delegateGroupID, readWrite):
+ """
+ Return the UIDs of those who have delegated to the given group with the
+ given access level.
+
+ @param delegateGroupID: the group ID of the delegate group
+ @type delegateGroupID: C{int}
+ @param readWrite: the access-type to check for; read and write
+ access if True, otherwise read-only access
+ @type readWrite: C{boolean}
+ @returns: the UIDs of the delegators (for the specified access
+ type)
+ @rtype: a Deferred resulting in a set
+
+ """
+ delegators = set()
+ results = (
+ yield self._selectDelegatorsToGroupQuery.on(
+ self,
+ delegateGroup=delegateGroupID,
+ readWrite=1 if readWrite else 0
+ )
+ )
+ for row in results:
+ delegators.add(row[0].decode("utf-8"))
+ returnValue(delegators)
+
+
+ @inlineCallbacks
def allGroupDelegates(self):
"""
Return the UIDs of all groups which have been delegated to. Useful
Modified: CalendarServer/trunk/txdav/who/delegates.py
===================================================================
--- CalendarServer/trunk/txdav/who/delegates.py 2014-04-08 02:05:39 UTC (rev 13188)
+++ CalendarServer/trunk/txdav/who/delegates.py 2014-04-08 03:04:33 UTC (rev 13189)
@@ -230,7 +230,9 @@
"""
if delegate.recordType == BaseRecordType.group:
# find the groupID
- groupID, name, membershipHash = (yield txn.groupByUID(delegate.uid))
+ groupID, name, membershipHash, modified = yield txn.groupByUID(
+ delegate.uid
+ )
yield txn.addDelegateGroup(delegator.uid, groupID, readWrite)
else:
yield txn.addDelegate(delegator.uid, delegate.uid, readWrite)
@@ -251,7 +253,9 @@
"""
if delegate.recordType == BaseRecordType.group:
# find the groupID
- groupID, name, membershipHash = (yield txn.groupByUID(delegate.uid))
+ groupID, name, membershipHash, modified = yield txn.groupByUID(
+ delegate.uid
+ )
yield txn.removeDelegateGroup(delegator.uid, groupID, readWrite)
else:
yield txn.removeDelegate(delegator.uid, delegate.uid, readWrite)
Modified: CalendarServer/trunk/txdav/who/directory.py
===================================================================
--- CalendarServer/trunk/txdav/who/directory.py 2014-04-08 02:05:39 UTC (rev 13188)
+++ CalendarServer/trunk/txdav/who/directory.py 2014-04-08 03:04:33 UTC (rev 13189)
@@ -76,7 +76,7 @@
elif address.startswith("mailto:"):
records = yield self.recordsWithEmailAddress(address[7:])
if records:
- returnValue(records[0])
+ record = records[0]
else:
returnValue(None)
elif address.startswith("/principals/"):
Modified: CalendarServer/trunk/txdav/who/groups.py
===================================================================
--- CalendarServer/trunk/txdav/who/groups.py 2014-04-08 02:05:39 UTC (rev 13188)
+++ CalendarServer/trunk/txdav/who/groups.py 2014-04-08 03:04:33 UTC (rev 13189)
@@ -269,11 +269,11 @@
) in changed:
readDelegateGroupID = writeDelegateGroupID = None
if readDelegateUID:
- readDelegateGroupID, _ignore_name, hash = (
+ readDelegateGroupID, _ignore_name, hash, modified = (
yield txn.groupByUID(readDelegateUID)
)
if writeDelegateUID:
- writeDelegateGroupID, _ignore_name, hash = (
+ writeDelegateGroupID, _ignore_name, hash, modified = (
yield txn.groupByUID(writeDelegateUID)
)
yield txn.assignExternalDelegates(
@@ -307,7 +307,7 @@
for member in members:
membershipHashContent.update(str(member.uid))
membershipHash = membershipHashContent.hexdigest()
- groupID, _ignore_cachedName, cachedMembershipHash = (
+ groupID, _ignore_cachedName, cachedMembershipHash, modified = (
yield txn.groupByUID(groupUID)
)
Modified: CalendarServer/trunk/txdav/who/test/test_delegates.py
===================================================================
--- CalendarServer/trunk/txdav/who/test/test_delegates.py 2014-04-08 02:05:39 UTC (rev 13188)
+++ CalendarServer/trunk/txdav/who/test/test_delegates.py 2014-04-08 03:04:33 UTC (rev 13189)
@@ -207,7 +207,7 @@
yield self.directory.recordWithShortName(RecordType.user, name)
)
newSet.add(record.uid)
- groupID, name, membershipHash = (yield txn.groupByUID(group1.uid))
+ groupID, name, membershipHash, modified = (yield txn.groupByUID(group1.uid))
numAdded, numRemoved = (
yield self.groupCacher.synchronizeMembers(txn, groupID, newSet)
)
Modified: CalendarServer/trunk/txdav/who/test/test_directory.py
===================================================================
--- CalendarServer/trunk/txdav/who/test/test_directory.py 2014-04-08 02:05:39 UTC (rev 13188)
+++ CalendarServer/trunk/txdav/who/test/test_directory.py 2014-04-08 03:04:33 UTC (rev 13189)
@@ -123,3 +123,22 @@
)
records = yield self.directory.recordsFromExpression(expression)
self.assertEquals(len(records), 1)
+
+
+ @inlineCallbacks
+ def test_recordWithCalendarUserAddress(self):
+ """
+ Make sure hasCalendars is honored
+ """
+
+ # hasCalendars
+ record = yield self.directory.recordWithCalendarUserAddress(
+ u"mailto:wsanchez at example.com"
+ )
+ self.assertNotEquals(record, None)
+
+ # no hasCalendars
+ record = yield self.directory.recordWithCalendarUserAddress(
+ u"mailto:nocalendar at example.com"
+ )
+ self.assertEquals(record, None)
Modified: CalendarServer/trunk/txdav/who/test/test_groups.py
===================================================================
--- CalendarServer/trunk/txdav/who/test/test_groups.py 2014-04-08 02:05:39 UTC (rev 13188)
+++ CalendarServer/trunk/txdav/who/test/test_groups.py 2014-04-08 03:04:33 UTC (rev 13189)
@@ -46,7 +46,7 @@
record = yield self.directory.recordWithUID(u"__top_group_1__")
yield self.groupCacher.refreshGroup(txn, record.uid)
- groupID, name, membershipHash = (yield txn.groupByUID(record.uid))
+ groupID, name, membershipHash, modified = (yield txn.groupByUID(record.uid))
self.assertEquals(membershipHash, "553eb54e3bbb26582198ee04541dbee4")
@@ -88,7 +88,7 @@
# Refresh the group so it's assigned a group_id
uid = u"__top_group_1__"
yield self.groupCacher.refreshGroup(txn, uid)
- groupID, name, membershipHash = (yield txn.groupByUID(uid))
+ groupID, name, membershipHash, modified = (yield txn.groupByUID(uid))
# Remove two members, and add one member
newSet = set()
@@ -135,7 +135,7 @@
uid = u"__top_group_1__"
hash = "553eb54e3bbb26582198ee04541dbee4"
yield self.groupCacher.refreshGroup(txn, uid)
- groupID, name, membershipHash = (yield txn.groupByUID(uid))
+ groupID, name, membershipHash, modified = yield txn.groupByUID(uid)
results = (yield txn.groupByID(groupID))
self.assertEquals((uid, u"Top Group 1", hash), results)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140407/631aeb26/attachment-0001.html>
More information about the calendarserver-changes
mailing list