[CalendarServer-changes] [15755] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Jul 7 13:38:32 PDT 2016


Revision: 15755
          http://trac.calendarserver.org//changeset/15755
Author:   sagen at apple.com
Date:     2016-07-07 13:38:32 -0700 (Thu, 07 Jul 2016)
Log Message:
-----------
Adds a new record.setAutoScheduleMode( ) method which csmp, web admin, and dps all use.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/gateway.py
    CalendarServer/trunk/calendarserver/tools/principals.py
    CalendarServer/trunk/calendarserver/tools/test/test_principals.py
    CalendarServer/trunk/calendarserver/tools/util.py
    CalendarServer/trunk/calendarserver/webadmin/delegation.py
    CalendarServer/trunk/txdav/caldav/icalendardirectoryservice.py
    CalendarServer/trunk/txdav/dps/client.py
    CalendarServer/trunk/txdav/dps/commands.py
    CalendarServer/trunk/txdav/dps/server.py
    CalendarServer/trunk/txdav/dps/test/test_client.py
    CalendarServer/trunk/txdav/who/augment.py
    CalendarServer/trunk/txdav/who/directory.py
    CalendarServer/trunk/txdav/who/test/test_directory.py

Modified: CalendarServer/trunk/calendarserver/tools/gateway.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/gateway.py	2016-07-07 18:53:32 UTC (rev 15754)
+++ CalendarServer/trunk/calendarserver/tools/gateway.py	2016-07-07 20:38:32 UTC (rev 15755)
@@ -35,16 +35,14 @@
     WRITABLE_CONFIG_KEYS, setKeyPath, getKeyPath, flattenDictionary,
     WritableConfig
 )
-from calendarserver.tools.principals import (
-    getProxies, setProxies
-)
 from calendarserver.tools.purge import (
     WorkerService, PurgeOldEventsService,
     DEFAULT_BATCH_SIZE, DEFAULT_RETAIN_DAYS,
     PrincipalPurgeWork
 )
 from calendarserver.tools.util import (
-    recordForPrincipalID, autoDisableMemcached
+    recordForPrincipalID, autoDisableMemcached,
+    getProxies, setProxies
 )
 from pycalendar.datetime import DateTime
 from twext.who.directory import DirectoryRecord

Modified: CalendarServer/trunk/calendarserver/tools/principals.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/principals.py	2016-07-07 18:53:32 UTC (rev 15754)
+++ CalendarServer/trunk/calendarserver/tools/principals.py	2016-07-07 20:38:32 UTC (rev 15755)
@@ -32,7 +32,7 @@
 
 from calendarserver.tools.cmdline import utilityMain, WorkerService
 from calendarserver.tools.util import (
-    recordForPrincipalID, prettyRecord
+    recordForPrincipalID, prettyRecord, action_addProxy, action_removeProxy
 )
 from twext.who.directory import DirectoryRecord
 from twext.who.idirectory import RecordType, InvalidDirectoryRecordError
@@ -40,8 +40,7 @@
 from twisted.internet.defer import inlineCallbacks, returnValue, succeed
 from twistedcaldav.config import config
 from twistedcaldav.cache import MemcacheChangeNotifier
-from txdav.who.delegates import Delegates, RecordType as DelegateRecordType, \
-    CachingDelegates
+from txdav.who.delegates import CachingDelegates
 from txdav.who.idirectory import AutoScheduleMode
 from txdav.who.groups import GroupCacherPollingWork
 
@@ -604,108 +603,11 @@
 
 
 
- at inlineCallbacks
-def _addRemoveProxy(msg, fn, store, record, proxyType, *proxyIDs):
-    directory = store.directoryService()
-    readWrite = (proxyType == "write")
-    for proxyID in proxyIDs:
-        proxyRecord = yield recordForPrincipalID(directory, proxyID)
-        if proxyRecord is None:
-            print("Invalid principal ID: %s" % (proxyID,))
-        else:
-            txn = store.newTransaction()
-            yield fn(txn, record, proxyRecord, readWrite)
-            yield txn.commit()
-            print(
-                "{msg} {proxy} as a {proxyType} proxy for {record}".format(
-                    msg=msg, proxy=prettyRecord(proxyRecord),
-                    proxyType=proxyType, record=prettyRecord(record)
-                )
-            )
 
 
 
- at inlineCallbacks
-def action_addProxy(store, record, proxyType, *proxyIDs):
-    if config.GroupCaching.Enabled and config.GroupCaching.UseDirectoryBasedDelegates:
-        if record.recordType in (
-            record.service.recordType.location,
-            record.service.recordType.resource,
-        ):
-            print("You are not allowed to add proxies for locations or resources via command line when their proxy assignments come from the directory service.")
-            returnValue(None)
 
