<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[12995] CalendarServer/branches/users/sagen/move2who-4/twistedcaldav</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/12995">12995</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-03-25 16:19:18 -0700 (Tue, 25 Mar 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Delegate assignments are loaded from XML to sqlite to store</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorycalendaruserproxyloaderpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/calendaruserproxyloader.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytestresourcesxml">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/resources.xml</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_upgradepy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_upgrade.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavtestutilpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/util.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavupgradepy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/upgrade.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorycalendaruserproxyloaderpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/calendaruserproxyloader.py (12994 => 12995)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/calendaruserproxyloader.py        2014-03-25 21:34:44 UTC (rev 12994)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/calendaruserproxyloader.py        2014-03-25 23:19:18 UTC (rev 12995)
</span><span class="lines">@@ -29,7 +29,6 @@
</span><span class="cx"> from twext.python.log import Logger
</span><span class="cx">
</span><span class="cx"> from twistedcaldav.config import config, fullServerPath
</span><del>-from twistedcaldav.directory import calendaruserproxy
</del><span class="cx"> from twistedcaldav.xmlutil import readXML
</span><span class="cx">
</span><span class="cx"> log = Logger()
</span><span class="lines">@@ -44,6 +43,7 @@
</span><span class="cx">
</span><span class="cx"> ATTRIBUTE_REPEAT = "repeat"
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> class XMLCalendarUserProxyLoader(object):
</span><span class="cx"> """
</span><span class="cx"> XML calendar user proxy configuration file parser and loader.
</span><span class="lines">@@ -52,10 +52,11 @@
</span><span class="cx"> return "<%s %r>" % (self.__class__.__name__, self.xmlFile)
</span><span class="cx">
</span><span class="cx">
</span><del>- def __init__(self, xmlFile):
</del><ins>+ def __init__(self, xmlFile, service):
</ins><span class="cx">
</span><span class="cx"> self.items = []
</span><span class="cx"> self.xmlFile = fullServerPath(config.DataRoot, xmlFile)
</span><ins>+ self.service = service
</ins><span class="cx">
</span><span class="cx"> # Read in XML
</span><span class="cx"> try:
</span><span class="lines">@@ -131,7 +132,7 @@
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def updateProxyDB(self):
</span><span class="cx">
</span><del>- db = calendaruserproxy.ProxyDBService
</del><ins>+ db = self.service
</ins><span class="cx"> for item in self.items:
</span><span class="cx"> guid, write_proxies, read_proxies = item
</span><span class="cx"> yield db.setGroupMembers("%s#%s" % (guid, "calendar-proxy-write"), write_proxies)
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytestresourcesxml"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/resources.xml (12994 => 12995)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/resources.xml        2014-03-25 21:34:44 UTC (rev 12994)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/resources.xml        2014-03-25 23:19:18 UTC (rev 12995)
</span><span class="lines">@@ -19,4 +19,60 @@
</span><span class="cx"> <!DOCTYPE accounts SYSTEM "../../../conf/auth/accounts.dtd">
</span><span class="cx">
</span><span class="cx"> <directory realm="Test">
</span><ins>+ <record type="location">
+ <uid>mercury</uid>
+ <short-name>mercury</short-name>
+ <password>mercury</password>
+ <full-name>Mercury Seven</full-name>
+ <email>mercury@example.com</email>
+ </record>
+ <record type="location">
+ <uid>gemini</uid>
+ <short-name>gemini</short-name>
+ <password>gemini</password>
+ <full-name>Gemini Twelve</full-name>
+ <email>gemini@example.com</email>
+ </record>
+ <record type="location">
+ <uid>apollo</uid>
+ <short-name>apollo</short-name>
+ <password>apollo</password>
+ <full-name>Apollo Eleven</full-name>
+ <email>apollo@example.com</email>
+ </record>
+ <record type="location">
+ <uid>orion</uid>
+ <short-name>orion</short-name>
+ <password>orion</password>
+ <full-name>Orion</full-name>
+ <email>orion@example.com</email>
+ </record>
+ <record type="resource">
+ <uid>transporter</uid>
+ <short-name>transporter</short-name>
+ <password>transporter</password>
+ <full-name>Mass Transporter</full-name>
+ <email>transporter@example.com</email>
+ </record>
+ <record type="resource">
+ <uid>ftlcpu</uid>
+ <short-name>ftlcpu</short-name>
+ <password>ftlcpu</password>
+ <full-name>Faster-Than-Light Microprocessor</full-name>
+ <email>ftlcpu@example.com</email>
+ </record>
+ <record type="resource">
+ <uid>non_calendar_proxy</uid>
+ <short-name>non_calendar_proxy</short-name>
+ <password>non_calendar_proxy</password>
+ <full-name>Non-calendar proxy</full-name>
+ <email>non_calendar_proxy@example.com</email>
+ </record>
+ <record type="resource">
+ <uid>disabled</uid>
+ <short-name>disabled</short-name>
+ <password>disabled</password>
+ <full-name>Disabled Record</full-name>
+ <email>disabled@example.com</email>
+ </record>
</ins><span class="cx"> </directory>
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_upgradepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_upgrade.py (12994 => 12995)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_upgrade.py        2014-03-25 21:34:44 UTC (rev 12994)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_upgrade.py        2014-03-25 23:19:18 UTC (rev 12995)
</span><span class="lines">@@ -26,14 +26,16 @@
</span><span class="cx"> from txdav.caldav.datastore.index_file import db_basename
</span><span class="cx">
</span><span class="cx"> from twistedcaldav.config import config
</span><del>-# from twistedcaldav.directory.xmlfile import XMLDirectoryService
</del><span class="cx"> from twistedcaldav.directory.resourceinfo import ResourceInfoDatabase
</span><span class="cx"> from txdav.caldav.datastore.scheduling.imip.mailgateway import MailGatewayTokensDatabase
</span><span class="cx"> from twistedcaldav.upgrade import (
</span><span class="cx"> xattrname, upgradeData, updateFreeBusySet,
</span><del>- removeIllegalCharacters, normalizeCUAddrs
</del><ins>+ removeIllegalCharacters, normalizeCUAddrs,
+ loadDelegatesFromXML, migrateDelegatesToStore
</ins><span class="cx"> )
</span><span class="cx"> from twistedcaldav.test.util import StoreTestCase
</span><ins>+from txdav.who.delegates import delegatesOf
+from twistedcaldav.directory.calendaruserproxy import ProxySqliteDB
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -54,21 +56,6 @@
</span><span class="cx"> class UpgradeTests(StoreTestCase):
</span><span class="cx">
</span><span class="cx">
</span><del>- # def setUpXMLDirectory(self):
- # xmlFile = os.path.join(os.path.dirname(os.path.dirname(__file__)),
- # "directory", "test", "accounts.xml")
- # config.DirectoryService.params.xmlFile = xmlFile
-
- # xmlAugmentsFile = os.path.join(os.path.dirname(os.path.dirname(__file__)),
- # "directory", "test", "augments.xml")
- # config.AugmentService.type = "twistedcaldav.directory.augment.AugmentXMLDB"
- # config.AugmentService.params.xmlFiles = (xmlAugmentsFile,)
-
- # resourceFile = os.path.join(os.path.dirname(os.path.dirname(__file__)),
- # "directory", "test", "resources.xml")
- # config.ResourceService.params.xmlFile = resourceFile
-
-
</del><span class="cx"> def doUpgrade(self, config):
</span><span class="cx"> """
</span><span class="cx"> Perform the actual upgrade. (Hook for parallel tests.)
</span><span class="lines">@@ -1566,6 +1553,46 @@
</span><span class="cx"> self.assertEquals(directory.count, 3)
</span><span class="cx">
</span><span class="cx">
</span><ins>+ @inlineCallbacks
+ def test_migrateDelegates(self):
+ store = self.storeUnderTest()
+ record = yield self.directory.recordWithUID(u"mercury")
+ txn = store.newTransaction()
+ writeDelegates = yield delegatesOf(txn, record, True)
+ self.assertEquals(len(writeDelegates), 0)
+ yield txn.commit()
+
+ # Load delegates from xml into sqlite
+ sqliteProxyService = ProxySqliteDB("proxies.sqlite")
+ proxyFile = os.path.join(config.DataRoot, "proxies.xml")
+ yield loadDelegatesFromXML(proxyFile, sqliteProxyService)
+
+ # Load delegates from sqlite into store
+ yield migrateDelegatesToStore(sqliteProxyService, store)
+
+ # Check delegates in store
+ txn = store.newTransaction()
+ writeDelegates = yield delegatesOf(txn, record, True)
+ self.assertEquals(len(writeDelegates), 1)
+ self.assertEquals(
+ set([d.uid for d in writeDelegates]),
+ set([u"left_coast"])
+ )
+
+ record = yield self.directory.recordWithUID(u"non_calendar_proxy")
+
+ readDelegates = yield delegatesOf(txn, record, False)
+ self.assertEquals(len(readDelegates), 1)
+ self.assertEquals(
+ set([d.uid for d in readDelegates]),
+ set([u"recursive2_coasts"])
+ )
+
+ yield txn.commit()
+
+
+
+
</ins><span class="cx"> normalizeEvent = """BEGIN:VCALENDAR
</span><span class="cx"> VERSION:2.0
</span><span class="cx"> BEGIN:VEVENT
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavtestutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/util.py (12994 => 12995)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/util.py        2014-03-25 21:34:44 UTC (rev 12994)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/util.py        2014-03-25 23:19:18 UTC (rev 12995)
</span><span class="lines">@@ -186,7 +186,11 @@
</span><span class="cx"> augments = FilePath(config.DataRoot).child("augments.xml")
</span><span class="cx"> augments.setContent(augmentsFile.getContent())
</span><span class="cx">
</span><ins>+ proxies = FilePath(config.DataRoot).child("proxies.xml")
+ proxies.setContent(proxiesFile.getContent())
</ins><span class="cx">
</span><ins>+
+
</ins><span class="cx"> def createHierarchy(self, structure, root=None):
</span><span class="cx"> if root is None:
</span><span class="cx"> root = os.path.abspath(self.mktemp())
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavupgradepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/upgrade.py (12994 => 12995)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/upgrade.py        2014-03-25 21:34:44 UTC (rev 12994)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/upgrade.py        2014-03-25 23:19:18 UTC (rev 12995)
</span><span class="lines">@@ -36,7 +36,6 @@
</span><span class="cx"> from txweb2.dav.fileop import rmdir
</span><span class="cx">
</span><span class="cx"> from twistedcaldav import caldavxml
</span><del>-from twistedcaldav.directory import calendaruserproxy
</del><span class="cx"> from twistedcaldav.directory.calendaruserproxyloader import XMLCalendarUserProxyLoader
</span><span class="cx"> from twistedcaldav.directory.principal import DirectoryCalendarPrincipalResource
</span><span class="cx"> from twistedcaldav.directory.resourceinfo import ResourceInfoDatabase
</span><span class="lines">@@ -63,9 +62,9 @@
</span><span class="cx"> from twext.who.idirectory import RecordType
</span><span class="cx"> from txdav.who.idirectory import RecordType as CalRecordType
</span><span class="cx"> from txdav.who.delegates import addDelegate
</span><ins>+from twistedcaldav.directory.calendaruserproxy import ProxySqliteDB
</ins><span class="cx">
</span><span class="cx">
</span><del>-
</del><span class="cx"> deadPropertyXattrPrefix = namedAny(
</span><span class="cx"> "txdav.base.propertystore.xattr.PropertyStore.deadPropertyXattrPrefix"
</span><span class="cx"> )
</span><span class="lines">@@ -1009,35 +1008,17 @@
</span><span class="cx"> log.warn("Migrated %d auto-schedule settings" % (len(augmentRecords),))
</span><span class="cx">
</span><span class="cx">
</span><del>-@inlineCallbacks
-def migrateDelegatesToStore(config, store):
- """
- If there is an sqlite file of delegates, migrate them into the store.
- """
- if config.ProxyDBService.type != "twistedcaldav.directory.calendaruserproxy.ProxySqliteDB":
- returnValue(None)
</del><ins>+def loadDelegatesFromXML(xmlFile, service):
+ loader = XMLCalendarUserProxyLoader(xmlFile, service)
+ return loader.updateProxyDB()
</ins><span class="cx">
</span><del>- dbPath = os.path.join(config.DataRoot, config.ProxyDBService.params.dbpath)
- if not os.path.exists(dbPath):
- returnValue(None)
</del><span class="cx">
</span><del>- proxyClass = namedClass(config.ProxyDBService.type)
- try:
- proxyService = proxyClass(**config.ProxyDBService.params)
- except:
- log.error("Could not migrate delegates to store")
- returnValue(None)
-
- yield _migrateDelegatesToStore(proxyService, store)
- os.remove(dbPath)
-
-
</del><span class="cx"> @inlineCallbacks
</span><del>-def _migrateDelegatesToStore(oldProxyService, store):
</del><ins>+def migrateDelegatesToStore(service, store):
</ins><span class="cx"> directory = store.directoryService()
</span><span class="cx"> txn = store.newTransaction()
</span><span class="cx"> for groupName, memberUID in (
</span><del>- yield oldProxyService.query(
</del><ins>+ yield service.query(
</ins><span class="cx"> "select GROUPNAME, MEMBER from GROUPS"
</span><span class="cx"> )
</span><span class="cx"> ):
</span><span class="lines">@@ -1132,13 +1113,24 @@
</span><span class="cx"> # directory = self.store.directoryService()
</span><span class="cx">
</span><span class="cx"> # Load proxy assignments from XML if specified
</span><del>- if self.config.ProxyLoadFromFile:
- proxydbClass = namedClass(self.config.ProxyDBService.type)
- calendaruserproxy.ProxyDBService = proxydbClass(
- **self.config.ProxyDBService.params)
- loader = XMLCalendarUserProxyLoader(self.config.ProxyLoadFromFile)
- yield loader.updateProxyDB()
</del><ins>+ if (
+ self.config.ProxyLoadFromFile and
+ os.path.exists(self.config.ProxyLoadFromFile) and
+ not os.path.exists(
+ os.path.join(
+ self.config.DataRoot, "proxies.sqlite"
+ )
+ )
+ ):
+ sqliteProxyService = ProxySqliteDB("proxies.sqlite")
+ yield loadDelegatesFromXML(
+ self.config.ProxyLoadFromFile,
+ sqliteProxyService
+ )
+ else:
+ sqliteProxyService = None
</ins><span class="cx">
</span><ins>+
</ins><span class="cx"> # # Populate the group membership cache
</span><span class="cx"> # if (self.config.GroupCaching.Enabled and
</span><span class="cx"> # self.config.GroupCaching.EnableUpdater):
</span><span class="lines">@@ -1171,7 +1163,9 @@
</span><span class="cx"> yield migrateTokensToStore(self.config.DataRoot, self.store)
</span><span class="cx">
</span><span class="cx"> # Migrate delegate assignments from sqlite to store
</span><del>- yield migrateDelegatesToStore(self.config, self.store)
</del><ins>+ if sqliteProxyService is None:
+ sqliteProxyService = ProxySqliteDB("proxies.sqlite")
+ yield migrateDelegatesToStore(sqliteProxyService, self.store)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span></span></pre>
</div>
</div>
</body>
</html>