[CalendarServer-changes] [12983] CalendarServer/branches/users/sagen/move2who-4

source_changes at macosforge.org source_changes at macosforge.org
Thu Mar 20 18:02:47 PDT 2014


Revision: 12983
          http://trac.calendarserver.org//changeset/12983
Author:   sagen at apple.com
Date:     2014-03-20 18:02:47 -0700 (Thu, 20 Mar 2014)
Log Message:
-----------
csmp supports structured location info

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/principals.py
    CalendarServer/branches/users/sagen/move2who-4/txdav/dps/client.py
    CalendarServer/branches/users/sagen/move2who-4/txdav/who/augment.py
    CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py
    CalendarServer/branches/users/sagen/move2who-4/txdav/who/idirectory.py
    CalendarServer/branches/users/sagen/move2who-4/txdav/who/util.py
    CalendarServer/branches/users/sagen/move2who-4/txdav/who/xml.py

Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/principals.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/principals.py	2014-03-20 03:28:55 UTC (rev 12982)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/principals.py	2014-03-21 01:02:47 UTC (rev 12983)
@@ -258,23 +258,23 @@
         elif opt in ("", "--get-auto-accept-group"):
             principalActions.append((action_getAutoAcceptGroup,))
 
-        # elif opt in ("", "--set-geo"):
-        #     principalActions.append((action_setValue, "Geo", arg))
+        elif opt in ("", "--set-geo"):
+            principalActions.append((action_setValue, u"geographicLocation", arg))
 
-        # elif opt in ("", "--get-geo"):
-        #     principalActions.append((action_getValue, "Geo"))
+        elif opt in ("", "--get-geo"):
+            principalActions.append((action_getValue, u"geographicLocation"))
 
-        # elif opt in ("", "--set-street-address"):
-        #     principalActions.append((action_setValue, "StreetAddress", arg))
+        elif opt in ("", "--set-street-address"):
+            principalActions.append((action_setValue, u"streetAddress", arg))
 
-        # elif opt in ("", "--get-street-address"):
-        #     principalActions.append((action_getValue, "StreetAddress"))
+        elif opt in ("", "--get-street-address"):
+            principalActions.append((action_getValue, u"streetAddress"))
 
-        # elif opt in ("", "--set-address"):
-        #     principalActions.append((action_setValue, "AssociatedAddress", arg))
+        elif opt in ("", "--set-address"):
+            principalActions.append((action_setValue, u"associatedAddress", arg))
 
-        # elif opt in ("", "--get-address"):
-        #     principalActions.append((action_getValue, "AssociatedAddress"))
+        elif opt in ("", "--get-address"):
+            principalActions.append((action_getValue, u"associatedAddress"))
 
         else:
             raise NotImplementedError(opt)
@@ -732,6 +732,39 @@
         )
 
 
+ at inlineCallbacks
+def action_setValue(store, record, name, value):
+    print(
+        "Setting {name} to {value} for {record}".format(
+            name=name, value=value, record=prettyRecord(record),
+        )
+    )
+    # Get original fields
+    newFields = record.fields.copy()
+
+    # Set new value
+    newFields[record.service.fieldName.lookupByName(name)] = value
+
+    updatedRecord = DirectoryRecord(record.service, newFields)
+    yield record.service.updateRecords([updatedRecord], create=False)
+
+
+def action_getValue(store, record, name):
+    try:
+        value = record.fields[record.service.fieldName.lookupByName(name)]
+        print(
+            "{name} for {record} is {value}".format(
+                name=name, record=prettyRecord(record), value=value
+            )
+        )
+    except KeyError:
+        print(
+            "{name} is not set for {record}".format(
+                name=name, record=prettyRecord(record),
+            )
+        )
+
+
 def abort(msg, status=1):
     sys.stdout.write("%s\n" % (msg,))
     try:

Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/dps/client.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/dps/client.py	2014-03-20 03:28:55 UTC (rev 12982)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/dps/client.py	2014-03-21 01:02:47 UTC (rev 12983)
@@ -41,6 +41,7 @@
 from txdav.who.directory import (
     CalendarDirectoryRecordMixin, CalendarDirectoryServiceMixin
 )
+import txdav.who.augment
 import txdav.who.delegates
 import txdav.who.idirectory
 from zope.interface import implementer
@@ -79,7 +80,8 @@
 
     fieldName = ConstantsContainer(
         (twext.who.idirectory.FieldName,
-         txdav.who.idirectory.FieldName)
+         txdav.who.idirectory.FieldName,
+         txdav.who.augment.FieldName)
     )
 
 

Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/augment.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/augment.py	2014-03-20 03:28:55 UTC (rev 12982)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/augment.py	2014-03-21 01:02:47 UTC (rev 12983)
@@ -26,19 +26,22 @@
 from zope.interface import implementer
 
 from twisted.internet.defer import inlineCallbacks, returnValue
-
 from twistedcaldav.directory.augment import AugmentRecord
 from twext.python.log import Logger
 from twext.who.directory import DirectoryRecord
 from twext.who.directory import DirectoryService as BaseDirectoryService
-from twext.who.idirectory import IDirectoryService, RecordType
+from twext.who.idirectory import (
+    IDirectoryService, RecordType, FieldName as BaseFieldName
+)
 from twext.who.util import ConstantsContainer
 
 from txdav.common.idirectoryservice import IStoreDirectoryService
 from txdav.who.directory import (
-    CalendarDirectoryRecordMixin, CalendarDirectoryServiceMixin
+    CalendarDirectoryRecordMixin, CalendarDirectoryServiceMixin,
 )
