Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
Make sure missing schedule-object state results in a recalculation of…
Browse files Browse the repository at this point in the history
… the proper state to aid migration from non-implicit.

git-svn-id: https://svn.calendarserver.org/repository/calendarserver/CalendarServer/trunk@8015 e27351fd-9f3e-4f54-a53b-843176b1656c
  • Loading branch information
cyrusdaboo committed Aug 25, 2011
1 parent b43ab78 commit cb913d3
Show file tree
Hide file tree
Showing 8 changed files with 566 additions and 13 deletions.
35 changes: 28 additions & 7 deletions twistedcaldav/scheduling/implicit.py
Expand Up @@ -67,7 +67,7 @@ def testImplicitSchedulingPUT(self, request, resource, resource_uri, calendar, i
self.internal_request = internal_request

existing_resource = resource.exists()
is_scheduling_object = self.checkSchedulingObjectResource(resource)
is_scheduling_object = (yield self.checkSchedulingObjectResource(resource))
existing_type = "schedule" if is_scheduling_object else "calendar"
new_type = "schedule" if (yield self.checkImplicitState()) else "calendar"

Expand Down Expand Up @@ -114,8 +114,8 @@ def testImplicitSchedulingMOVE(self, request, srcresource, srccal, src_uri, dest
new_type = "schedule" if (yield self.checkImplicitState()) else "calendar"

dest_exists = destresource.exists()
dest_is_implicit = self.checkSchedulingObjectResource(destresource)
src_is_implicit = self.checkSchedulingObjectResource(srcresource) or new_type == "schedule"
dest_is_implicit = (yield self.checkSchedulingObjectResource(destresource))
src_is_implicit = (yield self.checkSchedulingObjectResource(srcresource)) or new_type == "schedule"

if srccal and destcal:
if src_is_implicit and dest_exists or dest_is_implicit:
Expand Down Expand Up @@ -148,8 +148,8 @@ def testImplicitSchedulingCOPY(self, request, srcresource, srccal, src_uri, dest

new_type = "schedule" if (yield self.checkImplicitState()) else "calendar"

dest_is_implicit = self.checkSchedulingObjectResource(destresource)
src_is_implicit = self.checkSchedulingObjectResource(srcresource) or new_type == "schedule"
dest_is_implicit = (yield self.checkSchedulingObjectResource(destresource))
src_is_implicit = (yield self.checkSchedulingObjectResource(srcresource)) or new_type == "schedule"

if srccal and destcal:
if src_is_implicit or dest_is_implicit:
Expand Down Expand Up @@ -181,15 +181,36 @@ def testImplicitSchedulingDELETE(self, request, resource, calendar, internal_req

yield self.checkImplicitState()

is_scheduling_object = self.checkSchedulingObjectResource(resource)
is_scheduling_object = (yield self.checkSchedulingObjectResource(resource))
resource_type = "schedule" if is_scheduling_object else "calendar"
self.action = "remove" if resource_type == "schedule" else "none"

returnValue((self.action != "none", False,))

@inlineCallbacks
def checkSchedulingObjectResource(self, resource):

return resource.isScheduleObject if resource and resource.exists() else False
if resource and resource.exists():
implicit = resource.isScheduleObject
if implicit is not None:
returnValue(implicit)
else:
calendar = (yield self.resource.iCalendarForUser(self.request))
# Get the ORGANIZER and verify it is the same for all components
try:
organizer = calendar.validOrganizerForScheduling()
except ValueError:
# We have different ORGANIZERs in the same iCalendar object - this is an error
returnValue(False)
organizerPrincipal = resource.principalForCalendarUserAddress(organizer) if organizer else None
implicit = organizerPrincipal != None
log.debug("Implicit - checked scheduling object resource state for UID: '%s', result: %s" % (
calendar.resourceUID(),
implicit,
))
returnValue(implicit)

returnValue(False)

@inlineCallbacks
def checkImplicitState(self):
Expand Down
11 changes: 9 additions & 2 deletions txdav/caldav/datastore/file.py
Expand Up @@ -439,11 +439,18 @@ def _set_accessMode(self, value):
accessMode = property(_get_accessMode, _set_accessMode)

def _get_isScheduleObject(self):
return str(self.properties().get(PropertyName.fromElement(customxml.TwistedSchedulingObjectResource), "false")) == "true"
"""
If the property is not present, then return None, else return a bool based on the
str "true" or "false" value.
"""
prop = self.properties().get(PropertyName.fromElement(customxml.TwistedSchedulingObjectResource))
if prop is not None:
prop = str(prop) == "true"
return prop

def _set_isScheduleObject(self, value):
pname = PropertyName.fromElement(customxml.TwistedSchedulingObjectResource)
if value:
if value is not None:
self.properties()[pname] = customxml.TwistedSchedulingObjectResource.fromString("true" if value else "false")
elif pname in self.properties():
del self.properties()[pname]
Expand Down
2 changes: 1 addition & 1 deletion txdav/caldav/datastore/test/common.py
Expand Up @@ -175,7 +175,7 @@ class CommonTests(CommonCommonTests):
}
metadata3 = {
"accessMode": "PUBLIC",
"isScheduleObject": True,
"isScheduleObject": None,
"scheduleTag": "abc",
"scheduleEtags": (),
"hasPrivateComment": True,
Expand Down
4 changes: 2 additions & 2 deletions txdav/common/datastore/sql_schema/current.sql
Expand Up @@ -174,7 +174,7 @@ create table CALENDAR_OBJECT (
ORGANIZER_OBJECT integer references CALENDAR_OBJECT,
RECURRANCE_MAX date, -- maximum date that recurrences have been expanded to.
ACCESS integer default 0 not null,
SCHEDULE_OBJECT boolean default false not null,
SCHEDULE_OBJECT boolean default false,
SCHEDULE_TAG varchar(36) default null,
SCHEDULE_ETAGS text default null,
PRIVATE_COMMENTS boolean default false not null,
Expand Down Expand Up @@ -479,5 +479,5 @@ create table CALENDARSERVER (
unique(NAME)
);

insert into CALENDARSERVER values ('VERSION', '3');
insert into CALENDARSERVER values ('VERSION', '4');

0 comments on commit cb913d3

Please sign in to comment.