-    yield _addRemoveProxy("Added", Delegates.addDelegate, store, record, proxyType, *proxyIDs)
-
-
-
 @inlineCallbacks
-def action_removeProxy(store, record, *proxyIDs):
-    if config.GroupCaching.Enabled and config.GroupCaching.UseDirectoryBasedDelegates:
-        if record.recordType in (
-            record.service.recordType.location,
-            record.service.recordType.resource,
-        ):
-            print("You are not allowed to remove proxies for locations or resources via command line when their proxy assignments come from the directory service.")
-            returnValue(None)
-
-    # Write
-    yield _addRemoveProxy("Removed", Delegates.removeDelegate, store, record, "write", *proxyIDs)
-    # Read
-    yield _addRemoveProxy("Removed", Delegates.removeDelegate, store, record, "read", *proxyIDs)
-
-
-
- at inlineCallbacks
-def setProxies(record, readProxyRecords, writeProxyRecords):
-    """
-    Set read/write proxies en masse for a record
-    @param record: L{IDirectoryRecord}
-    @param readProxyRecords: a list of records
-    @param writeProxyRecords: a list of records
-    """
-
-    proxyTypes = [
-        (DelegateRecordType.readDelegateGroup, readProxyRecords),
-        (DelegateRecordType.writeDelegateGroup, writeProxyRecords),
-    ]
-    for recordType, proxyRecords in proxyTypes:
-        if proxyRecords is None:
-            continue
-        proxyGroup = yield record.service.recordWithShortName(
-            recordType, record.uid
-        )
-        yield proxyGroup.setMembers(proxyRecords)
-
-
-
- at inlineCallbacks
-def getProxies(record):
-    """
-    Returns a tuple containing the records for read proxies and write proxies
-    of the given record
-    """
-
-    allProxies = {
-        DelegateRecordType.readDelegateGroup: [],
-        DelegateRecordType.writeDelegateGroup: [],
-    }
-    for recordType in allProxies.iterkeys():
-        proxyGroup = yield record.service.recordWithShortName(
-            recordType, record.uid
-        )
-        allProxies[recordType] = yield proxyGroup.members()
-
-    returnValue(
-        (
-            allProxies[DelegateRecordType.readDelegateGroup],
-            allProxies[DelegateRecordType.writeDelegateGroup]
-        )
-    )
-
-
-
- at inlineCallbacks
 def action_listGroupMembers(store, record):
     members = yield record.members()
     if members:
@@ -871,17 +773,10 @@
             )
         )
 
-        # Get original fields
-        newFields = record.fields.copy()
+        yield record.setAutoScheduleMode(autoScheduleMode)
 
-        # Set new values
-        newFields[record.service.fieldName.autoScheduleMode] = autoScheduleMode
 
-        updatedRecord = DirectoryRecord(record.service, newFields)
-        yield record.service.updateRecords([updatedRecord], create=False)
 
-
-
 @inlineCallbacks
 def action_setAutoAcceptGroup(store, record, autoAcceptGroup):
     if record.recordType == RecordType.group:

Modified: CalendarServer/trunk/calendarserver/tools/test/test_principals.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_principals.py	2016-07-07 18:53:32 UTC (rev 15754)
+++ CalendarServer/trunk/calendarserver/tools/test/test_principals.py	2016-07-07 20:38:32 UTC (rev 15755)
@@ -19,8 +19,11 @@
 from twistedcaldav.stdconfig import config
 from calendarserver.tools.principals import (
     parseCreationArgs, matchStrings,
-    recordForPrincipalID, getProxies, setProxies
+    recordForPrincipalID
 )
+from calendarserver.tools.util import (
+    getProxies, setProxies
+)
 from twext.python.filepath import CachingFilePath as FilePath
 from twisted.internet import reactor
 from twisted.internet.defer import inlineCallbacks, Deferred, returnValue

Modified: CalendarServer/trunk/calendarserver/tools/util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/util.py	2016-07-07 18:53:32 UTC (rev 15754)
+++ CalendarServer/trunk/calendarserver/tools/util.py	2016-07-07 20:38:32 UTC (rev 15755)
@@ -41,9 +41,6 @@
 from twext.python.log import Logger
 from twisted.internet.defer import inlineCallbacks, returnValue
 
-from txdav.xml import element as davxml
-
-
 from twistedcaldav import memcachepool
 from txdav.base.propertystore.base import PropertyName
 from txdav.xml import element