-from txdav.who.idirectory import AutoScheduleMode, FieldName
+from txdav.who.idirectory import (
+    AutoScheduleMode, FieldName
+)
 
 log = Logger()
 
@@ -56,7 +59,7 @@
     """
 
     fieldName = ConstantsContainer((
-        BaseDirectoryService.fieldName,
+        BaseFieldName,
         FieldName,
     ))
 

Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py	2014-03-20 03:28:55 UTC (rev 12982)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py	2014-03-21 01:02:47 UTC (rev 12983)
@@ -181,9 +181,10 @@
         "writeDelegatorGroup": "writeDelegatorGroups",
     }
 
-    # FIXME: Existing code assumes record type names are plural. Is there any
-    # reason to maintain backwards compatibility?  I suppose there could be
-    # scripts referring to record type of "users", "locations"
+
+    # Maps record types <--> url path segments, i.e. the segment after
+    # /principals/ e.g. "users" or "groups"
+
     def recordTypeToOldName(self, recordType):
         return self._oldRecordTypeNames[recordType.name]
 
@@ -201,9 +202,6 @@
     @inlineCallbacks
     def verifyCredentials(self, credentials):
 
-        # XYZZY REMOVE THIS, it bypasses all authentication!:
-        # returnValue(True)
-
         if isinstance(credentials, UsernamePassword):
             log.debug("UsernamePassword")
             returnValue(

Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/idirectory.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/idirectory.py	2014-03-20 03:28:55 UTC (rev 12982)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/idirectory.py	2014-03-21 01:02:47 UTC (rev 12983)
@@ -155,3 +155,26 @@
     autoAcceptGroup = NamedConstant()
     autoAcceptGroup.description = u"auto-accept group"
     autoAcceptGroup.valueType = BaseFieldName.valueType(BaseFieldName.uid)
+
+    # For "locations", i.e., scheduled spaces:
+
+    associatedAddress = NamedConstant()
+    associatedAddress.description = u"associated address UID"
+
+    capacity = NamedConstant()
+    capacity.description = u"room capacity"
+    capacity.valueType = int
+
+    floor = NamedConstant()
+    floor.description = u"building floor"
+
+    # For "addresses", i.e., non-scheduled areas containing locations:
+
+    abbreviatedName = NamedConstant()
+    abbreviatedName.description = u"abbreviated name"
+
+    geographicLocation = NamedConstant()
+    geographicLocation.description = u"geographic location URI"
+
+    streetAddress = NamedConstant()
+    streetAddress.description = u"street address"

Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/util.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/util.py	2014-03-20 03:28:55 UTC (rev 12982)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/util.py	2014-03-21 01:02:47 UTC (rev 12983)
@@ -22,16 +22,22 @@
 from txdav.who.augment import AugmentedDirectoryService
 
 from calendarserver.tap.util import getDBPool, storeFromConfig
-from twext.who.idirectory import RecordType, DirectoryConfigurationError
+from twext.who.idirectory import (
+    RecordType, DirectoryConfigurationError, FieldName
+)
 from twext.who.ldap import DirectoryService as LDAPDirectoryService
 from twext.who.util import ConstantsContainer
 from twisted.python.filepath import FilePath
 from twisted.python.reflect import namedClass
 from twistedcaldav.config import fullServerPath
 from txdav.who.delegates import DirectoryService as DelegateDirectoryService
-from txdav.who.idirectory import RecordType as CalRecordType
+from txdav.who.idirectory import (
+    RecordType as CalRecordType,
+    FieldName as CalFieldName
+)
 from txdav.who.xml import DirectoryService as XMLDirectoryService
 
+
 log = Logger()
 
 
@@ -61,6 +67,9 @@
         directoryType = serviceValue.type.lower()
         params = serviceValue.params
 
+        # TODO: add a "test" directory service that produces test records
+        # from code -- no files needed.
+
         if "xml" in directoryType:
             xmlFile = params.xmlFile
             xmlFile = fullServerPath(config.DataRoot, xmlFile)
@@ -115,6 +124,7 @@
             types.append(recordType)
 
         directory.recordType = ConstantsContainer(types)
+        directory.fieldName = ConstantsContainer((FieldName, CalFieldName))
         aggregatedServices.append(directory)
 
     #

Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/xml.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/xml.py	2014-03-20 03:28:55 UTC (rev 12982)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/xml.py	2014-03-21 01:02:47 UTC (rev 12983)
@@ -105,8 +105,30 @@
         AutoScheduleMode.acceptIfFreeDeclineIfBusy
     )
 
+    # For "locations", i.e., scheduled spaces:
 
+    capacity = ValueConstant(u"capacity")
+    capacity.fieldName = FieldName.capacity
 
+    floor = ValueConstant(u"floor")
+    floor.fieldName = FieldName.floor
+
+    associatedAddress = ValueConstant(u"associatedAddress")
+    associatedAddress.fieldName = FieldName.associatedAddress
+
+    # For "addresses", i.e., non-scheduled areas containing locations:
+
+    abbreviatedName = ValueConstant(u"abbreviatedName")
+    abbreviatedName.fieldName = FieldName.abbreviatedName
+
+    streetAddress = ValueConstant(u"streetAddress")
+    streetAddress.fieldName = FieldName.streetAddress
+
+    geographicLocation = ValueConstant(u"geographicLocation")
+    geographicLocation.fieldName = FieldName.geographicLocation
+
+
+
 class Attribute(Values):
     """
     XML calendar and contacts attribute names.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140320/6cc82584/attachment-0001.html>


More information about the calendarserver-changes mailing list