[CalendarServer-changes] [15408] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Sat Dec 19 07:01:41 PST 2015
Revision: 15408
http://trac.calendarserver.org//changeset/15408
Author: cdaboo at apple.com
Date: 2015-12-19 07:01:41 -0800 (Sat, 19 Dec 2015)
Log Message:
-----------
Fake email address for resources and locations.
Modified Paths:
--------------
CalendarServer/trunk/conf/caldavd-stdconfig.plist
CalendarServer/trunk/twistedcaldav/ical.py
CalendarServer/trunk/twistedcaldav/stdconfig.py
CalendarServer/trunk/twistedcaldav/test/test_icalendar.py
CalendarServer/trunk/txdav/common/datastore/test/accounts/resources.xml
CalendarServer/trunk/txdav/who/augment.py
CalendarServer/trunk/txdav/who/directory.py
CalendarServer/trunk/txdav/who/test/test_directory.py
CalendarServer/trunk/txdav/who/wiki.py
Modified: CalendarServer/trunk/conf/caldavd-stdconfig.plist
===================================================================
--- CalendarServer/trunk/conf/caldavd-stdconfig.plist 2015-12-19 03:26:23 UTC (rev 15407)
+++ CalendarServer/trunk/conf/caldavd-stdconfig.plist 2015-12-19 15:01:41 UTC (rev 15408)
@@ -1420,6 +1420,10 @@
<key>TrackUnscheduledResourceData</key>
<true/>
+ <!-- Add fake email addresses to work around client bug -->
+ <key>FakeResourceLocationEmail</key>
+ <false/>
+
<!-- Maximum number of attendees to request freebusy for -->
<key>LimitFreeBusyAttendees</key>
<integer>30</integer>
Modified: CalendarServer/trunk/twistedcaldav/ical.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/ical.py 2015-12-19 03:26:23 UTC (rev 15407)
+++ CalendarServer/trunk/twistedcaldav/ical.py 2015-12-19 15:01:41 UTC (rev 15408)
@@ -3510,6 +3510,10 @@
if oldemail:
oldemail = "mailto:{0}".format(oldemail,)
+ if config.Scheduling.Options.FakeResourceLocationEmail:
+ if oldemail.endswith("@do_not_reply"):
+ oldemail = None
+
# Get any CN parameter
oldCN = prop.parameterValue("CN")
@@ -3583,6 +3587,10 @@
else:
email = None
+ if config.Scheduling.Options.FakeResourceLocationEmail:
+ if email and email.endswith("@do_not_reply"):
+ email = ""
+
if email:
prop.setParameter("EMAIL", email)
else:
Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/stdconfig.py 2015-12-19 03:26:23 UTC (rev 15407)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py 2015-12-19 15:01:41 UTC (rev 15408)
@@ -767,6 +767,7 @@
"AllowResourceWithoutOrganizer" : True, # Allow resources to have events without an Organizer
"TrackUnscheduledLocationData" : True, # Track who the last modifier of an unscheduled location event is
"TrackUnscheduledResourceData" : True, # Track who the last modifier of an unscheduled resource event is
+ "FakeResourceLocationEmail" : False, # Add fake email addresses to work around client bug
"LimitFreeBusyAttendees" : 30, # Maximum number of attendees to request freebusy for
"AttendeeRefreshBatch" : 5, # Number of attendees to do batched refreshes: 0 - no batching
"AttendeeRefreshCountLimit" : 50, # Number of attendees above which attendee refreshes are suppressed: 0 - no limit
@@ -1768,6 +1769,7 @@
)
POST_UPDATE_HOOKS = (
_updateMultiProcess,
+ _updateUtilityLog, # Must be before _updateDataStore for proper relative path
_updateDataStore,
_updateHostName,
_updateWorkQueue,
@@ -1777,7 +1779,6 @@
_updateACLs,
_updateRejectClients,
_updateClientFixes,
- _updateUtilityLog,
_updateLogLevels,
_updateNotifications,
_updateICalendar,
Modified: CalendarServer/trunk/twistedcaldav/test/test_icalendar.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_icalendar.py 2015-12-19 03:26:23 UTC (rev 15407)
+++ CalendarServer/trunk/twistedcaldav/test/test_icalendar.py 2015-12-19 15:01:41 UTC (rev 15408)
@@ -21,6 +21,7 @@
from twisted.trial.unittest import SkipTest
from twisted.internet.defer import inlineCallbacks, succeed
+from twistedcaldav.config import config
from twistedcaldav.dateops import normalizeForExpand
from twistedcaldav.ical import Component, Property, InvalidICalendarDataError, \
normalizeCUAddress, normalize_iCalStr, diff_iCalStrs
@@ -8434,6 +8435,73 @@
self.assertEquals(prop.parameterValue("CN"), "{Restricted} Buzz")
+ def test_normalizeCalendarUserAddressesWithFakeEmail(self):
+ """
+ Ensure fake email addresses are not inserted as EMAIL parameters.
+ """
+
+ self.patch(config.Scheduling.Options, "FakeResourceLocationEmail", True)
+
+ data = """BEGIN:VCALENDAR
+VERSION:2.0
+DTSTART:20071114T000000Z
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20071114T000000Z
+ATTENDEE:/principals/users/foo
+ATTENDEE;CN=Fake 1;CUTYPE=ROOM:mailto:fake1 at do_not_reply
+ATTENDEE;CN=Fake 2;CUTYPE=ROOM;EMAIL=fake2 at do_not_reply:mailto:fake2 at do_not_reply
+LOCATION:Buzz
+DTSTAMP:20071114T000000Z
+END:VEVENT
+END:VCALENDAR
+"""
+
+ result = """BEGIN:VCALENDAR
+VERSION:2.0
+DTSTART:20071114T000000Z
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20071114T000000Z
+ATTENDEE;CN=Foo;EMAIL=foo at example.com:urn:x-uid:foo
+ATTENDEE;CN=Fake 1;CUTYPE=ROOM:urn:x-uid:fake1
+ATTENDEE;CN=Fake 2;CUTYPE=ROOM:urn:x-uid:fake2
+LOCATION:Buzz
+DTSTAMP:20071114T000000Z
+END:VEVENT
+END:VCALENDAR
+"""
+
+ component = Component.fromString(data)
+
+
+ def lookupFunction(cuaddr, ignored1, ignored2):
+ return succeed({
+ "/principals/users/foo" : (
+ "Foo",
+ "foo",
+ "INDIVIDUAL",
+ ("urn:x-uid:foo", "mailto:foo at example.com")
+ ),
+ "mailto:fake1 at do_not_reply" : (
+ "Fake 1",
+ "fake1",
+ "ROOM",
+ ("urn:x-uid:fake1", "mailto:fake1 at do_not_reply")
+ ),
+ "mailto:fake2 at do_not_reply" : (
+ "Fake 2",
+ "fake2",
+ "ROOM",
+ ("urn:x-uid:fake2", "mailto:fake2 at do_not_reply")
+ ),
+ }[cuaddr])
+
+ component.normalizeCalendarUserAddresses(lookupFunction, None, toURN_UUID=True)
+
+ self.assertEqual(normalize_iCalStr(component), normalize_iCalStr(result))
+
+
def test_serializationCaching(self):
data = """BEGIN:VCALENDAR
Modified: CalendarServer/trunk/txdav/common/datastore/test/accounts/resources.xml
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/test/accounts/resources.xml 2015-12-19 03:26:23 UTC (rev 15407)
+++ CalendarServer/trunk/txdav/common/datastore/test/accounts/resources.xml 2015-12-19 15:01:41 UTC (rev 15408)
@@ -80,6 +80,11 @@
<short-name>sanchezoffice</short-name>
<full-name>Sanchez Office</full-name>
</record>
+ <record type="resource">
+ <short-name>resource01</short-name>
+ <uid>resource01</uid>
+ <full-name>Resource 01</full-name>
+ </record>
<record type="location">
<uid>75EA36BE-F71B-40F9-81F9-CF59BF40CA8F</uid>
<guid>75EA36BE-F71B-40F9-81F9-CF59BF40CA8F</guid>
Modified: CalendarServer/trunk/txdav/who/augment.py
===================================================================
--- CalendarServer/trunk/txdav/who/augment.py 2015-12-19 03:26:23 UTC (rev 15407)
+++ CalendarServer/trunk/txdav/who/augment.py 2015-12-19 15:01:41 UTC (rev 15408)
@@ -476,6 +476,7 @@
def __init__(self, service, baseRecord, augmentedFields):
DirectoryRecord.__init__(self, service, augmentedFields)
+ CalendarDirectoryRecordMixin.__init__(self)
self._baseRecord = baseRecord
Modified: CalendarServer/trunk/txdav/who/directory.py
===================================================================
--- CalendarServer/trunk/txdav/who/directory.py 2015-12-19 03:26:23 UTC (rev 15407)
+++ CalendarServer/trunk/txdav/who/directory.py 2015-12-19 15:01:41 UTC (rev 15408)
@@ -25,7 +25,7 @@
MatchType, Operand, MatchExpression, CompoundExpression, MatchFlags,
ExistsExpression, BooleanExpression
)
-from twext.who.idirectory import RecordType as BaseRecordType
+from twext.who.idirectory import RecordType as BaseRecordType, FieldName as BaseFieldName
from twisted.cred.credentials import UsernamePassword
from twisted.internet.defer import inlineCallbacks, returnValue
from twistedcaldav.config import config
@@ -81,6 +81,10 @@
address = normalizeCUAddr(address)
record = None
+ if config.Scheduling.Options.FakeResourceLocationEmail:
+ if address.startswith("mailto:") and address.endswith("@do_not_reply"):
+ address = "urn:x-uid:{}".format(address[7:-13].decode("hex"))
+
if address.startswith("urn:x-uid:"):
uid = address[10:]
record = yield self.recordWithUID(
@@ -341,6 +345,12 @@
class
"""
+ def __init__(self):
+ if config.Scheduling.Options.FakeResourceLocationEmail:
+ if self.recordType in (DAVRecordType.location, DAVRecordType.resource) and not getattr(self, "emailAddresses", None):
+ self.fields[BaseFieldName.emailAddresses] = ("{}@do_not_reply".format(self.uid.encode("hex"),),)
+
+
@inlineCallbacks
def verifyCredentials(self, credentials):
Modified: CalendarServer/trunk/txdav/who/test/test_directory.py
===================================================================
--- CalendarServer/trunk/txdav/who/test/test_directory.py 2015-12-19 03:26:23 UTC (rev 15407)
+++ CalendarServer/trunk/txdav/who/test/test_directory.py 2015-12-19 15:01:41 UTC (rev 15408)
@@ -19,15 +19,16 @@
"""
from twisted.internet.defer import inlineCallbacks
+from twistedcaldav.config import config
from twistedcaldav.test.util import StoreTestCase
from twext.who.directory import DirectoryRecord
from twext.who.idirectory import FieldName, RecordType
from txdav.who.directory import CalendarDirectoryRecordMixin, AutoScheduleMode
-from txdav.who.util import startswithFilter
-from uuid import UUID
from twext.who.expression import (
MatchType, MatchFlags, MatchExpression
)
+from txdav.who.util import startswithFilter
+from uuid import UUID
@@ -206,6 +207,33 @@
@inlineCallbacks
+ def test_recordWithCalendarUserAddress_no_fake_email(self):
+ """
+ Make sure that recordWithCalendarUserAddress handles fake emails for
+ resources and locations.
+ """
+
+ record = yield self.directory.recordWithCalendarUserAddress(u"mailto:{}@do_not_reply".format("resource01".encode("hex")))
+ self.assertTrue(record is None)
+ record = yield self.directory.recordWithCalendarUserAddress(u"mailto:{}@do_not_reply".format("75EA36BE-F71B-40F9-81F9-CF59BF40CA8F".encode("hex")))
+ self.assertTrue(record is None)
+ record = yield self.directory.recordWithCalendarUserAddress(u"mailto:{}@do_not_reply".format("resource02".encode("hex")))
+ self.assertTrue(record is None)
+
+
+ @inlineCallbacks
+ def test_calendarUserAddress_no_fake_email(self):
+ """
+ Make sure that recordWs have fake email addresses.
+ """
+
+ record = yield self.directory.recordWithUID(u"resource01")
+ self.assertTrue(record is not None)
+ self.assertTrue(len(getattr(record, "emailAddresses", ())) == 0)
+ self.assertTrue(len([cuaddr for cuaddr in record.calendarUserAddresses if cuaddr.startswith("mailto:")]) == 0)
+
+
+ @inlineCallbacks
def test_recordsMatchingTokensNoFilter(self):
"""
Records with names containing the token are returned
@@ -328,3 +356,43 @@
),
notInGroupMode
)
+
+
+
+class DirectoryTestCaseFakeEmail(StoreTestCase):
+
+
+ def configure(self):
+ """
+ Adjust the global configuration for this test.
+ """
+ super(StoreTestCase, self).configure()
+
+ config.Scheduling.Options.FakeResourceLocationEmail = True
+
+
+ @inlineCallbacks
+ def test_recordWithCalendarUserAddress_fake_email(self):
+ """
+ Make sure that recordWithCalendarUserAddress handles fake emails for
+ resources and locations.
+ """
+
+ record = yield self.directory.recordWithCalendarUserAddress(u"mailto:{}@do_not_reply".format("resource01".encode("hex")))
+ self.assertTrue(record is not None)
+ record = yield self.directory.recordWithCalendarUserAddress(u"mailto:{}@do_not_reply".format("75EA36BE-F71B-40F9-81F9-CF59BF40CA8F".encode("hex")))
+ self.assertTrue(record is not None)
+ record = yield self.directory.recordWithCalendarUserAddress(u"mailto:{}@do_not_reply".format("resource02".encode("hex")))
+ self.assertTrue(record is None)
+
+
+ @inlineCallbacks
+ def test_calendarUserAddress_fake_email(self):
+ """
+ Make sure that recordWs have fake email addresses.
+ """
+
+ record = yield self.directory.recordWithUID(u"resource01")
+ self.assertTrue(record is not None)
+ self.assertIn(u"{}@do_not_reply".format("resource01".encode("hex")), record.emailAddresses)
+ self.assertIn(u"mailto:{}@do_not_reply".format("resource01".encode("hex")), record.calendarUserAddresses)
Modified: CalendarServer/trunk/txdav/who/wiki.py
===================================================================
--- CalendarServer/trunk/txdav/who/wiki.py 2015-12-19 03:26:23 UTC (rev 15407)
+++ CalendarServer/trunk/txdav/who/wiki.py 2015-12-19 15:01:41 UTC (rev 15408)
@@ -148,6 +148,11 @@
log = Logger()
+ def __init__(self, service, fields):
+ BaseDirectoryRecord.__init__(self, service, fields)
+ CalendarDirectoryRecordMixin.__init__(self)
+
+
@property
def name(self):
return self.shortNames[0]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20151219/1bf0c458/attachment-0001.html>
More information about the calendarserver-changes
mailing list