@@ -52,7 +49,9 @@
 from twext.who.idirectory import RecordType
 from txdav.who.idirectory import RecordType as CalRecordType
 
+from txdav.who.delegates import Delegates, RecordType as DelegateRecordType
 
+
 log = Logger()
 
 
@@ -343,129 +342,110 @@
     raise ValueError("Invalid principal identifier: %s" % (principalID,))
 
 
+ at inlineCallbacks
+def _addRemoveProxy(msg, fn, store, record, proxyType, *proxyIDs):
+    directory = store.directoryService()
+    readWrite = (proxyType == "write")
+    for proxyID in proxyIDs:
+        proxyRecord = yield recordForPrincipalID(directory, proxyID)
+        if proxyRecord is None:
+            print("Invalid principal ID: %s" % (proxyID,))
+        else:
+            txn = store.newTransaction()
+            yield fn(txn, record, proxyRecord, readWrite)
+            yield txn.commit()
+            print(
+                "{msg} {proxy} as a {proxyType} proxy for {record}".format(
+                    msg=msg, proxy=prettyRecord(proxyRecord),
+                    proxyType=proxyType, record=prettyRecord(record)
+                )
+            )
 
-def proxySubprincipal(principal, proxyType):
-    return principal.getChild("calendar-proxy-" + proxyType)
 
 
-
 @inlineCallbacks
-def action_addProxyPrincipal(rootResource, directory, store, principal, proxyType, proxyPrincipal):
-    try:
-        (yield addProxy(rootResource, directory, store, principal, proxyType, proxyPrincipal))
-        print("Added %s as a %s proxy for %s" % (
-            prettyPrincipal(proxyPrincipal), proxyType,
-            prettyPrincipal(principal)))
-    except ProxyError, e:
-        print("Error:", e)
-    except ProxyWarning, e:
-        print(e)
+def action_addProxy(store, record, proxyType, *proxyIDs):
+    if config.GroupCaching.Enabled and config.GroupCaching.UseDirectoryBasedDelegates:
+        if record.recordType in (
+            record.service.recordType.location,
+            record.service.recordType.resource,
+        ):
+            print("You are not allowed to add proxies for locations or resources via command line when their proxy assignments come from the directory service.")
+            returnValue(None)
 
+    yield _addRemoveProxy("Added", Delegates.addDelegate, store, record, proxyType, *proxyIDs)
 
 
+
 @inlineCallbacks
-def action_removeProxyPrincipal(rootResource, directory, store, principal, proxyPrincipal, **kwargs):
-    try:
-        removed = (yield removeProxy(
-            rootResource, directory, store,
-            principal, proxyPrincipal, **kwargs
-        ))
-        if removed:
-            print("Removed %s as a proxy for %s" % (
-                prettyPrincipal(proxyPrincipal),
-                prettyPrincipal(principal)))
-    except ProxyError, e:
-        print("Error:", e)
-    except ProxyWarning, e:
-        print(e)
+def action_removeProxy(store, record, *proxyIDs):
+    if config.GroupCaching.Enabled and config.GroupCaching.UseDirectoryBasedDelegates:
+        if record.recordType in (
+            record.service.recordType.location,
+            record.service.recordType.resource,
+        ):
+            print("You are not allowed to remove proxies for locations or resources via command line when their proxy assignments come from the directory service.")
+            returnValue(None)
 
+    # Write
+    yield _addRemoveProxy("Removed", Delegates.removeDelegate, store, record, "write", *proxyIDs)
+    # Read
+    yield _addRemoveProxy("Removed", Delegates.removeDelegate, store, record, "read", *proxyIDs)
 
 
 @inlineCallbacks
-def addProxy(rootResource, directory, store, principal, proxyType, proxyPrincipal):
-    proxyURL = proxyPrincipal.url()
+def setProxies(record, readProxyRecords, writeProxyRecords):
+    """
+    Set read/write proxies en masse for a record
+    @param record: L{IDirectoryRecord}
+    @param readProxyRecords: a list of records
+    @param writeProxyRecords: a list of records
+    """
 
