Revision: 9333 http://trac.macosforge.org/projects/calendarserver/changeset/9333 Author: gaya@apple.com Date: 2012-06-05 16:42:39 -0700 (Tue, 05 Jun 2012) Log Message: ----------- add BIND_MODE to GROUP_BIND table Modified Paths: -------------- CalendarServer/branches/users/gaya/sharedabgroups/txdav/carddav/datastore/sql.py CalendarServer/branches/users/gaya/sharedabgroups/txdav/common/datastore/sql_legacy.py CalendarServer/branches/users/gaya/sharedabgroups/txdav/common/datastore/sql_schema/current.sql Modified: CalendarServer/branches/users/gaya/sharedabgroups/txdav/carddav/datastore/sql.py =================================================================== --- CalendarServer/branches/users/gaya/sharedabgroups/txdav/carddav/datastore/sql.py 2012-06-05 01:44:31 UTC (rev 9332) +++ CalendarServer/branches/users/gaya/sharedabgroups/txdav/carddav/datastore/sql.py 2012-06-05 23:42:39 UTC (rev 9333) @@ -72,7 +72,9 @@ from twext.enterprise.dal.syntax import Update from twext.python.clsprop import classproperty +from txdav.common.datastore.sql_tables import _BIND_MODE_READ + class AddressBookHome(CommonHome): implements(IAddressBookHome) @@ -285,26 +287,13 @@ if not owned: bind = schema.GROUP_BIND - groupIDRows = (yield Select([bind.GROUP_ID,], + groupIDRows = (yield Select([bind.GROUP_ID, bind.BIND_MODE], From=bind, Where=(bind.ADDRESSBOOK_BIND_ID == groupBindID)).on(home._txn)) print("xxx AddressBook.loadAllObjects() groupIDRows=%s" % (groupIDRows,)) - if groupIDRows: - [groupIDs] = groupIDRows - - for groupID in groupIDs: - - #debug, print group members - bind = schema.GROUP_MEMBERSHIP - memberRows = (yield Select([bind.MEMBER_ID,], - From=bind, - Where=bind.GROUP_ID == groupID).on(home._txn)) - - print("xxx AddressBook.loadAllObjects() for groupID=%s" % (memberRows,)) - - child = GroupAddressBook(home, resource_name, resourceID, groupIDs) + child = GroupAddressBook(home, resource_name, resourceID, groupIDRows) if not child: child = cls(home, resource_name, resourceID, owned) @@ -413,17 +402,13 @@ resourceID, groupBindID = data[0] bind = schema.GROUP_BIND - groupIDRows = (yield Select([bind.GROUP_ID,], + groupIDRows = (yield Select([bind.GROUP_ID, bind.BIND_MODE,], From=bind, Where=(bind.ADDRESSBOOK_BIND_ID == groupBindID)).on(home._txn)) - print("xxx AddressBook.objectWithName() memberIDRows=%s name=%s" % (groupIDRows, name,)) - + print("xxx AddressBook.objectWithName() groupIDRows=%s name=%s" % (groupIDRows, name,)) if groupIDRows: - groupIDs = []; - for groupIDRow in groupIDRows: - groupIDs.extend(groupIDRow) - child = GroupAddressBook(home, name, resourceID, groupIDs) + child = GroupAddressBook(home, name, resourceID, groupIDRows) elif didGroupAddressbookQuery: child = None else: @@ -443,7 +428,7 @@ implements(IAddressBook) - def __init__(self, home, name, resourceID, groupIDs): + def __init__(self, home, name, resourceID, groupIDBindModes): """ Initialize an addressbook pointing at a path on disk. @@ -460,14 +445,11 @@ """ super(GroupAddressBook, self).__init__(home, name, resourceID, False) - print("xxx GroupAddressBook.__init__() self=%s, memberIDs=%s" % (self, groupIDs,)) self._objectResourceClass = GroupAddressBookObject + self._groupIDBindModes = groupIDBindModes + print("xxx GroupAddressBook.__init__() self=%s, groupIDBindModes=%s" % (self, groupIDBindModes,)) - print("xxx GroupAddressBook.objectResources() self=%s, self._objectResourceClass=%s" % (self, self._objectResourceClass)) - self._groupIDs = groupIDs - - @classproperty def _memberIDsForGroupIDQuery(cls): #@NoSelf bind = schema.GROUP_MEMBERSHIP @@ -588,16 +570,23 @@ return read-only/read-write members indication """ - print("xxx GroupAddressBook.allowedChildResourceIDs() self=%s" % (self,)) - allowedChildResourceIDs = [] - for groupID in tuple(self._groupIDs): + print("xxx GroupAddressBook.allowedChildResourceIDs() self=%s, self._groupIDBindModes=%s" % (self, self._groupIDBindModes, )) + readonlyChildResourceIDs = [] + readWriteChildResourceIDs = [] + for groupID, bindMode in self._groupIDBindModes: groupMemberIDRows = (yield self._memberIDsForGroupIDQuery.on(self._txn, groupID=groupID)) - - print("xxx GroupAddressBook.allowedChildResourceIDs(): groupMemberIDRows=%s" % (groupMemberIDRows,)) for groupMemberIDRow in groupMemberIDRows: - allowedChildResourceIDs += groupMemberIDRow - print("xxx GroupAddressBook.allowedChildResourceIDs(): allowedChildResourceIDs=%s" % (allowedChildResourceIDs,)) - returnValue(set(allowedChildResourceIDs)) + if bindMode == _BIND_MODE_READ: + readonlyChildResourceIDs.append(groupMemberIDRow[0]) + else: + readWriteChildResourceIDs.append(groupMemberIDRow[0]) + + #debug, calc and print composite privs + readWriteChildResourceIDSet = set(readWriteChildResourceIDs); + readonlyChildResourceIDSet = set(readonlyChildResourceIDs).difference(readWriteChildResourceIDSet) + print("xxx GroupAddressBook.allowedChildResourceIDs(): readonlyChildResourceIDSet=%s, readWriteChildResourceIDSet=%s" % (readonlyChildResourceIDSet, readWriteChildResourceIDSet,)) + + returnValue(set(readonlyChildResourceIDs + readWriteChildResourceIDs)) @inlineCallbacks @@ -606,7 +595,6 @@ AddressBookObject.listObjectResources + filtering """ - print("xxx GroupAddressBook.allowedChildResourceIDs() self=%s" % (self,)) print("xxx GroupAddressBook.listObjectResources() self=%s" % (self,)) if self._objectNames is None: @@ -619,7 +607,6 @@ names = [] for row in rows: - print("xxx GroupAddressBook.listObjectResources(): row=%s" % (row,)) if row[1] in allowedChildResourceIDs: names += [row[0],] Modified: CalendarServer/branches/users/gaya/sharedabgroups/txdav/common/datastore/sql_legacy.py =================================================================== --- CalendarServer/branches/users/gaya/sharedabgroups/txdav/common/datastore/sql_legacy.py 2012-06-05 01:44:31 UTC (rev 9332) +++ CalendarServer/branches/users/gaya/sharedabgroups/txdav/common/datastore/sql_legacy.py 2012-06-05 23:42:39 UTC (rev 9333) @@ -495,6 +495,7 @@ { bind.ADDRESSBOOK_BIND_ID: Parameter("addressbookBindID"), bind.GROUP_ID: Parameter("groupID"), + bind.BIND_MODE: Parameter("mode"), } ) @@ -604,7 +605,7 @@ # constraints in place, whereas INVITE does not. Really we need to do this in a sub-transaction so # we can roll back if any one query fails. if rows: - print("xxx addOrUpdateRecord() leg rows=%s" % (rows,)) + print("xxx addOrUpdateRecord() rows=%s" % (rows,)) [[resourceID, homeResourceID]] = rows yield self._updateBindQuery.on( self._txn, @@ -648,6 +649,7 @@ self._txn, groupID=self._collection._resourceID, addressbookBindID=bindID, + mode=bindMode, ) print("xxx _insertInviteQuery(): uid=%s, name=%s, homeID=%s, resourceID=%s" % (record.inviteuid, Modified: CalendarServer/branches/users/gaya/sharedabgroups/txdav/common/datastore/sql_schema/current.sql =================================================================== --- CalendarServer/branches/users/gaya/sharedabgroups/txdav/common/datastore/sql_schema/current.sql 2012-06-05 01:44:31 UTC (rev 9332) +++ CalendarServer/branches/users/gaya/sharedabgroups/txdav/common/datastore/sql_schema/current.sql 2012-06-05 23:42:39 UTC (rev 9333) @@ -418,11 +418,10 @@ -------------------------------- create table GROUP_BIND ( - ADDRESSBOOK_BIND_ID integer references ADDRESSBOOK_BIND, + ADDRESSBOOK_BIND_ID integer references ADDRESSBOOK_BIND, GROUP_ID integer, -- temporary, should use line below when parser is fixed -- GROUP_ID integer references GROUP_MEMBERSHIP(GROUP_ID), --- or add the following line --- foreign key(GROUP_ID) references GROUP_MEMBERSHIP(GROUP_ID) + BIND_MODE integer not null, -- enum CALENDAR_BIND_MODE primary key(ADDRESSBOOK_BIND_ID, GROUP_ID) -- implicit index );
participants (1)
-
source_changes@macosforge.org