Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Allow a default augment record to be set.

  • Loading branch information
cyrusdaboo committed Oct 13, 2009
1 parent dfcb633 commit a17ff42eff5c5a2458e2006dec7059987c67addf
@@ -20,27 +20,10 @@ limitations under the License.

<augments>
<record>
<guid>admin</guid>
<guid>Default</guid>
<enable>true</enable>
<enable-calendar>true</enable-calendar>
</record>
<record>
<guid>apprentice</guid>
<enable>true</enable>
<enable-calendar>true</enable-calendar>
</record>
<record repeat="99">
<guid>user%02d</guid>
<enable>true</enable>
<enable-calendar>true</enable-calendar>
<cuaddr>mailto:user%02d@example.com</cuaddr>
</record>
<record repeat="10">
<guid>public%02d</guid>
<enable>true</enable>
<enable-calendar>true</enable-calendar>
<cuaddr>mailto:public%02d@example.com</cuaddr>
</record>
<record repeat="10">
<guid>location%02d</guid>
<enable>true</enable>
@@ -19,6 +19,7 @@
from twistedcaldav.database import AbstractADBAPIDatabase, ADBAPISqliteMixin,\
ADBAPIPostgreSQLMixin
from twistedcaldav.directory.xmlaugmentsparser import XMLAugmentsParser
import copy
import time

from twistedcaldav.log import Logger
@@ -54,7 +55,27 @@ class AugmentDB(object):
def __init__(self):
pass

@inlineCallbacks
def getAugmentRecord(self, guid):
"""
Get an AugmentRecord for the specified GUID or the default.
@param guid: directory GUID to lookup
@type guid: C{str}
@return: L{Deferred}
"""

result = (yield self._lookupAugmentRecord(guid))
if result is None:
if not hasattr(self, "_defaultRecord"):
self._defaultRecord = (yield self._lookupAugmentRecord("Default"))
if self._defaultRecord is not None:
result = copy.deepcopy(self._defaultRecord)
result.guid = guid
returnValue(result)

def _lookupAugmentRecord(self, guid):
"""
Get an AugmentRecord for the specified GUID.
@@ -95,7 +116,7 @@ def __init__(self, xmlFiles, cacheTimeout=30):

self.lastCached = time.time()

def getAugmentRecord(self, guid):
def _lookupAugmentRecord(self, guid):
"""
Get an AugmentRecord for the specified GUID.
@@ -148,7 +169,7 @@ def __init__(self, dbID, dbapiName, dbapiArgs, **kwargs):
AbstractADBAPIDatabase.__init__(self, dbID, dbapiName, dbapiArgs, True, **kwargs)