-    subPrincipal = yield proxySubprincipal(principal, proxyType)
-    if subPrincipal is None:
-        raise ProxyError(
-            "Unable to edit %s proxies for %s\n" % (
-                proxyType,
-                prettyPrincipal(principal)
-            )
+    proxyTypes = [
+        (DelegateRecordType.readDelegateGroup, readProxyRecords),
+        (DelegateRecordType.writeDelegateGroup, writeProxyRecords),
+    ]
+    for recordType, proxyRecords in proxyTypes:
+        if proxyRecords is None:
+            continue
+        proxyGroup = yield record.service.recordWithShortName(
+            recordType, record.uid
         )
+        yield proxyGroup.setMembers(proxyRecords)
 
-    membersProperty = (yield subPrincipal.readProperty(davxml.GroupMemberSet, None))
 
-    for memberURL in membersProperty.children:
-        if str(memberURL) == proxyURL:
-            raise ProxyWarning("%s is already a %s proxy for %s" % (
-                prettyPrincipal(proxyPrincipal), proxyType,
-                prettyPrincipal(principal)))
 
-    else:
-        memberURLs = list(membersProperty.children)
-        memberURLs.append(davxml.HRef(proxyURL))
-        membersProperty = davxml.GroupMemberSet(*memberURLs)
-        (yield subPrincipal.writeProperty(membersProperty, None))
+ at inlineCallbacks
+def getProxies(record):
+    """
+    Returns a tuple containing the records for read proxies and write proxies
+    of the given record
+    """
 
-    proxyTypes = ["read", "write"]
-    proxyTypes.remove(proxyType)
+    allProxies = {
+        DelegateRecordType.readDelegateGroup: [],
+        DelegateRecordType.writeDelegateGroup: [],
+    }
+    for recordType in allProxies.iterkeys():
+        proxyGroup = yield record.service.recordWithShortName(
+            recordType, record.uid
+        )
+        allProxies[recordType] = yield proxyGroup.members()
 
-    yield action_removeProxyPrincipal(
-        rootResource, directory, store,
-        principal, proxyPrincipal, proxyTypes=proxyTypes
+    returnValue(
+        (
+            allProxies[DelegateRecordType.readDelegateGroup],
+            allProxies[DelegateRecordType.writeDelegateGroup]
+        )
     )
 
-    # Schedule work the PeerConnectionPool will pick up as overdue
-    def groupPollNow(txn):
-        from txdav.who.groups import GroupCacherPollingWork
-        return GroupCacherPollingWork.reschedule(txn, 0, force=True)
-    yield store.inTransaction("addProxy groupPollNow", groupPollNow)
 
+def proxySubprincipal(principal, proxyType):
+    return principal.getChild("calendar-proxy-" + proxyType)
 
 
- at inlineCallbacks
-def removeProxy(rootResource, directory, store, principal, proxyPrincipal, **kwargs):
-    removed = False
-    proxyTypes = kwargs.get("proxyTypes", ("read", "write"))
-    for proxyType in proxyTypes:
-        proxyURL = proxyPrincipal.url()
 
-        subPrincipal = yield proxySubprincipal(principal, proxyType)
-        if subPrincipal is None:
-            raise ProxyError(
-                "Unable to edit %s proxies for %s\n" % (
-                    proxyType,
-                    prettyPrincipal(principal)
-                )
-            )
-
-        membersProperty = (yield subPrincipal.readProperty(davxml.GroupMemberSet, None))
-
-        memberURLs = [
-            m for m in membersProperty.children
-            if str(m) != proxyURL
-        ]
-
-        if len(memberURLs) == len(membersProperty.children):
-            # No change
-            continue
-        else:
-            removed = True
-
-        membersProperty = davxml.GroupMemberSet(*memberURLs)
-        (yield subPrincipal.writeProperty(membersProperty, None))
-
-    if removed:
-        # Schedule work the PeerConnectionPool will pick up as overdue
-        def groupPollNow(txn):
-            from txdav.who.groups import GroupCacherPollingWork
-            return GroupCacherPollingWork.reschedule(txn, 0, force=True)
-        yield store.inTransaction("removeProxy groupPollNow", groupPollNow)
-    returnValue(removed)
-
-
-
 def prettyPrincipal(principal):
     return prettyRecord(principal.record)
 

Modified: CalendarServer/trunk/calendarserver/webadmin/delegation.py
===================================================================
--- CalendarServer/trunk/calendarserver/webadmin/delegation.py	2016-07-07 18:53:32 UTC (rev 15754)
+++ CalendarServer/trunk/calendarserver/webadmin/delegation.py	2016-07-07 20:38:32 UTC (rev 15755)
@@ -27,8 +27,8 @@
 import urlparse
 
 from calendarserver.tools.util import (
-    principalForPrincipalID, proxySubprincipal, action_addProxyPrincipal,
-    action_removeProxyPrincipal
+    recordForPrincipalID, proxySubprincipal, action_addProxy,
+    action_removeProxy, principalForPrincipalID
 )
 
 from twistedcaldav.config import config
@@ -49,6 +49,15 @@
 from twext.who.idirectory import RecordType
 from txdav.who.idirectory import RecordType as CalRecordType, AutoScheduleMode
 
+allowedAutoScheduleModes = {
+    "default": None,
+    "none": AutoScheduleMode.none,
+    "accept-always": AutoScheduleMode.accept,
+    "decline-always": AutoScheduleMode.decline,
+    "accept-if-free": AutoScheduleMode.acceptIfFree,
+    "decline-if-busy": AutoScheduleMode.declineIfBusy,
+    "automatic": AutoScheduleMode.acceptIfFreeDeclineIfBusy,
+}
 
 class WebAdminPage(Element):
     """
@@ -221,8 +230,8 @@
         self.principalResource = principalResource
         self.adminResource = adminResource
         self.proxySearch = proxySearch
-        record = principalResource.record
-        tag.fillSlots(resourceTitle=recordTitle(record),
+        self.record = principalResource.record
+        tag.fillSlots(resourceTitle=recordTitle(self.record),
                       resourceId=resourceId,
                       davPropertyName=davPropertyName,
                       proxySearch=proxySearch)
@@ -283,9 +292,9 @@
         Renderer which elides its tag for non-resource-type principals.
         """
         if (
-            self.principalResource.record.recordType.description != "user" and
-            self.principalResource.record.recordType.description != "group" or
-            self.principalResource.record.recordType.description == "user" and
+            self.record.recordType.description != "user" and
+            self.record.recordType.description != "group" or
+            self.record.recordType.description == "user" and
             config.Scheduling.Options.AutoSchedule.AllowUsers
         ):
             return tag
@@ -293,99 +302,91 @@
 
 
     @renderer
-    @inlineCallbacks
     def isAutoSchedule(self, request, tag):
         """
         Renderer which sets the 'selected' attribute on its tag if the resource
         is auto-schedule.
         """
-        if (yield self.principalResource.getAutoScheduleMode()) is not AutoScheduleMode.none:
+        if self.record.autoScheduleMode is not AutoScheduleMode.none:
             tag(selected='selected')
-        returnValue(tag)
+        return tag
 
 
     @renderer
-    @inlineCallbacks
     def isntAutoSchedule(self, request, tag):
         """
         Renderer which sets the 'selected' attribute on its tag if the resource
         is not auto-schedule.
         """
-        if (yield self.principalResource.getAutoScheduleMode()) is AutoScheduleMode.none:
+        if self.record.autoScheduleMode is AutoScheduleMode.none:
             tag(selected='selected')
-        returnValue(tag)
+        return tag
 
 
     @renderer
-    @inlineCallbacks
     def autoScheduleModeNone(self, request, tag):
         """
         Renderer which sets the 'selected' attribute on its tag based on the resource
         auto-schedule-mode.
         """
-        if (yield self.principalResource.getAutoScheduleMode()) is AutoScheduleMode.none:
+        if self.record.autoScheduleMode is AutoScheduleMode.none:
             tag(selected='selected')
-        returnValue(tag)
+        return tag
 
 
     @renderer
-    @inlineCallbacks
     def autoScheduleModeAcceptAlways(self, request, tag):
         """
         Renderer which sets the 'selected' attribute on its tag based on the resource
         auto-schedule-mode.
         """
-        if (yield self.principalResource.getAutoScheduleMode()) is AutoScheduleMode.accept:
+        if self.record.autoScheduleMode is AutoScheduleMode.accept:
             tag(selected='selected')
-        returnValue(tag)
+        return tag
 
 
     @renderer
-    @inlineCallbacks
     def autoScheduleModeDeclineAlways(self, request, tag):
         """
         Renderer which sets the 'selected' attribute on its tag based on the resource
         auto-schedule-mode.
         """
-        if (yield self.principalResource.getAutoScheduleMode()) is AutoScheduleMode.decline:
+        if self.record.autoScheduleMode is AutoScheduleMode.decline:
             tag(selected='selected')
-        returnValue(tag)
+        return tag
 
 
     @renderer
-    @inlineCallbacks
     def autoScheduleModeAcceptIfFree(self, request, tag):
         """
         Renderer which sets the 'selected' attribute on its tag based on the resource
         auto-schedule-mode.
         """
-        if (yield self.principalResource.getAutoScheduleMode()) is AutoScheduleMode.acceptIfFree:
+        if self.record.autoScheduleMode is AutoScheduleMode.acceptIfFree:
             tag(selected='selected')
-        returnValue(tag)
+        return tag
 
 
     @renderer
-    @inlineCallbacks
     def autoScheduleModeDeclineIfBusy(self, request, tag):
         """
         Renderer which sets the 'selected' attribute on its tag based on the resource
         auto-schedule-mode.
         """
-        if (yield self.principalResource.getAutoScheduleMode()) is AutoScheduleMode.declineIfBusy:
+        if self.record.autoScheduleMode is AutoScheduleMode.declineIfBusy:
             tag(selected='selected')
-        returnValue(tag)
+        return tag
 
 
     @renderer
-    @inlineCallbacks
     def autoScheduleModeAutomatic(self, request, tag):
         """
         Renderer which sets the 'selected' attribute on its tag based on the resource
         auto-schedule-mode.
         """
-        if (yield self.principalResource.getAutoScheduleMode()) is AutoScheduleMode.acceptIfFreeDeclineIfBusy:
+        if self.record.autoScheduleMode is AutoScheduleMode.acceptIfFreeDeclineIfBusy:
             tag(selected='selected')
-        returnValue(tag)
+        return tag
 
     _matrix = None
 
@@ -634,9 +635,9 @@
 
 
     @inlineCallbacks
-    def resourceActions(self, request, principal):
+    def resourceActions(self, request, record):
         """
-        Take all actions on the given principal based on the given request.
+        Take all actions on the given record based on the given request.
         """
 
         def queryValue(arg):
@@ -651,45 +652,32 @@
                     matches.append(key[len(arg):])
             return matches
 
-        autoSchedule = queryValue("autoSchedule")
         autoScheduleMode = queryValue("autoScheduleMode")
         makeReadProxies = queryValues("mkReadProxy|")
         makeWriteProxies = queryValues("mkWriteProxy|")
         removeProxies = queryValues("rmProxy|")
 
-        # Update the auto-schedule value if specified.
-        if autoSchedule is not None and (autoSchedule == "true" or
-                                         autoSchedule == "false"):
+        # Update the auto-schedule-mode value if specified.
+        if autoScheduleMode:
             if (
-                principal.record.recordType != RecordType.user and
-                principal.record.recordType != RecordType.group or
-                principal.record.recordType == RecordType.user and
+                record.recordType != RecordType.user and
+                record.recordType != RecordType.group or
+                record.recordType == RecordType.user and
                 config.Scheduling.Options.AutoSchedule.AllowUsers
             ):
-                (yield principal.setAutoSchedule(autoSchedule == "true"))
-                (yield principal.setAutoScheduleMode(autoScheduleMode))
+                autoScheduleMode = allowedAutoScheduleModes[autoScheduleMode]
+                yield record.setAutoScheduleMode(autoScheduleMode)
+                record.autoScheduleMode = autoScheduleMode
 
         # Update the proxies if specified.
-        for proxyId in removeProxies:
-            proxy = yield self.getResourceById(request, proxyId)
-            yield action_removeProxyPrincipal(
-                self.root, self.directory, self.store,
-                principal, proxy, proxyTypes=["read", "write"]
-            )
+        if removeProxies:
+            yield action_removeProxy(self.store, record, *removeProxies)
 
-        for proxyId in makeReadProxies:
-            proxy = yield self.getResourceById(request, proxyId)
-            yield action_addProxyPrincipal(
-                self.root, self.directory, self.store,
-                principal, "read", proxy
-            )
+        if makeReadProxies:
+            yield action_addProxy(self.store, record, "read", *makeReadProxies)
 
-        for proxyId in makeWriteProxies:
-            proxy = yield self.getResourceById(request, proxyId)
-            yield action_addProxyPrincipal(
-                self.root, self.directory, self.store,
-                principal, "write", proxy
-            )
+        if makeWriteProxies:
+            yield action_addProxy(self.store, record, "write", *makeWriteProxies)
 
 
     @inlineCallbacks
@@ -700,8 +688,8 @@
         """
         resourceId = request.args.get('resourceId', [''])[0]
         if resourceId:
-            principal = yield self.getResourceById(request, resourceId)
-            yield self.resourceActions(request, principal)
+            record = yield recordForPrincipalID(self.directory, resourceId)
+            yield self.resourceActions(request, record)
         htmlContent = yield flattenString(request, WebAdminPage(self))
         response = Response()
         response.stream = MemoryStream(htmlContent)

Modified: CalendarServer/trunk/txdav/caldav/icalendardirectoryservice.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/icalendardirectoryservice.py	2016-07-07 18:53:32 UTC (rev 15754)
+++ CalendarServer/trunk/txdav/caldav/icalendardirectoryservice.py	2016-07-07 20:38:32 UTC (rev 15755)
@@ -106,6 +106,15 @@
         @rtype: C{bool}
         """
 
+    def setAutoScheduleMode(autoScheduleMode): #@NoSelf
+        """
+        Sets the mode of automatic scheduling used for this record.
+
+        @param autoScheduleMode: the new mode
+        @type autoScheduleMode: L{AutoScheduleMode}
+        """
+
+
     def isProxyFor(other): #@NoSelf
         """
         Test whether the record is a calendar user proxy for the specified record.

Modified: CalendarServer/trunk/txdav/dps/client.py
===================================================================
--- CalendarServer/trunk/txdav/dps/client.py	2016-07-07 18:53:32 UTC (rev 15754)
+++ CalendarServer/trunk/txdav/dps/client.py	2016-07-07 20:38:32 UTC (rev 15755)
@@ -44,7 +44,8 @@
     WikiAccessForUIDCommand, ContinuationCommand,
     StatsCommand, ExternalDelegatesCommand, ExpandedMemberUIDsCommand,
     AddMembersCommand, RemoveMembersCommand,
-    UpdateRecordsCommand, ExpandedMembersCommand, FlushCommand
+    UpdateRecordsCommand, ExpandedMembersCommand, FlushCommand,
+    SetAutoScheduleModeCommand
 )
 from txdav.who.delegates import RecordType as DelegatesRecordType
 from txdav.who.directory import (
@@ -422,6 +423,14 @@
         )
 
 
+    def setAutoScheduleMode(self, record, autoScheduleMode):
+        return self._sendCommand(
+            SetAutoScheduleModeCommand,
+            uid=record.uid.encode("utf-8"),
+            autoScheduleMode=autoScheduleMode.name,
+        )
+
+
     @inlineCallbacks
     def flush(self):
         try:

Modified: CalendarServer/trunk/txdav/dps/commands.py
===================================================================
--- CalendarServer/trunk/txdav/dps/commands.py	2016-07-07 18:53:32 UTC (rev 15754)
+++ CalendarServer/trunk/txdav/dps/commands.py	2016-07-07 20:38:32 UTC (rev 15755)
@@ -265,7 +265,16 @@
     ]
 
 
+class SetAutoScheduleModeCommand(amp.Command):
+    arguments = [
+        ('uid', amp.String()),
+        ('autoScheduleMode', amp.String()),
+    ]
+    response = [
+        ('success', amp.Boolean()),
+    ]
 
+
 class FlushCommand(amp.Command):
     arguments = []
     response = [

Modified: CalendarServer/trunk/txdav/dps/server.py
===================================================================
--- CalendarServer/trunk/txdav/dps/server.py	2016-07-07 18:53:32 UTC (rev 15754)
+++ CalendarServer/trunk/txdav/dps/server.py	2016-07-07 20:38:32 UTC (rev 15755)
@@ -45,8 +45,10 @@
     WikiAccessForUIDCommand, ContinuationCommand,
     ExternalDelegatesCommand, StatsCommand, ExpandedMemberUIDsCommand,
     AddMembersCommand, RemoveMembersCommand,
-    UpdateRecordsCommand, FlushCommand,  # RemoveRecordsCommand,
+    UpdateRecordsCommand, FlushCommand, SetAutoScheduleModeCommand,
+    # RemoveRecordsCommand,
 )
+from txdav.who.idirectory import AutoScheduleMode
 from txdav.who.wiki import WikiAccessLevel
 
 from zope.interface import implementer
@@ -540,6 +542,21 @@
         returnValue(response)
 
 
+    @SetAutoScheduleModeCommand.responder
+    @inlineCallbacks
+    def setAutoScheduleMode(self, uid, autoScheduleMode):
+        uid = uid.decode("utf-8")
+        record = yield self._directory.recordWithUID(uid)
+        autoScheduleMode = autoScheduleMode.decode("utf-8")
+        autoScheduleMode = AutoScheduleMode.lookupByName(autoScheduleMode)
+        yield self._directory.setAutoScheduleMode(record, autoScheduleMode)
+        response = {
+            "success": True
+        }
+        returnValue(response)
+
+
+
     @GroupsCommand.responder
     @inlineCallbacks
     def groups(self, uid):

Modified: CalendarServer/trunk/txdav/dps/test/test_client.py
===================================================================
--- CalendarServer/trunk/txdav/dps/test/test_client.py	2016-07-07 18:53:32 UTC (rev 15754)
+++ CalendarServer/trunk/txdav/dps/test/test_client.py	2016-07-07 20:38:32 UTC (rev 15755)
@@ -36,6 +36,7 @@
 from txdav.who.test.support import (
     TestRecord, CalendarInMemoryDirectoryService
 )
+from txdav.who.idirectory import AutoScheduleMode
 
 
 testMode = "xml"  # "xml" or "od"
@@ -442,6 +443,22 @@
 
 
     @inlineCallbacks
+    def test_setAutoScheduleMode(self):
+        """
+        Verify setAutoSchedule works across DPS
+        """
+        record = yield self.client.recordWithUID(u"75EA36BE-F71B-40F9-81F9-CF59BF40CA8F")
+        # Defaults to automatic
+        self.assertEquals(record.autoScheduleMode, AutoScheduleMode.acceptIfFreeDeclineIfBusy)
+        # Change it to accept-if-busy
+        yield record.setAutoScheduleMode(AutoScheduleMode.acceptIfFree)
+        # Refetch it
+        record = yield self.client.recordWithUID(u"75EA36BE-F71B-40F9-81F9-CF59BF40CA8F")
+        # Verify it's changed
+        self.assertEquals(record.autoScheduleMode, AutoScheduleMode.acceptIfFree)
+
+
+    @inlineCallbacks
     def test_uid(self):
         record = (yield self.client.recordWithUID(self.wsanchezUID))
         self.assertTrue(u"wsanchez" in record.shortNames)

Modified: CalendarServer/trunk/txdav/who/augment.py
===================================================================
--- CalendarServer/trunk/txdav/who/augment.py	2016-07-07 18:53:32 UTC (rev 15754)
+++ CalendarServer/trunk/txdav/who/augment.py	2016-07-07 20:38:32 UTC (rev 15755)
@@ -471,7 +471,27 @@
         returnValue(augmentedRecord)
 
 
+    @inlineCallbacks
+    def setAutoScheduleMode(self, record, autoScheduleMode):
+        augmentRecord = yield self._augmentDB.getAugmentRecord(
+            record.uid,
+            self.recordTypeToOldName(record.recordType)
+        )
+        if augmentRecord is not None:
+            autoScheduleMode = {
+                AutoScheduleMode.none: "none",
+                AutoScheduleMode.accept: "accept-always",
+                AutoScheduleMode.decline: "decline-always",
+                AutoScheduleMode.acceptIfFree: "accept-if-free",
+                AutoScheduleMode.declineIfBusy: "decline-if-busy",
+                AutoScheduleMode.acceptIfFreeDeclineIfBusy: "automatic",
+            }.get(autoScheduleMode)
 
+            augmentRecord.autoScheduleMode = autoScheduleMode
+            yield self._augmentDB.addAugmentRecords([augmentRecord])
+
+
+
 class AugmentedDirectoryRecord(DirectoryRecord, CalendarDirectoryRecordMixin):
     """
     Augmented directory record.

Modified: CalendarServer/trunk/txdav/who/directory.py
===================================================================
--- CalendarServer/trunk/txdav/who/directory.py	2016-07-07 18:53:32 UTC (rev 15754)
+++ CalendarServer/trunk/txdav/who/directory.py	2016-07-07 20:38:32 UTC (rev 15755)
@@ -607,6 +607,10 @@
         returnValue(autoScheduleMode)
 
 
+    def setAutoScheduleMode(self, autoScheduleMode):
+        return self.service.setAutoScheduleMode(self, autoScheduleMode)
+
+
     @inlineCallbacks
     def autoAcceptFromOrganizer(self, organizer):
         try:

Modified: CalendarServer/trunk/txdav/who/test/test_directory.py
===================================================================
--- CalendarServer/trunk/txdav/who/test/test_directory.py	2016-07-07 18:53:32 UTC (rev 15754)
+++ CalendarServer/trunk/txdav/who/test/test_directory.py	2016-07-07 20:38:32 UTC (rev 15755)
@@ -358,7 +358,22 @@
             )
 
 
+    @inlineCallbacks
+    def test_setAutoScheduleMode(self):
+        """
+        Verify the record.setAutoScheduleMode( ) method
+        """
+        orion = yield self.directory.recordWithUID(u"orion")
+        # Defaults to automatic
+        self.assertEquals(orion.autoScheduleMode, AutoScheduleMode.acceptIfFreeDeclineIfBusy)
+        # Change it to decline-if-busy
+        yield orion.setAutoScheduleMode(AutoScheduleMode.declineIfBusy)
+        # Refetch it
+        orion = yield self.directory.recordWithUID(u"orion")
+        # Verify it's changed
+        self.assertEquals(orion.autoScheduleMode, AutoScheduleMode.declineIfBusy)
 
+
 class DirectoryTestCaseFakeEmail(StoreTestCase):
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20160707/7fa8c3f5/attachment-0001.html>


More information about the calendarserver-changes mailing list