[CalendarServer-changes] [10128] CalendarServer/branches/users/gaya/sharedgroups
source_changes at macosforge.org
source_changes at macosforge.org
Tue Dec 4 20:54:04 PST 2012
Revision: 10128
http://trac.calendarserver.org//changeset/10128
Author: gaya at apple.com
Date: 2012-12-04 20:54:04 -0800 (Tue, 04 Dec 2012)
Log Message:
-----------
in sharing.py, SharedCollectionMixin -> SharedResourceMixin plus other name cleanup; Move SharedCollectionsDatabase & SharedCollectionRecord to txdav.common.datastore.file.py, the only place these classes are used.
Modified Paths:
--------------
CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/resource.py
CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/sharing.py
CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/test/test_sharing.py
CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py
CalendarServer/branches/users/gaya/sharedgroups/txdav/common/datastore/file.py
Modified: CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/resource.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/resource.py 2012-12-05 00:02:05 UTC (rev 10127)
+++ CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/resource.py 2012-12-05 04:54:04 UTC (rev 10128)
@@ -79,7 +79,7 @@
getPubSubConfiguration, getPubSubXMPPURI, getPubSubHeartbeatURI,
getPubSubAPSConfiguration,
)
-from twistedcaldav.sharing import SharedCollectionMixin, SharedHomeMixin
+from twistedcaldav.sharing import SharedResourceMixin, SharedHomeMixin
from twistedcaldav.util import normalizationLookup
from twistedcaldav.vcard import Component as vComponent
@@ -224,7 +224,7 @@
class CalDAVResource (
- CalDAVComplianceMixIn, SharedCollectionMixin,
+ CalDAVComplianceMixIn, SharedResourceMixin,
DAVResourceWithChildrenMixin, DAVResource, LoggingMixIn
):
"""
Modified: CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/sharing.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/sharing.py 2012-12-05 00:02:05 UTC (rev 10127)
+++ CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/sharing.py 2012-12-05 04:54:04 UTC (rev 10128)
@@ -21,10 +21,9 @@
__all__ = [
- "SharedCollectionMixin",
+ "SharedResourceMixin",
]
-from twext.python.log import LoggingMixIn
from twext.web2 import responsecode
from twext.web2.http import HTTPError, Response, XMLResponse
from twext.web2.dav.http import ErrorResponse, MultiStatusResponse
@@ -44,12 +43,9 @@
from twistedcaldav.customxml import calendarserver_namespace
from twistedcaldav.directory.wiki import WikiDirectoryService, getWikiAccess
from twistedcaldav.linkresource import LinkFollowerMixIn
-from twistedcaldav.sql import AbstractSQLDatabase, db_prefix
from pycalendar.datetime import PyCalendarDateTime
-import os
-import types
# FIXME: Get rid of these imports
from twistedcaldav.directory.util import TRANSACTION_KEY
@@ -60,7 +56,7 @@
#ENOTIFICATIONTYPE = 2
-class SharedCollectionMixin(object):
+class SharedResourceMixin(object):
@inlineCallbacks
def inviteProperty(self, request):
@@ -260,7 +256,7 @@
def resourceType(self):
- superObject = super(SharedCollectionMixin, self)
+ superObject = super(SharedResourceMixin, self)
try:
superMethod = superObject.resourceType
except AttributeError:
@@ -1015,18 +1011,18 @@
elif self._newStoreHome._homeType == EADDRESSBOOKTYPE:
sharerHomeCollection = yield sharer.addressBookHome(request)
- itemShared = yield child.ownerHome().childWithID(child._resourceID)
- if itemShared:
- url = joinURL(sharerHomeCollection.url(), itemShared.name())
+ sharerHomeChild = yield child.ownerHome().childWithID(child._resourceID)
+ if sharerHomeChild:
+ url = joinURL(sharerHomeCollection.url(), sharerHomeChild.name())
+ share = Share(shareeHomeChild=child, sharerHomeChildOrGroup=sharerHomeChild, url=url)
else:
for sharerHomeChild in (yield child.ownerHome().children()):
- itemShared = yield sharerHomeChild.objectResourceWithID(child._resourceID)
- if itemShared:
- url = joinURL(sharerHomeCollection.url(), itemShared._parentCollection.name(), itemShared.name())
+ sharedGroup = yield sharerHomeChild.objectResourceWithID(child._resourceID)
+ if sharedGroup:
+ url = joinURL(sharerHomeCollection.url(), sharerHomeChild.name(), sharedGroup.name())
+ share = Share(shareeHomeChild=child, sharerHomeChildOrGroup=sharedGroup, url=url)
break
- share = Share(shareeHomeChild=child, sharerHomeChild=itemShared, url=url)
-
returnValue(share)
@inlineCallbacks
@@ -1059,9 +1055,9 @@
if oldShare:
share = oldShare
else:
- sharedCollection = yield request.locateResource(hostUrl)
+ sharedResource = yield request.locateResource(hostUrl)
shareeHomeChild = yield self._newStoreHome.childWithName(inviteUID)
- share = Share(shareeHomeChild=shareeHomeChild, sharerHomeChild=sharedCollection._newStoreObject, url=hostUrl)
+ share = Share(shareeHomeChild=shareeHomeChild, sharerHomeChildOrGroup=sharedResource._newStoreObject, url=hostUrl)
response = yield self._acceptShare(request, not oldShare, share, displayname)
returnValue(response)
@@ -1082,7 +1078,7 @@
message=displayname)
shareeHomeChild = yield self._newStoreHome.childWithName(sharedName)
- share = Share(shareeHomeChild=shareeHomeChild, sharerHomeChild=sharedCollection._newStoreObject, url=hostUrl)
+ share = Share(shareeHomeChild=shareeHomeChild, sharerHomeChildOrGroup=sharedCollection._newStoreObject, url=hostUrl)
response = yield self._acceptShare(request, not oldShare, share, displayname)
returnValue(response)
@@ -1091,20 +1087,20 @@
def _acceptShare(self, request, isNewShare, share, displayname=None):
# Get shared collection in non-share mode first
- sharedCollection = yield request.locateResource(share.url())
+ sharedResource = yield request.locateResource(share.url())
# For a direct share we will copy any calendar-color over using the owners view
color = None
- if share.direct() and isNewShare and sharedCollection.isCalendarCollection():
+ if share.direct() and isNewShare and sharedResource.isCalendarCollection():
try:
- color = (yield sharedCollection.readProperty(customxml.CalendarColor, request))
+ color = (yield sharedResource.readProperty(customxml.CalendarColor, request))
except HTTPError:
pass
sharee = self.principalForUID(share.shareeUID())
- if sharedCollection.isCalendarCollection():
+ if sharedResource.isCalendarCollection():
shareeHomeResource = yield sharee.calendarHome(request)
- elif sharedCollection.isAddressBookCollection() or sharedCollection.isGroup():
+ elif sharedResource.isAddressBookCollection() or sharedResource.isGroup():
shareeHomeResource = yield sharee.addressBookHome(request)
shareeURL = joinURL(shareeHomeResource.url(), share.name())
shareeCollection = yield request.locateResource(shareeURL)
@@ -1112,7 +1108,7 @@
#FIXME: addcresourceType to dead properties for share groups -
# it's already there for shared address book and calendars
- if isNewShare and sharedCollection.isGroup():
+ if isNewShare and sharedResource.isGroup():
shareeCollection.writeDeadProperty(carddavxml.ResourceType.addressbook)
# For calendars only, per-user displayname and color
@@ -1192,9 +1188,9 @@
if share.direct():
- yield share._sharerHomeChild.unshareWith(share._shareeHomeChild.viewerHome())
+ yield share._sharerHomeChildOrGroup.unshareWith(share._shareeHomeChild.viewerHome())
else:
- yield share._sharerHomeChild.updateShare(share._shareeHomeChild, status=_BIND_STATUS_DECLINED)
+ yield share._sharerHomeChildOrGroup.updateShare(share._shareeHomeChild, status=_BIND_STATUS_DECLINED)
returnValue(displayname)
@@ -1219,8 +1215,8 @@
# Change state in sharer invite
ownerPrincipal = (yield self.ownerPrincipal(request))
ownerPrincipalUID = ownerPrincipal.principalUID()
- sharedCollection = (yield request.locateResource(hostUrl))
- if sharedCollection is None:
+ sharedResource = (yield request.locateResource(hostUrl))
+ if sharedResource is None:
# Original shared collection is gone - nothing we can do except ignore it
raise HTTPError(ErrorResponse(
responsecode.FORBIDDEN,
@@ -1229,16 +1225,16 @@
))
# Change the record
- yield sharedCollection.changeUserInviteState(request, replytoUID, ownerPrincipalUID, state, displayname)
+ yield sharedResource.changeUserInviteState(request, replytoUID, ownerPrincipalUID, state, displayname)
- yield self.sendReply(request, ownerPrincipal, sharedCollection, state, hostUrl, replytoUID, displayname)
+ yield self.sendReply(request, ownerPrincipal, sharedResource, state, hostUrl, replytoUID, displayname)
@inlineCallbacks
- def sendReply(self, request, shareePrincipal, sharedCollection, state, hostUrl, replytoUID, displayname=None):
+ def sendReply(self, request, shareePrincipal, sharedResource, state, hostUrl, replytoUID, displayname=None):
# Locate notifications collection for sharer
- sharer = (yield sharedCollection.ownerPrincipal(request))
+ sharer = (yield sharedResource.ownerPrincipal(request))
notificationResource = (yield request.locateResource(sharer.notificationURL()))
notifications = notificationResource._newStoreNotifications
@@ -1312,20 +1308,11 @@
-class SharedCollectionRecord(object):
-
- def __init__(self, shareuid, sharetype, hosturl, localname, summary):
- self.shareuid = shareuid
- self.sharetype = sharetype
- self.hosturl = hosturl
- self.localname = localname
- self.summary = summary
-
class Share(object):
- def __init__(self, sharerHomeChild, shareeHomeChild, url):
+ def __init__(self, sharerHomeChildOrGroup, shareeHomeChild, url):
self._shareeHomeChild = shareeHomeChild
- self._sharerHomeChild = sharerHomeChild
+ self._sharerHomeChildOrGroup = sharerHomeChildOrGroup
self._sharedResourceURL = url
@classmethod
@@ -1335,7 +1322,7 @@
def uid(self):
# Move to CommonHomeChild shareUID?
if self._shareeHomeChild.shareMode() == _BIND_MODE_DIRECT:
- return self.directUID(shareeHome=self._shareeHomeChild.viewerHome(), sharerHomeChild=self._sharerHomeChild,)
+ return self.directUID(shareeHome=self._shareeHomeChild.viewerHome(), sharerHomeChild=self._sharerHomeChildOrGroup,)
else:
return self._shareeHomeChild.shareUID()
@@ -1353,145 +1340,3 @@
def shareeUID(self):
return self._shareeHomeChild.viewerHome().uid()
-
-class SharedCollectionsDatabase(AbstractSQLDatabase, LoggingMixIn):
-
- db_basename = db_prefix + "shares"
- schema_version = "1"
- db_type = "shares"
-
- def __init__(self, resource):
- """
- @param resource: the L{CalDAVResource} resource for
- the shared collection. C{resource} must be a calendar/addressbook home collection.)
- """
- self.resource = resource
- db_filename = os.path.join(self.resource.fp.path, SharedCollectionsDatabase.db_basename)
- super(SharedCollectionsDatabase, self).__init__(db_filename, True, autocommit=True)
-
-
- def get_dbpath(self):
- return self.resource.fp.child(SharedCollectionsDatabase.db_basename).path
-
-
- def set_dbpath(self, newpath):
- pass
-
- dbpath = property(get_dbpath, set_dbpath)
-
-
- def create(self):
- """
- Create the index and initialize it.
- """
- self._db()
-
-
- def allRecords(self):
-
- records = self._db_execute("select * from SHARES order by LOCALNAME")
- return [self._makeRecord(row) for row in (records if records is not None else ())]
-
-
- def recordForShareUID(self, shareUID):
-
- row = self._db_execute("select * from SHARES where SHAREUID = :1", shareUID)
- return self._makeRecord(row[0]) if row else None
-
-
- def addOrUpdateRecord(self, record):
-
- self._db_execute("""insert or replace into SHARES (SHAREUID, SHARETYPE, HOSTURL, LOCALNAME, SUMMARY)
- values (:1, :2, :3, :4, :5)
- """, record.shareuid, record.sharetype, record.hosturl, record.localname, record.summary,
- )
-
-
- def removeRecordForLocalName(self, localname):
-
- self._db_execute("delete from SHARES where LOCALNAME = :1", localname)
-
-
- def removeRecordForShareUID(self, shareUID):
-
- self._db_execute("delete from SHARES where SHAREUID = :1", shareUID)
-
-
- def remove(self):
-
- self._db_close()
- os.remove(self.dbpath)
-
-
- def directShareID(self, shareeHome, sharerCollection):
- return "Direct-%s-%s" % (shareeHome.resourceID(), sharerCollection.resourceID(),)
-
-
- def _db_version(self):
- """
- @return: the schema version assigned to this index.
- """
- return SharedCollectionsDatabase.schema_version
-
-
- def _db_type(self):
- """
- @return: the collection type assigned to this index.
- """
- return SharedCollectionsDatabase.db_type
-
-
- def _db_init_data_tables(self, q):
- """
- Initialise the underlying database tables.
- @param q: a database cursor to use.
- """
- #
- # SHARES table is the primary table
- # SHAREUID: UID for this share
- # SHARETYPE: type of share: "I" for invite, "D" for direct
- # HOSTURL: URL for data source
- # LOCALNAME: local path name
- # SUMMARY: Share summary
- #
- q.execute(
- """
- create table SHARES (
- SHAREUID text unique,
- SHARETYPE text(1),
- HOSTURL text,
- LOCALNAME text,
- SUMMARY text
- )
- """
- )
-
- q.execute(
- """
- create index SHAREUID on SHARES (SHAREUID)
- """
- )
- q.execute(
- """
- create index HOSTURL on SHARES (HOSTURL)
- """
- )
- q.execute(
- """
- create index LOCALNAME on SHARES (LOCALNAME)
- """
- )
-
-
- def _db_upgrade_data_tables(self, q, old_version):
- """
- Upgrade the data from an older version of the DB.
- """
-
- # Nothing to do as we have not changed the schema
- pass
-
-
- def _makeRecord(self, row):
-
- return SharedCollectionRecord(*[str(item) if type(item) == types.UnicodeType else item for item in row])
Modified: CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/test/test_sharing.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/test/test_sharing.py 2012-12-05 00:02:05 UTC (rev 10127)
+++ CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/test/test_sharing.py 2012-12-05 04:54:04 UTC (rev 10128)
@@ -25,7 +25,7 @@
from twistedcaldav import customxml
from twistedcaldav.config import config
from twistedcaldav.test.util import HomeTestCase, norequest
-from twistedcaldav.sharing import SharedCollectionMixin, WikiDirectoryService
+from twistedcaldav.sharing import SharedResourceMixin, WikiDirectoryService
from twistedcaldav.resource import CalDAVResource
from txdav.common.datastore.test.util import buildStore, StubNotifierFactory
@@ -627,7 +627,7 @@
def shareeUID(self):
return StubUserPrincipal().record.guid
- class TestCollection(SharedCollectionMixin, StubCollection):
+ class TestCollection(SharedResourceMixin, StubCollection):
def principalForUID(self, uid):
principal = StubUserPrincipal()
return principal if principal.record.guid == uid else None
Modified: CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py 2012-12-05 00:02:05 UTC (rev 10127)
+++ CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py 2012-12-05 04:54:04 UTC (rev 10128)
@@ -205,7 +205,7 @@
def resourceType(self):
return ResourceType.addressbook #@UndefinedVariable
- #FIXME: Only used for resouretype in SharedCollectionMixin.upgradeToShare() and SharedCollectionMixin.downgradeFromShare()
+ #FIXME: Only used for shared group resouretype in SharedResourceMixin.upgradeToShare() and SharedResourceMixin.downgradeFromShare()
def objectResourcesHaveProperties(self):
return True
Modified: CalendarServer/branches/users/gaya/sharedgroups/txdav/common/datastore/file.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups/txdav/common/datastore/file.py 2012-12-05 00:02:05 UTC (rev 10127)
+++ CalendarServer/branches/users/gaya/sharedgroups/txdav/common/datastore/file.py 2012-12-05 04:54:04 UTC (rev 10128)
@@ -36,7 +36,6 @@
from twistedcaldav.customxml import NotificationType
from twistedcaldav.notifications import NotificationRecord
from twistedcaldav.notifications import NotificationsDatabase as OldNotificationIndex
-from twistedcaldav.sharing import SharedCollectionsDatabase
from txdav.caldav.icalendarstore import ICalendarStore, BIND_OWN
from txdav.common.datastore.common import HomeChildBase
@@ -58,7 +57,11 @@
from zope.interface import implements, directlyProvides
import uuid
+from twistedcaldav.sql import AbstractSQLDatabase, db_prefix
+import os
+import types
+
ECALENDARTYPE = 0
EADDRESSBOOKTYPE = 1
@@ -376,6 +379,159 @@
+class SharedCollectionRecord(object):
+
+ def __init__(self, shareuid, sharetype, hosturl, localname, summary):
+ self.shareuid = shareuid
+ self.sharetype = sharetype
+ self.hosturl = hosturl
+ self.localname = localname
+ self.summary = summary
+
+
+class SharedCollectionsDatabase(AbstractSQLDatabase, LoggingMixIn):
+
+ db_basename = db_prefix + "shares"
+ schema_version = "1"
+ db_type = "shares"
+
+ def __init__(self, resource):
+ """
+ @param resource: the L{CalDAVResource} resource for
+ the shared collection. C{resource} must be a calendar/addressbook home collection.)
+ """
+ self.resource = resource
+ db_filename = os.path.join(self.resource.fp.path, SharedCollectionsDatabase.db_basename)
+ super(SharedCollectionsDatabase, self).__init__(db_filename, True, autocommit=True)
+
+
+ def get_dbpath(self):
+ return self.resource.fp.child(SharedCollectionsDatabase.db_basename).path
+
+
+ def set_dbpath(self, newpath):
+ pass
+
+ dbpath = property(get_dbpath, set_dbpath)
+
+
+ def create(self):
+ """
+ Create the index and initialize it.
+ """
+ self._db()
+
+
+ def allRecords(self):
+
+ records = self._db_execute("select * from SHARES order by LOCALNAME")
+ return [self._makeRecord(row) for row in (records if records is not None else ())]
+
+
+ def recordForShareUID(self, shareUID):
+
+ row = self._db_execute("select * from SHARES where SHAREUID = :1", shareUID)
+ return self._makeRecord(row[0]) if row else None
+
+
+ def addOrUpdateRecord(self, record):
+
+ self._db_execute("""insert or replace into SHARES (SHAREUID, SHARETYPE, HOSTURL, LOCALNAME, SUMMARY)
+ values (:1, :2, :3, :4, :5)
+ """, record.shareuid, record.sharetype, record.hosturl, record.localname, record.summary,
+ )
+
+
+ def removeRecordForLocalName(self, localname):
+
+ self._db_execute("delete from SHARES where LOCALNAME = :1", localname)
+
+
+ def removeRecordForShareUID(self, shareUID):
+
+ self._db_execute("delete from SHARES where SHAREUID = :1", shareUID)
+
+
+ def remove(self):
+
+ self._db_close()
+ os.remove(self.dbpath)
+
+
+ def directShareID(self, shareeHome, sharerCollection):
+ return "Direct-%s-%s" % (shareeHome.resourceID(), sharerCollection.resourceID(),)
+
+
+ def _db_version(self):
+ """
+ @return: the schema version assigned to this index.
+ """
+ return SharedCollectionsDatabase.schema_version
+
+
+ def _db_type(self):
+ """
+ @return: the collection type assigned to this index.
+ """
+ return SharedCollectionsDatabase.db_type
+
+
+ def _db_init_data_tables(self, q):
+ """
+ Initialise the underlying database tables.
+ @param q: a database cursor to use.
+ """
+ #
+ # SHARES table is the primary table
+ # SHAREUID: UID for this share
+ # SHARETYPE: type of share: "I" for invite, "D" for direct
+ # HOSTURL: URL for data source
+ # LOCALNAME: local path name
+ # SUMMARY: Share summary
+ #
+ q.execute(
+ """
+ create table SHARES (
+ SHAREUID text unique,
+ SHARETYPE text(1),
+ HOSTURL text,
+ LOCALNAME text,
+ SUMMARY text
+ )
+ """
+ )
+
+ q.execute(
+ """
+ create index SHAREUID on SHARES (SHAREUID)
+ """
+ )
+ q.execute(
+ """
+ create index HOSTURL on SHARES (HOSTURL)
+ """
+ )
+ q.execute(
+ """
+ create index LOCALNAME on SHARES (LOCALNAME)
+ """
+ )
+
+
+ def _db_upgrade_data_tables(self, q, old_version):
+ """
+ Upgrade the data from an older version of the DB.
+ """
+
+ # Nothing to do as we have not changed the schema
+ pass
+
+
+ def _makeRecord(self, row):
+
+ return SharedCollectionRecord(*[str(item) if type(item) == types.UnicodeType else item for item in row])
+
+
class CommonHome(FileMetaDataMixin, LoggingMixIn):
# All these need to be initialized by derived classes for each store type
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20121204/ca51185a/attachment-0001.html>
More information about the calendarserver-changes
mailing list