@inlineCallbacks
def getAugmentRecord(self, guid):
def _lookupAugmentRecord(self, guid):
"""
Get an AugmentRecord for the specified GUID.
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
Copyright (c) 2009 Apple Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<!DOCTYPE accounts SYSTEM "../../../conf/auth/augments.dtd">

<augments>
<record>
<guid>Default</guid>
<enable>true</enable>
<enable-calendar>true</enable-calendar>
<hosted-at>00001</hosted-at>
</record>
<record>
<guid>D11F03A0-97EA-48AF-9A6C-FAC7F3975766</guid>
<enable>true</enable>
</record>
<record>
<guid>6423F94A-6B76-4A3A-815B-D52CFD77935D</guid>
<enable>true</enable>
<enable-calendar>true</enable-calendar>
<cuaddr>mailto:wsanchez@example.com</cuaddr>
</record>
<record>
<guid>5A985493-EE2C-4665-94CF-4DFEA3A89500</guid>
<enable>false</enable>
</record>
<record>
<guid>8B4288F6-CC82-491D-8EF9-642EF4F3E7D0</guid>
<enable>true</enable>
<enable-calendar>false</enable-calendar>
</record>
<record>
<guid>5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1</guid>
<enable>true</enable>
<hosted-at>00001</hosted-at>
</record>
<record>
<guid>543D28BA-F74F-4D5F-9243-B3E3A61171E5</guid>
<enable>true</enable>
<hosted-at>00002</hosted-at>
</record>
<record>
<guid>6A73326A-F781-47E7-A9F8-AF47364D4152</guid>
<enable>true</enable>
<hosted-at>00002</hosted-at>
<enable>true</enable>
<enable-calendar>true</enable-calendar>
<auto-schedule>true</auto-schedule>
<cuaddr>mailto:usera@example.com</cuaddr>
<cuaddr>mailto:user.a@example.com</cuaddr>
<cuaddr>mailto:user_a@example.com</cuaddr>
</record>
</augments>
@@ -23,6 +23,7 @@
import os

xmlFile = os.path.join(os.path.dirname(__file__), "augments-test.xml")
xmlFileDefault = os.path.join(os.path.dirname(__file__), "augments-test-default.xml")

testRecords = (
{"guid":"D11F03A0-97EA-48AF-9A6C-FAC7F3975766", "enabled":True, "hostedAt":"", "enabledForCalendaring":False, "autoSchedule":False, "calendarUserAddresses":set()},
@@ -34,6 +35,8 @@
{"guid":"6A73326A-F781-47E7-A9F8-AF47364D4152", "enabled":True, "hostedAt":"00002", "enabledForCalendaring":True, "autoSchedule":True, "calendarUserAddresses":set(("mailto:usera@example.com", "mailto:user.a@example.com", "mailto:user_a@example.com",))},
)

testRecordDefault = {"guid":"A4318887-F2C7-4A70-9056-B88CC8DB26F1", "enabled":True, "hostedAt":"00001", "enabledForCalendaring":True, "autoSchedule":False, "calendarUserAddresses":set()}

class AugmentTests(TestCase):

@inlineCallbacks
@@ -63,6 +66,16 @@ def test_read(self):

yield self._checkNoRecord(db, "D11F03A0-97EA-48AF-9A6C-FAC7F3975767")

@inlineCallbacks
def test_read_default(self):

db = AugmentXMLDB((xmlFileDefault,))

for item in testRecords:
yield self._checkRecord(db, item)

yield self._checkRecord(db, testRecordDefault)

def test_parseErrors(self):

db = {}
@@ -108,6 +121,20 @@ def test_read(self):

yield self._checkNoRecord(db, "D11F03A0-97EA-48AF-9A6C-FAC7F3975767")

@inlineCallbacks
def test_read_default(self):

db = AugmentSqliteDB(self.mktemp())

dbxml = AugmentXMLDB((xmlFileDefault,))
for record in dbxml.db.values():
yield db.addAugmentRecord(record)

for item in testRecords:
yield self._checkRecord(db, item)

yield self._checkRecord(db, testRecordDefault)

class AugmentPostgreSQLTests(AugmentTests):

@inlineCallbacks
@@ -125,6 +152,21 @@ def test_read(self):

yield self._checkNoRecord(db, "D11F03A0-97EA-48AF-9A6C-FAC7F3975767")

@inlineCallbacks
def test_read_default(self):

db = AugmentPostgreSQLDB("localhost", "augments")
yield db.clean()

dbxml = AugmentXMLDB((xmlFileDefault,))
for record in dbxml.db.values():
yield db.addAugmentRecord(record)

for item in testRecords:
yield self._checkRecord(db, item)

yield self._checkRecord(db, testRecordDefault)

try:
import pgdb
except ImportError:
@@ -303,7 +303,7 @@ def changed(self):
oldCacheNotifier = DirectoryPrincipalResource.cacheNotifierFactory

try:
DirectoryPrincipalResource.cacheNotifierFactory = (lambda _1, _2: notifier)
DirectoryPrincipalResource.cacheNotifierFactory = (lambda _1, _2, **kwargs: notifier)

self.assertEquals(notifier.changedCount, 0)

@@ -411,4 +411,6 @@ def _installPool(name, handleTypes, serverAddress, maxClients=5, reactor=None):
_memCachePoolHandler[handle] = pool

def defaultCachePool(name):
if name not in _memCachePoolHandler:
name = "Default"
return _memCachePoolHandler[name]

0 comments on commit a17ff42

Please sign in to comment.
You can’t perform that action at this time.