<!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>[12017] CalendarServer/trunk</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/12017">12017</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2013-12-02 12:56:25 -0800 (Mon, 02 Dec 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>Merge sharing-in-the-store branch. Sharing invites api is now fully store-based.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarserverpushnotifierpy">CalendarServer/trunk/calendarserver/push/notifier.py</a></li>
<li><a href="#CalendarServertrunkcalendarserverpushtesttest_notifierpy">CalendarServer/trunk/calendarserver/push/test/test_notifier.py</a></li>
<li><a href="#CalendarServertrunkcalendarservertapcaldavpy">CalendarServer/trunk/calendarserver/tap/caldav.py</a></li>
<li><a href="#CalendarServertrunktwistedcaldavcustomxmlpy">CalendarServer/trunk/twistedcaldav/customxml.py</a></li>
<li><a href="#CalendarServertrunktwistedcaldavnotificationspy">CalendarServer/trunk/twistedcaldav/notifications.py</a></li>
<li><a href="#CalendarServertrunktwistedcaldavresourcepy">CalendarServer/trunk/twistedcaldav/resource.py</a></li>
<li><a href="#CalendarServertrunktwistedcaldavsharingpy">CalendarServer/trunk/twistedcaldav/sharing.py</a></li>
<li><a href="#CalendarServertrunktwistedcaldavstorebridgepy">CalendarServer/trunk/twistedcaldav/storebridge.py</a></li>
<li><a href="#CalendarServertrunktwistedcaldavtesttest_sharingpy">CalendarServer/trunk/twistedcaldav/test/test_sharing.py</a></li>
<li><a href="#CalendarServertrunktxdavbasedatastoreutilpy">CalendarServer/trunk/txdav/base/datastore/util.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoresqlpy">CalendarServer/trunk/txdav/caldav/datastore/sql.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoretestcommonpy">CalendarServer/trunk/txdav/caldav/datastore/test/common.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoretesttest_sqlpy">CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py</a></li>
<li><a href="#CalendarServertrunktxdavcarddavdatastoresqlpy">CalendarServer/trunk/txdav/carddav/datastore/sql.py</a></li>
<li><a href="#CalendarServertrunktxdavcarddavdatastoretesttest_sqlpy">CalendarServer/trunk/txdav/carddav/datastore/test/test_sql.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastorefilepy">CalendarServer/trunk/txdav/common/datastore/file.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresqlpy">CalendarServer/trunk/txdav/common/datastore/sql.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresql_schemacurrentoracledialectsql">CalendarServer/trunk/txdav/common/datastore/sql_schema/current-oracle-dialect.sql</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresql_schemacurrentsql">CalendarServer/trunk/txdav/common/datastore/sql_schema/current.sql</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresql_tablespy">CalendarServer/trunk/txdav/common/datastore/sql_tables.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoretestutilpy">CalendarServer/trunk/txdav/common/datastore/test/util.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoreupgradesqlupgradepy">CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrade.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoreupgradesqlupgradesutilpy">CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/util.py</a></li>
<li><a href="#CalendarServertrunktxdavcommoninotificationspy">CalendarServer/trunk/txdav/common/inotifications.py</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxdavcaldavdatastoretesttest_sql_sharingpy">CalendarServer/trunk/txdav/caldav/datastore/test/test_sql_sharing.py</a></li>
<li><a href="#CalendarServertrunktxdavcarddavdatastoretesttest_sql_sharingpy">CalendarServer/trunk/txdav/carddav/datastore/test/test_sql_sharing.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresql_schemaoldoracledialectv28sql">CalendarServer/trunk/txdav/common/datastore/sql_schema/old/oracle-dialect/v28.sql</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresql_schemaoldpostgresdialectv28sql">CalendarServer/trunk/txdav/common/datastore/sql_schema/old/postgres-dialect/v28.sql</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresql_schemaupgradesoracledialectupgrade_from_28_to_29sql">CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_28_to_29.sql</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresql_schemaupgradespostgresdialectupgrade_from_28_to_29sql">CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_28_to_29.sql</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoreupgradesqlupgradesnotification_upgrade_from_0_to_1py">CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/notification_upgrade_from_0_to_1.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoreupgradesqlupgradestesttest_notification_upgrade_from_0_to_1py">CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/test/test_notification_upgrade_from_0_to_1.py</a></li>
</ul>
<h3>Property Changed</h3>
<ul>
<li><a href="#CalendarServertrunk">CalendarServer/trunk/</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunk"></a>
<div class="propset"><h4>Property changes: CalendarServer/trunk</h4>
<pre class="diff"><span>
</span></pre></div>
<a id="svnmergeinfo"></a>
<div class="modfile"><h4>Modified: svn:mergeinfo</h4></div>
<span class="cx">/CalendarServer/branches/config-separation:4379-4443
</span><span class="cx">/CalendarServer/branches/egg-info-351:4589-4625
</span><span class="cx">/CalendarServer/branches/generic-sqlstore:6167-6191
</span><span class="cx">/CalendarServer/branches/new-store:5594-5934
</span><span class="cx">/CalendarServer/branches/new-store-no-caldavfile:5911-5935
</span><span class="cx">/CalendarServer/branches/new-store-no-caldavfile-2:5936-5981
</span><span class="cx">/CalendarServer/branches/release/CalendarServer-4.3-dev:10180-10190,10192
</span><span class="cx">/CalendarServer/branches/release/CalendarServer-5.1-dev:11846
</span><span class="cx">/CalendarServer/branches/users/cdaboo/batchupload-6699:6700-7198
</span><span class="cx">/CalendarServer/branches/users/cdaboo/cached-subscription-calendars-5692:5693-5702
</span><span class="cx">/CalendarServer/branches/users/cdaboo/component-set-fixes:8130-8346
</span><span class="cx">/CalendarServer/branches/users/cdaboo/directory-cache-on-demand-3627:3628-3644
</span><span class="cx">/CalendarServer/branches/users/cdaboo/fix-no-ischedule:11607-11871
</span><span class="cx">/CalendarServer/branches/users/cdaboo/implicituidrace:8137-8141
</span><span class="cx">/CalendarServer/branches/users/cdaboo/ischedule-dkim:9747-9979
</span><span class="cx">/CalendarServer/branches/users/cdaboo/json:11622-11912
</span><span class="cx">/CalendarServer/branches/users/cdaboo/managed-attachments:9985-10145
</span><span class="cx">/CalendarServer/branches/users/cdaboo/more-sharing-5591:5592-5601
</span><span class="cx">/CalendarServer/branches/users/cdaboo/partition-4464:4465-4957
</span><span class="cx">/CalendarServer/branches/users/cdaboo/performance-tweaks:11824-11836
</span><span class="cx">/CalendarServer/branches/users/cdaboo/pods:7297-7377
</span><span class="cx">/CalendarServer/branches/users/cdaboo/pycalendar:7085-7206
</span><span class="cx">/CalendarServer/branches/users/cdaboo/pycard:7227-7237
</span><span class="cx">/CalendarServer/branches/users/cdaboo/queued-attendee-refreshes:7740-8287
</span><span class="cx">/CalendarServer/branches/users/cdaboo/relative-config-paths-5070:5071-5105
</span><span class="cx">/CalendarServer/branches/users/cdaboo/reverse-proxy-pods:11875-11900
</span><span class="cx">/CalendarServer/branches/users/cdaboo/shared-calendars-5187:5188-5440
</span><span class="cx">/CalendarServer/branches/users/cdaboo/store-scheduling:10876-11129
</span><span class="cx">/CalendarServer/branches/users/cdaboo/timezones:7443-7699
</span><span class="cx">/CalendarServer/branches/users/cdaboo/txn-debugging:8730-8743
</span><span class="cx">/CalendarServer/branches/users/gaya/sharedgroups-3:11088-11204
</span><span class="cx">/CalendarServer/branches/users/glyph/always-abort-txn-on-error:9958-9969
</span><span class="cx">/CalendarServer/branches/users/glyph/case-insensitive-uid:8772-8805
</span><span class="cx">/CalendarServer/branches/users/glyph/conn-limit:6574-6577
</span><span class="cx">/CalendarServer/branches/users/glyph/contacts-server-merge:4971-5080
</span><span class="cx">/CalendarServer/branches/users/glyph/dalify:6932-7023
</span><span class="cx">/CalendarServer/branches/users/glyph/db-reconnect:6824-6876
</span><span class="cx">/CalendarServer/branches/users/glyph/deploybuild:7563-7572
</span><span class="cx">/CalendarServer/branches/users/glyph/digest-auth-redux:10624-10635
</span><span class="cx">/CalendarServer/branches/users/glyph/disable-quota:7718-7727
</span><span class="cx">/CalendarServer/branches/users/glyph/dont-start-postgres:6592-6614
</span><span class="cx">/CalendarServer/branches/users/glyph/enforce-max-requests:11640-11643
</span><span class="cx">/CalendarServer/branches/users/glyph/hang-fix:11465-11491
</span><span class="cx">/CalendarServer/branches/users/glyph/imip-and-admin-html:7866-7984
</span><span class="cx">/CalendarServer/branches/users/glyph/ipv6-client:9054-9105
</span><span class="cx">/CalendarServer/branches/users/glyph/launchd-wrapper-bis:11413-11436
</span><span class="cx">/CalendarServer/branches/users/glyph/linux-tests:6893-6900
</span><span class="cx">/CalendarServer/branches/users/glyph/log-cleanups:11691-11731
</span><span class="cx">/CalendarServer/branches/users/glyph/migrate-merge:8690-8713
</span><span class="cx">/CalendarServer/branches/users/glyph/misc-portability-fixes:7365-7374
</span><span class="cx">/CalendarServer/branches/users/glyph/more-deferreds-6:6322-6368
</span><span class="cx">/CalendarServer/branches/users/glyph/more-deferreds-7:6369-6445
</span><span class="cx">/CalendarServer/branches/users/glyph/multiget-delete:8321-8330
</span><span class="cx">/CalendarServer/branches/users/glyph/new-export:7444-7485
</span><span class="cx">/CalendarServer/branches/users/glyph/one-home-list-api:10048-10073
</span><span class="cx">/CalendarServer/branches/users/glyph/oracle:7106-7155
</span><span class="cx">/CalendarServer/branches/users/glyph/oracle-nulls:7340-7351
</span><span class="cx">/CalendarServer/branches/users/glyph/other-html:8062-8091
</span><span class="cx">/CalendarServer/branches/users/glyph/parallel-sim:8240-8251
</span><span class="cx">/CalendarServer/branches/users/glyph/parallel-upgrade:8376-8400
</span><span class="cx">/CalendarServer/branches/users/glyph/parallel-upgrade_to_1:8571-8583
</span><span class="cx">/CalendarServer/branches/users/glyph/q:9560-9688
</span><span class="cx">/CalendarServer/branches/users/glyph/queue-locking-and-timing:10204-10289
</span><span class="cx">/CalendarServer/branches/users/glyph/quota:7604-7637
</span><span class="cx">/CalendarServer/branches/users/glyph/sendfdport:5388-5424
</span><span class="cx">/CalendarServer/branches/users/glyph/shared-pool-fixes:8436-8443
</span><span class="cx">/CalendarServer/branches/users/glyph/shared-pool-take2:8155-8174
</span><span class="cx">/CalendarServer/branches/users/glyph/sharedpool:6490-6550
</span><span class="cx">/CalendarServer/branches/users/glyph/sharing-api:9192-9205
</span><span class="cx">/CalendarServer/branches/users/glyph/skip-lonely-vtimezones:8524-8535
</span><span class="cx">/CalendarServer/branches/users/glyph/sql-store:5929-6073
</span><span class="cx">/CalendarServer/branches/users/glyph/start-service-start-loop:11060-11065
</span><span class="cx">/CalendarServer/branches/users/glyph/subtransactions:7248-7258
</span><span class="cx">/CalendarServer/branches/users/glyph/table-alias:8651-8664
</span><span class="cx">/CalendarServer/branches/users/glyph/uidexport:7673-7676
</span><span class="cx">/CalendarServer/branches/users/glyph/unshare-when-access-revoked:10562-10595
</span><span class="cx">/CalendarServer/branches/users/glyph/use-system-twisted:5084-5149
</span><span class="cx">/CalendarServer/branches/users/glyph/uuid-normalize:9268-9296
</span><span class="cx">/CalendarServer/branches/users/glyph/warning-cleanups:11347-11357
</span><span class="cx">/CalendarServer/branches/users/glyph/whenNotProposed:11881-11897
</span><span class="cx">/CalendarServer/branches/users/glyph/xattrs-from-files:7757-7769
</span><span class="cx">/CalendarServer/branches/users/sagen/applepush:8126-8184
</span><span class="cx">/CalendarServer/branches/users/sagen/inboxitems:7380-7381
</span><span class="cx">/CalendarServer/branches/users/sagen/locations-resources:5032-5051
</span><span class="cx">/CalendarServer/branches/users/sagen/locations-resources-2:5052-5061
</span><span class="cx">/CalendarServer/branches/users/sagen/purge_old_events:6735-6746
</span><span class="cx">/CalendarServer/branches/users/sagen/resource-delegates-4038:4040-4067
</span><span class="cx">/CalendarServer/branches/users/sagen/resource-delegates-4066:4068-4075
</span><span class="cx">/CalendarServer/branches/users/sagen/resources-2:5084-5093
</span><span class="cx">/CalendarServer/branches/users/sagen/testing:10827-10851,10853-10855
</span><span class="cx">/CalendarServer/branches/users/wsanchez/transations:5515-5593
</span><span class="cx"> + /CalDAVTester/trunk:11193-11198
</span><span class="cx">/CalendarServer/branches/config-separation:4379-4443
</span><span class="cx">/CalendarServer/branches/egg-info-351:4589-4625
</span><span class="cx">/CalendarServer/branches/generic-sqlstore:6167-6191
</span><span class="cx">/CalendarServer/branches/new-store:5594-5934
</span><span class="cx">/CalendarServer/branches/new-store-no-caldavfile:5911-5935
</span><span class="cx">/CalendarServer/branches/new-store-no-caldavfile-2:5936-5981
</span><span class="cx">/CalendarServer/branches/release/CalendarServer-4.3-dev:10180-10190,10192
</span><span class="cx">/CalendarServer/branches/release/CalendarServer-5.1-dev:11846
</span><span class="cx">/CalendarServer/branches/users/cdaboo/batchupload-6699:6700-7198
</span><span class="cx">/CalendarServer/branches/users/cdaboo/cached-subscription-calendars-5692:5693-5702
</span><span class="cx">/CalendarServer/branches/users/cdaboo/component-set-fixes:8130-8346
</span><span class="cx">/CalendarServer/branches/users/cdaboo/directory-cache-on-demand-3627:3628-3644
</span><span class="cx">/CalendarServer/branches/users/cdaboo/fix-no-ischedule:11607-11871
</span><span class="cx">/CalendarServer/branches/users/cdaboo/implicituidrace:8137-8141
</span><span class="cx">/CalendarServer/branches/users/cdaboo/ischedule-dkim:9747-9979
</span><span class="cx">/CalendarServer/branches/users/cdaboo/json:11622-11912
</span><span class="cx">/CalendarServer/branches/users/cdaboo/managed-attachments:9985-10145
</span><span class="cx">/CalendarServer/branches/users/cdaboo/more-sharing-5591:5592-5601
</span><span class="cx">/CalendarServer/branches/users/cdaboo/partition-4464:4465-4957
</span><span class="cx">/CalendarServer/branches/users/cdaboo/performance-tweaks:11824-11836
</span><span class="cx">/CalendarServer/branches/users/cdaboo/pods:7297-7377
</span><span class="cx">/CalendarServer/branches/users/cdaboo/pycalendar:7085-7206
</span><span class="cx">/CalendarServer/branches/users/cdaboo/pycard:7227-7237
</span><span class="cx">/CalendarServer/branches/users/cdaboo/queued-attendee-refreshes:7740-8287
</span><span class="cx">/CalendarServer/branches/users/cdaboo/relative-config-paths-5070:5071-5105
</span><span class="cx">/CalendarServer/branches/users/cdaboo/reverse-proxy-pods:11875-11900
</span><span class="cx">/CalendarServer/branches/users/cdaboo/shared-calendars-5187:5188-5440
</span><span class="cx">/CalendarServer/branches/users/cdaboo/sharing-in-the-store:11935-12016
</span><span class="cx">/CalendarServer/branches/users/cdaboo/store-scheduling:10876-11129
</span><span class="cx">/CalendarServer/branches/users/cdaboo/timezones:7443-7699
</span><span class="cx">/CalendarServer/branches/users/cdaboo/txn-debugging:8730-8743
</span><span class="cx">/CalendarServer/branches/users/gaya/sharedgroups-3:11088-11204
</span><span class="cx">/CalendarServer/branches/users/glyph/always-abort-txn-on-error:9958-9969
</span><span class="cx">/CalendarServer/branches/users/glyph/case-insensitive-uid:8772-8805
</span><span class="cx">/CalendarServer/branches/users/glyph/conn-limit:6574-6577
</span><span class="cx">/CalendarServer/branches/users/glyph/contacts-server-merge:4971-5080
</span><span class="cx">/CalendarServer/branches/users/glyph/dalify:6932-7023
</span><span class="cx">/CalendarServer/branches/users/glyph/db-reconnect:6824-6876
</span><span class="cx">/CalendarServer/branches/users/glyph/deploybuild:7563-7572
</span><span class="cx">/CalendarServer/branches/users/glyph/digest-auth-redux:10624-10635
</span><span class="cx">/CalendarServer/branches/users/glyph/disable-quota:7718-7727
</span><span class="cx">/CalendarServer/branches/users/glyph/dont-start-postgres:6592-6614
</span><span class="cx">/CalendarServer/branches/users/glyph/enforce-max-requests:11640-11643
</span><span class="cx">/CalendarServer/branches/users/glyph/hang-fix:11465-11491
</span><span class="cx">/CalendarServer/branches/users/glyph/imip-and-admin-html:7866-7984
</span><span class="cx">/CalendarServer/branches/users/glyph/ipv6-client:9054-9105
</span><span class="cx">/CalendarServer/branches/users/glyph/launchd-wrapper-bis:11413-11436
</span><span class="cx">/CalendarServer/branches/users/glyph/linux-tests:6893-6900
</span><span class="cx">/CalendarServer/branches/users/glyph/log-cleanups:11691-11731
</span><span class="cx">/CalendarServer/branches/users/glyph/migrate-merge:8690-8713
</span><span class="cx">/CalendarServer/branches/users/glyph/misc-portability-fixes:7365-7374
</span><span class="cx">/CalendarServer/branches/users/glyph/more-deferreds-6:6322-6368
</span><span class="cx">/CalendarServer/branches/users/glyph/more-deferreds-7:6369-6445
</span><span class="cx">/CalendarServer/branches/users/glyph/multiget-delete:8321-8330
</span><span class="cx">/CalendarServer/branches/users/glyph/new-export:7444-7485
</span><span class="cx">/CalendarServer/branches/users/glyph/one-home-list-api:10048-10073
</span><span class="cx">/CalendarServer/branches/users/glyph/oracle:7106-7155
</span><span class="cx">/CalendarServer/branches/users/glyph/oracle-nulls:7340-7351
</span><span class="cx">/CalendarServer/branches/users/glyph/other-html:8062-8091
</span><span class="cx">/CalendarServer/branches/users/glyph/parallel-sim:8240-8251
</span><span class="cx">/CalendarServer/branches/users/glyph/parallel-upgrade:8376-8400
</span><span class="cx">/CalendarServer/branches/users/glyph/parallel-upgrade_to_1:8571-8583
</span><span class="cx">/CalendarServer/branches/users/glyph/q:9560-9688
</span><span class="cx">/CalendarServer/branches/users/glyph/queue-locking-and-timing:10204-10289
</span><span class="cx">/CalendarServer/branches/users/glyph/quota:7604-7637
</span><span class="cx">/CalendarServer/branches/users/glyph/sendfdport:5388-5424
</span><span class="cx">/CalendarServer/branches/users/glyph/shared-pool-fixes:8436-8443
</span><span class="cx">/CalendarServer/branches/users/glyph/shared-pool-take2:8155-8174
</span><span class="cx">/CalendarServer/branches/users/glyph/sharedpool:6490-6550
</span><span class="cx">/CalendarServer/branches/users/glyph/sharing-api:9192-9205
</span><span class="cx">/CalendarServer/branches/users/glyph/skip-lonely-vtimezones:8524-8535
</span><span class="cx">/CalendarServer/branches/users/glyph/sql-store:5929-6073
</span><span class="cx">/CalendarServer/branches/users/glyph/start-service-start-loop:11060-11065
</span><span class="cx">/CalendarServer/branches/users/glyph/subtransactions:7248-7258
</span><span class="cx">/CalendarServer/branches/users/glyph/table-alias:8651-8664
</span><span class="cx">/CalendarServer/branches/users/glyph/uidexport:7673-7676
</span><span class="cx">/CalendarServer/branches/users/glyph/unshare-when-access-revoked:10562-10595
</span><span class="cx">/CalendarServer/branches/users/glyph/use-system-twisted:5084-5149
</span><span class="cx">/CalendarServer/branches/users/glyph/uuid-normalize:9268-9296
</span><span class="cx">/CalendarServer/branches/users/glyph/warning-cleanups:11347-11357
</span><span class="cx">/CalendarServer/branches/users/glyph/whenNotProposed:11881-11897
</span><span class="cx">/CalendarServer/branches/users/glyph/xattrs-from-files:7757-7769
</span><span class="cx">/CalendarServer/branches/users/sagen/applepush:8126-8184
</span><span class="cx">/CalendarServer/branches/users/sagen/inboxitems:7380-7381
</span><span class="cx">/CalendarServer/branches/users/sagen/locations-resources:5032-5051
</span><span class="cx">/CalendarServer/branches/users/sagen/locations-resources-2:5052-5061
</span><span class="cx">/CalendarServer/branches/users/sagen/purge_old_events:6735-6746
</span><span class="cx">/CalendarServer/branches/users/sagen/resource-delegates-4038:4040-4067
</span><span class="cx">/CalendarServer/branches/users/sagen/resource-delegates-4066:4068-4075
</span><span class="cx">/CalendarServer/branches/users/sagen/resources-2:5084-5093
</span><span class="cx">/CalendarServer/branches/users/sagen/testing:10827-10851,10853-10855
</span><span class="cx">/CalendarServer/branches/users/wsanchez/transations:5515-5593
</span><a id="CalendarServertrunkcalendarserverpushnotifierpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/push/notifier.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/push/notifier.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/calendarserver/push/notifier.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -38,7 +38,6 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><del>-
</del><span class="cx"> class PushNotificationWork(WorkItem, fromTable(schema.PUSH_NOTIFICATION_WORK)):
</span><span class="cx">
</span><span class="cx"> group = property(lambda self: self.pushID)
</span></span></pre></div>
<a id="CalendarServertrunkcalendarserverpushtesttest_notifierpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/push/test/test_notifier.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/push/test/test_notifier.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/calendarserver/push/test/test_notifier.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -99,6 +99,7 @@
</span><span class="cx"> return(succeed(None))
</span><span class="cx">
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> class PushNotificationWorkTests(StoreTestCase):
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="lines">@@ -179,6 +180,7 @@
</span><span class="cx"> [("/CalDAV/localhost/bar/", PushPriority.high)])
</span><span class="cx">
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> class NotifierFactory(StoreTestCase):
</span><span class="cx">
</span><span class="cx"> requirements = {
</span><span class="lines">@@ -231,27 +233,27 @@
</span><span class="cx"> def test_shareWithNotifier(self):
</span><span class="cx">
</span><span class="cx"> calendar = yield self.calendarUnderTest()
</span><del>- home2 = yield self.homeUnderTest(name="home2")
- yield calendar.shareWith(home2, _BIND_MODE_WRITE)
</del><ins>+ yield calendar.inviteUserToShare("home2", _BIND_MODE_WRITE, "")
</ins><span class="cx"> self.assertEquals(
</span><span class="cx"> set(self.notifierFactory.history),
</span><span class="cx"> set([
</span><span class="cx"> ("/CalDAV/example.com/home1/", PushPriority.high),
</span><span class="cx"> ("/CalDAV/example.com/home1/calendar_1/", PushPriority.high),
</span><span class="cx"> ("/CalDAV/example.com/home2/", PushPriority.high),
</span><ins>+ ("/CalDAV/example.com/home2/notification/", PushPriority.high),
</ins><span class="cx"> ])
</span><span class="cx"> )
</span><span class="cx"> yield self.commit()
</span><span class="cx">
</span><span class="cx"> calendar = yield self.calendarUnderTest()
</span><del>- home2 = yield self.homeUnderTest(name="home2")
- yield calendar.unshareWith(home2)
</del><ins>+ yield calendar.uninviteUserFromShare("home2")
</ins><span class="cx"> self.assertEquals(
</span><span class="cx"> set(self.notifierFactory.history),
</span><span class="cx"> set([
</span><span class="cx"> ("/CalDAV/example.com/home1/", PushPriority.high),
</span><span class="cx"> ("/CalDAV/example.com/home1/calendar_1/", PushPriority.high),
</span><span class="cx"> ("/CalDAV/example.com/home2/", PushPriority.high),
</span><ins>+ ("/CalDAV/example.com/home2/notification/", PushPriority.high),
</ins><span class="cx"> ])
</span><span class="cx"> )
</span><span class="cx"> yield self.commit()
</span><span class="lines">@@ -261,8 +263,9 @@
</span><span class="cx"> def test_sharedCalendarNotifier(self):
</span><span class="cx">
</span><span class="cx"> calendar = yield self.calendarUnderTest()
</span><del>- home2 = yield self.homeUnderTest(name="home2")
- shareName = yield calendar.shareWith(home2, _BIND_MODE_WRITE)
</del><ins>+ shareeView = yield calendar.inviteUserToShare("home2", _BIND_MODE_WRITE, "")
+ yield shareeView.acceptShare("")
+ shareName = shareeView.name()
</ins><span class="cx"> yield self.commit()
</span><span class="cx"> self.notifierFactory.reset()
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunkcalendarservertapcaldavpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tap/caldav.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tap/caldav.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -72,8 +72,7 @@
</span><span class="cx"> from txdav.common.datastore.upgrade.sql.upgrade import (
</span><span class="cx"> UpgradeDatabaseSchemaStep, UpgradeDatabaseAddressBookDataStep,
</span><span class="cx"> UpgradeDatabaseCalendarDataStep, UpgradeDatabaseOtherStep,
</span><del>- UpgradeAcquireLockStep, UpgradeReleaseLockStep
-)
</del><ins>+ UpgradeAcquireLockStep, UpgradeReleaseLockStep, UpgradeDatabaseNotificationDataStep)
</ins><span class="cx"> from txdav.common.datastore.upgrade.migrate import UpgradeToDatabaseStep
</span><span class="cx"> from txdav.caldav.datastore.scheduling.imip.inbound import MailRetriever
</span><span class="cx"> from txdav.caldav.datastore.scheduling.imip.inbound import scheduleNextMailPoll
</span><span class="lines">@@ -1420,6 +1419,12 @@
</span><span class="cx"> )
</span><span class="cx">
</span><span class="cx"> pps.addStep(
</span><ins>+ UpgradeDatabaseNotificationDataStep(
+ store, uid=overrideUID, gid=overrideGID
+ )
+ )
+
+ pps.addStep(
</ins><span class="cx"> UpgradeToDatabaseStep(
</span><span class="cx"> UpgradeToDatabaseStep.fileStoreFromPath(
</span><span class="cx"> CachingFilePath(config.DocumentRoot)
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavcustomxmlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/customxml.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/customxml.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/twistedcaldav/customxml.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -639,8 +639,9 @@
</span><span class="cx"> name = "dtstamp"
</span><span class="cx">
</span><span class="cx"> def __init__(self, *children):
</span><del>- super(DTStamp, self).__init__(children)
- self.children = (PCDATAElement(DateTime.getNowUTC().getText()),)
</del><ins>+ super(DTStamp, self).__init__(*children)
+ if not self.children:
+ self.children = (PCDATAElement(DateTime.getNowUTC().getText()),)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavnotificationspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/notifications.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/notifications.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/twistedcaldav/notifications.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx">
</span><span class="cx"> from txdav.common.icommondatastore import SyncTokenValidException
</span><span class="cx">
</span><ins>+import json
</ins><span class="cx"> import os
</span><span class="cx"> import types
</span><span class="cx">
</span><span class="lines">@@ -92,17 +93,6 @@
</span><span class="cx"> return davxml.ResourceType.notification
</span><span class="cx">
</span><span class="cx">
</span><del>- @inlineCallbacks
- def addNotification(self, request, uid, xmltype, xmldata):
-
- # Write data to file
- rname = uid + ".xml"
- yield self._writeNotification(request, uid, rname, xmltype, xmldata)
-
- # Update database
- self.notificationsDB().addOrUpdateRecord(NotificationRecord(uid, rname, xmltype.name))
-
-
</del><span class="cx"> def getNotifictionMessages(self, request, componentType=None, returnLatestVersion=True):
</span><span class="cx"> return succeed([])
</span><span class="cx">
</span><span class="lines">@@ -144,10 +134,10 @@
</span><span class="cx">
</span><span class="cx"> class NotificationRecord(object):
</span><span class="cx">
</span><del>- def __init__(self, uid, name, xmltype):
</del><ins>+ def __init__(self, uid, name, notificationtype):
</ins><span class="cx"> self.uid = uid
</span><span class="cx"> self.name = name
</span><del>- self.xmltype = xmltype
</del><ins>+ self.notificationtype = notificationtype if isinstance(notificationtype, dict) else json.loads(notificationtype)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -184,7 +174,7 @@
</span><span class="cx">
</span><span class="cx"> self._db_execute("""insert or replace into NOTIFICATIONS (UID, NAME, TYPE)
</span><span class="cx"> values (:1, :2, :3)
</span><del>- """, record.uid, record.name, record.xmltype,
</del><ins>+ """, record.uid, record.name, json.dumps(record.notificationtype),
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx"> self._db_execute(
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavresourcepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/resource.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/resource.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/twistedcaldav/resource.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -691,7 +691,7 @@
</span><span class="cx">
</span><span class="cx"> elif qname == customxml.SharedURL.qname():
</span><span class="cx"> if self.isShareeResource():
</span><del>- returnValue(customxml.SharedURL(element.HRef.fromString(self._share.url())))
</del><ins>+ returnValue(customxml.SharedURL(element.HRef.fromString(self._share_url)))
</ins><span class="cx"> else:
</span><span class="cx"> returnValue(None)
</span><span class="cx">
</span><span class="lines">@@ -859,8 +859,12 @@
</span><span class="cx"> Return the DAV:owner property value (MUST be a DAV:href or None).
</span><span class="cx"> """
</span><span class="cx">
</span><del>- if self.isShareeResource():
- parent = (yield self.locateParent(request, self._share.url()))
</del><ins>+ if hasattr(self, "_newStoreObject"):
+ if not hasattr(self._newStoreObject, "ownerHome"):
+ home = self._newStoreObject.parentCollection().ownerHome()
+ else:
+ home = self._newStoreObject.ownerHome()
+ returnValue(element.HRef(self.principalForUID(home.uid()).principalURL()))
</ins><span class="cx"> else:
</span><span class="cx"> parent = (yield self.locateParent(request, request.urlForResource(self)))
</span><span class="cx"> if parent and isinstance(parent, CalDAVResource):
</span><span class="lines">@@ -875,8 +879,12 @@
</span><span class="cx"> """
</span><span class="cx"> Return the DAV:owner property value (MUST be a DAV:href or None).
</span><span class="cx"> """
</span><del>- if self.isShareeResource():
- parent = (yield self.locateParent(request, self._share.url()))
</del><ins>+ if hasattr(self, "_newStoreObject"):
+ if not hasattr(self._newStoreObject, "ownerHome"):
+ home = self._newStoreObject.parentCollection().ownerHome()
+ else:
+ home = self._newStoreObject.ownerHome()
+ returnValue(self.principalForUID(home.uid()))
</ins><span class="cx"> else:
</span><span class="cx"> parent = (yield self.locateParent(request, request.urlForResource(self)))
</span><span class="cx"> if parent and isinstance(parent, CalDAVResource):
</span><span class="lines">@@ -1251,13 +1259,13 @@
</span><span class="cx"> sharedParent = None
</span><span class="cx"> if self.isShareeResource():
</span><span class="cx"> # A sharee collection's quota root is the resource owner's root
</span><del>- sharedParent = (yield request.locateResource(parentForURL(self._share.url())))
</del><ins>+ sharedParent = (yield request.locateResource(parentForURL(self._share_url)))
</ins><span class="cx"> else:
</span><span class="cx"> parent = (yield self.locateParent(request, request.urlForResource(self)))
</span><span class="cx"> if isCalendarCollectionResource(parent) or isAddressBookCollectionResource(parent):
</span><span class="cx"> if parent.isShareeResource():
</span><span class="cx"> # A sharee collection's quota root is the resource owner's root
</span><del>- sharedParent = (yield request.locateResource(parentForURL(parent._share.url())))
</del><ins>+ sharedParent = (yield request.locateResource(parentForURL(parent._share_url)))
</ins><span class="cx">
</span><span class="cx"> if sharedParent:
</span><span class="cx"> result = (yield sharedParent.quotaRootResource(request))
</span><span class="lines">@@ -2542,6 +2550,11 @@
</span><span class="cx"> return config.Sharing.Enabled and config.Sharing.Calendars.Enabled and self.exists()
</span><span class="cx">
</span><span class="cx">
</span><ins>+ def _otherPrincipalHomeURL(self, otherUID):
+ ownerPrincipal = self.principalForUID(otherUID)
+ return ownerPrincipal.calendarHomeURLs()[0]
+
+
</ins><span class="cx"> @inlineCallbacks
</span><span class="cx"> def makeRegularChild(self, name):
</span><span class="cx"> newCalendar = yield self._newStoreHome.calendarWithName(name)
</span><span class="lines">@@ -2794,6 +2807,11 @@
</span><span class="cx"> return config.Sharing.Enabled and config.Sharing.AddressBooks.Enabled and self.exists()
</span><span class="cx">
</span><span class="cx">
</span><ins>+ def _otherPrincipalHomeURL(self, otherUID):
+ ownerPrincipal = self.principalForUID(otherUID)
+ return ownerPrincipal.addressBookHomeURLs()[0]
+
+
</ins><span class="cx"> @inlineCallbacks
</span><span class="cx"> def makeRegularChild(self, name):
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavsharingpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/sharing.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/sharing.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/twistedcaldav/sharing.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -22,6 +22,7 @@
</span><span class="cx">
</span><span class="cx"> __all__ = [
</span><span class="cx"> "SharedResourceMixin",
</span><ins>+ "SharedHomeMixin",
</ins><span class="cx"> ]
</span><span class="cx">
</span><span class="cx"> from twext.web2 import responsecode
</span><span class="lines">@@ -30,11 +31,11 @@
</span><span class="cx"> from twext.web2.dav.resource import TwistedACLInheritable
</span><span class="cx"> from twext.web2.dav.util import allDataFromStream, joinURL
</span><span class="cx">
</span><del>-from txdav.common.datastore.sql import SharingInvitation
</del><span class="cx"> from txdav.common.datastore.sql_tables import _BIND_MODE_OWN, \
</span><span class="cx"> _BIND_MODE_READ, _BIND_MODE_WRITE, _BIND_STATUS_INVITED, \
</span><del>- _BIND_MODE_DIRECT, _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED, \
- _BIND_STATUS_INVALID, _ABO_KIND_GROUP
</del><ins>+ _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED, \
+ _BIND_STATUS_INVALID, _ABO_KIND_GROUP, _BIND_STATUS_DELETED, \
+ _BIND_MODE_DIRECT, _BIND_MODE_INDIRECT
</ins><span class="cx"> from txdav.xml import element
</span><span class="cx">
</span><span class="cx"> from twisted.internet.defer import succeed, inlineCallbacks, DeferredList, \
</span><span class="lines">@@ -46,26 +47,11 @@
</span><span class="cx"> from twistedcaldav.directory.wiki import WikiDirectoryService, getWikiAccess
</span><span class="cx"> from twistedcaldav.linkresource import LinkFollowerMixIn
</span><span class="cx">
</span><del>-from pycalendar.datetime import DateTime
</del><span class="cx">
</span><del>-
-# FIXME: Get rid of these imports
-from twistedcaldav.directory.util import TRANSACTION_KEY
-# circular import
-# from txdav.common.datastore.sql import ECALENDARTYPE, EADDRESSBOOKTYPE
-ECALENDARTYPE = 0
-EADDRESSBOOKTYPE = 1
-# ENOTIFICATIONTYPE = 2
-
-
</del><span class="cx"> class SharedResourceMixin(object):
</span><span class="cx"> """
</span><span class="cx"> A mix-in for calendar/addressbook resources that implements sharing-related
</span><span class="cx"> functionality.
</span><del>-
- @ivar _share: If this L{SharedResourceMixin} is the sharee's version of a
- resource, this refers to the L{Share} that describes it.
- @type _share: L{Share} or L{NoneType}
</del><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="lines">@@ -78,15 +64,15 @@
</span><span class="cx">
</span><span class="cx"> def invitePropertyElement(invitation, includeUID=True):
</span><span class="cx">
</span><del>- userid = "urn:uuid:" + invitation.shareeUID()
- principal = self.principalForUID(invitation.shareeUID())
- cn = principal.displayName() if principal else invitation.shareeUID()
</del><ins>+ userid = "urn:uuid:" + invitation.shareeUID
+ principal = self.principalForUID(invitation.shareeUID)
+ cn = principal.displayName() if principal else invitation.shareeUID
</ins><span class="cx"> return customxml.InviteUser(
</span><del>- customxml.UID.fromString(invitation.uid()) if includeUID else None,
</del><ins>+ customxml.UID.fromString(invitation.uid) if includeUID else None,
</ins><span class="cx"> element.HRef.fromString(userid),
</span><span class="cx"> customxml.CommonName.fromString(cn),
</span><del>- customxml.InviteAccess(invitationBindModeToXMLMap[invitation.mode()]()),
- invitationBindStatusToXMLMap[invitation.status()](),
</del><ins>+ customxml.InviteAccess(invitationBindModeToXMLMap[invitation.mode]()),
+ invitationBindStatusToXMLMap[invitation.status](),
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx"> # See if this property is on the shared calendar
</span><span class="lines">@@ -98,11 +84,12 @@
</span><span class="cx">
</span><span class="cx"> # See if it is on the sharee calendar
</span><span class="cx"> if self.isShareeResource():
</span><del>- original = (yield request.locateResource(self._share.url()))
</del><ins>+ original = yield self._newStoreObject.ownerView()
</ins><span class="cx"> if original is not None:
</span><del>- invitations = yield original.validateInvites(request)
</del><ins>+ invitations = yield original.allInvitations()
+ invitations = yield self.validateInvites(request, invitations)
</ins><span class="cx">
</span><del>- ownerPrincipal = (yield original.ownerPrincipal(request))
</del><ins>+ ownerPrincipal = self.principalForUID(self._newStoreObject.ownerHome().uid())
</ins><span class="cx"> # FIXME: use urn:uuid in all cases
</span><span class="cx"> if self.isCalendarCollection():
</span><span class="cx"> owner = ownerPrincipal.principalURL()
</span><span class="lines">@@ -138,35 +125,13 @@
</span><span class="cx"> yield self._newStoreObject.setShared(False)
</span><span class="cx">
</span><span class="cx"> # Remove all invitees
</span><del>- for invitation in (yield self._allInvitations()):
- yield self.uninviteFromShare(invitation, request)
</del><ins>+ for invitation in (yield self._newStoreObject.allInvitations()):
+ yield self._newStoreObject.uninviteUserFromShare(invitation.shareeUID)
</ins><span class="cx">
</span><span class="cx"> returnValue(True)
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def changeUserInviteState(self, request, inviteUID, shareeUID, state, summary=None):
- if not self.isShared():
- raise HTTPError(ErrorResponse(
- responsecode.FORBIDDEN,
- (customxml.calendarserver_namespace, "valid-request"),
- "Invalid share",
- ))
-
- invitation = yield self._invitationForUID(inviteUID)
- if invitation is None or invitation.shareeUID() != shareeUID:
- raise HTTPError(ErrorResponse(
- responsecode.FORBIDDEN,
- (customxml.calendarserver_namespace, "valid-request"),
- "Invalid invitation uid: %s" % (inviteUID,),
- ))
-
- # Only certain states are owner controlled
- if invitation.status() in (_BIND_STATUS_INVITED, _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED,):
- yield self._updateInvitation(invitation, status=state, summary=summary)
-
-
- @inlineCallbacks
</del><span class="cx"> def directShare(self, request):
</span><span class="cx"> """
</span><span class="cx"> Directly bind an accessible calendar/address book collection into the
</span><span class="lines">@@ -233,11 +198,16 @@
</span><span class="cx"> ))
</span><span class="cx">
</span><span class="cx"> # Accept it
</span><del>- directUID = Share.directUID(shareeHomeResource._newStoreHome, self._newStoreObject)
- response = (yield shareeHomeResource.acceptDirectShare(request, hostURL, directUID, self.displayName()))
</del><ins>+ shareeView = yield self._newStoreObject.directShareWithUser(sharee.principalUID())
</ins><span class="cx">
</span><span class="cx"> # Return the URL of the shared calendar
</span><del>- returnValue(response)
</del><ins>+ sharedAsURL = joinURL(shareeHomeResource.url(), shareeView.name())
+ returnValue(XMLResponse(
+ code=responsecode.OK,
+ element=customxml.SharedAs(
+ element.HRef.fromString(sharedAsURL)
+ )
+ ))
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def isShared(self):
</span><span class="lines">@@ -250,54 +220,34 @@
</span><span class="cx"> return False
</span><span class="cx">
</span><span class="cx">
</span><del>- def setShare(self, share):
</del><ins>+ def setShare(self, share_url):
</ins><span class="cx"> """
</span><del>- Set the L{Share} associated with this L{SharedResourceMixin}. (This
</del><ins>+ Set the URL associated with this L{SharedResourceMixin}. (This
</ins><span class="cx"> is only invoked on the sharee's resource, not the owner's.)
</span><span class="cx"> """
</span><span class="cx"> self._isShareeResource = True
</span><del>- self._share = share
</del><ins>+ self._share_url = share_url
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def isShareeResource(self):
</span><span class="cx"> """
</span><del>- Return True if this is a sharee view of a shared calendar collection.
</del><ins>+ Return True if this is a sharee view of a shared collection.
</ins><span class="cx"> """
</span><del>- return hasattr(self, "_isShareeResource")
</del><ins>+ return (
+ hasattr(self, "_newStoreObject") and
+ hasattr(self._newStoreObject, "owned") and
+ not self._newStoreObject.owned() and
+ getattr(self._newStoreObject, "_bindMode", None) is not None
+ )
</ins><span class="cx">
</span><span class="cx">
</span><del>- @inlineCallbacks
</del><span class="cx"> def removeShareeResource(self, request):
</span><span class="cx"> """
</span><span class="cx"> Called when the sharee DELETEs a shared collection.
</span><span class="cx"> """
</span><ins>+ return self._newStoreObject.deleteShare()
</ins><span class="cx">
</span><del>- sharee = self.principalForUID(self._share.shareeUID())
</del><span class="cx">
</span><del>- # Remove from sharee's calendar/address book home
- if self.isCalendarCollection():
- shareeHome = yield sharee.calendarHome(request)
- elif self.isAddressBookCollection() or self.isGroup():
- shareeHome = yield sharee.addressBookHome(request)
- returnValue((yield shareeHome.removeShare(request, self._share)))
-
-
- def sharedResourceType(self):
- """
- Return the DAV:resourcetype stripped of any shared elements.
- """
-
- if self.isCalendarCollection():
- return "calendar"
- elif self.isAddressBookCollection():
- return "addressbook"
- elif self.isGroup():
- # TODO: Add group xml resource type ?
- return "group"
- else:
- return ""
-
-
</del><span class="cx"> @inlineCallbacks
</span><span class="cx"> def _checkAccessControl(self):
</span><span class="cx"> """
</span><span class="lines">@@ -315,13 +265,12 @@
</span><span class="cx"> access control mechanism has dictate the home should no longer have
</span><span class="cx"> any access at all.
</span><span class="cx"> """
</span><del>- if self._share.direct():
- ownerUID = self._share.ownerUID()
- owner = self.principalForUID(ownerUID)
</del><ins>+ if self._newStoreObject.direct():
+ owner = self.principalForUID(self._newStoreObject.ownerHome().uid())
</ins><span class="cx"> if owner.record.recordType == WikiDirectoryService.recordType_wikis:
</span><span class="cx"> # Access level comes from what the wiki has granted to the
</span><span class="cx"> # sharee
</span><del>- sharee = self.principalForUID(self._share.shareeUID())
</del><ins>+ sharee = self.principalForUID(self._newStoreObject.viewerHome().uid())
</ins><span class="cx"> userID = sharee.record.guid
</span><span class="cx"> wikiID = owner.record.shortNames[0]
</span><span class="cx"> access = (yield getWikiAccess(userID, wikiID))
</span><span class="lines">@@ -366,13 +315,12 @@
</span><span class="cx"> assert self._isShareeResource, "Only call this for a sharee resource"
</span><span class="cx"> assert self.isCalendarCollection() or self.isAddressBookCollection(), "Only call this for a address book or calendar resource"
</span><span class="cx">
</span><del>- sharee = self.principalForUID(self._share.shareeUID())
</del><ins>+ sharee = self.principalForUID(self._newStoreObject.viewerHome().uid())
</ins><span class="cx"> access = yield self._checkAccessControl()
</span><span class="cx">
</span><span class="cx"> if access == "original":
</span><del>- original = (yield request.locateResource(self._share.url()))
- result = (yield original.accessControlList(request, *args,
- **kwargs))
</del><ins>+ original = (yield request.locateResource(self._share_url))
+ result = (yield original.accessControlList(request, *args, **kwargs))
</ins><span class="cx"> returnValue(result)
</span><span class="cx">
</span><span class="cx"> # Direct shares use underlying privileges of shared collection
</span><span class="lines">@@ -476,18 +424,17 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def validateInvites(self, request):
</del><ins>+ def validateInvites(self, request, invitations=None):
</ins><span class="cx"> """
</span><span class="cx"> Make sure each userid in an invite is valid - if not re-write status.
</span><span class="cx"> """
</span><span class="cx"> # assert request
</span><del>- invitations = yield self._allInvitations()
</del><ins>+ if invitations is None:
+ invitations = yield self._newStoreObject.allInvitations()
</ins><span class="cx"> for invitation in invitations:
</span><del>- if invitation.status() != _BIND_STATUS_INVALID:
- if not (yield self.validUserIDForShare("urn:uuid:" + invitation.shareeUID(), request)):
- # FIXME: temporarily disable this to deal with flaky directory
- #yield self._updateInvitation(invitation, status=_BIND_STATUS_INVALID)
- self.log.error("Invalid sharee detected: {uid}", uid=invitation.shareeUID())
</del><ins>+ if invitation.status != _BIND_STATUS_INVALID:
+ if not (yield self.validUserIDForShare("urn:uuid:" + invitation.shareeUID, request)):
+ self.log.error("Invalid sharee detected: {uid}", uid=invitation.shareeUID)
</ins><span class="cx">
</span><span class="cx"> returnValue(invitations)
</span><span class="cx">
</span><span class="lines">@@ -549,78 +496,6 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def _createInvitation(self, shareeUID, mode, summary,):
- """
- Create a new homeChild and wrap it in an Invitation
- """
- if self.isCalendarCollection():
- shareeHome = yield self._newStoreObject._txn.calendarHomeWithUID(shareeUID, create=True)
- elif self.isAddressBookCollection() or self.isGroup():
- shareeHome = yield self._newStoreObject._txn.addressbookHomeWithUID(shareeUID, create=True)
-
- shareUID = yield self._newStoreObject.shareWith(shareeHome,
- mode=mode,
- status=_BIND_STATUS_INVITED,
- message=summary)
- shareeStoreObject = yield shareeHome.invitedObjectWithShareUID(shareUID)
- invitation = SharingInvitation.fromCommonHomeChild(shareeStoreObject)
- returnValue(invitation)
-
-
- @inlineCallbacks
- def _updateInvitation(self, invitation, mode=None, status=None, summary=None):
- yield self._newStoreObject.updateShareFromSharingInvitation(invitation, mode=mode, status=status, message=summary)
- if mode is not None:
- invitation.setMode(mode)
- if status is not None:
- invitation.setStatus(status)
- if summary is not None:
- invitation.setSummary(summary)
-
-
- @inlineCallbacks
- def _allInvitations(self):
- """
- Get list of all invitations (non-direct) to this object.
- """
- if not self.exists():
- returnValue([])
-
- invitations = yield self._newStoreObject.sharingInvites()
-
- # remove direct shares as those are not "real" invitations
- invitations = filter(lambda x: x.mode() != _BIND_MODE_DIRECT, invitations)
-
- invitations.sort(key=lambda invitation: invitation.shareeUID())
-
- returnValue(invitations)
-
-
- @inlineCallbacks
- def _invitationForShareeUID(self, shareeUID):
- """
- Get an invitation for this sharee principal UID
- """
- invitations = yield self._allInvitations()
- for invitation in invitations:
- if invitation.shareeUID() == shareeUID:
- returnValue(invitation)
- returnValue(None)
-
-
- @inlineCallbacks
- def _invitationForUID(self, uid):
- """
- Get an invitation for an invitations uid
- """
- invitations = yield self._allInvitations()
- for invitation in invitations:
- if invitation.uid() == uid:
- returnValue(invitation)
- returnValue(None)
-
-
- @inlineCallbacks
</del><span class="cx"> def inviteSingleUserToShare(self, userid, cn, ace, summary, request): #@UnusedVariable
</span><span class="cx">
</span><span class="cx"> # We currently only handle local users
</span><span class="lines">@@ -628,71 +503,32 @@
</span><span class="cx"> if not sharee:
</span><span class="cx"> returnValue(False)
</span><span class="cx">
</span><del>- shareeUID = sharee.principalUID()
</del><ins>+ result = (yield self._newStoreObject.inviteUserToShare(
+ sharee.principalUID(),
+ invitationBindModeFromXMLMap[type(ace)],
+ summary,
+ ))
</ins><span class="cx">
</span><del>- # Look for existing invite and update its fields or create new one
- invitation = yield self._invitationForShareeUID(shareeUID)
- if invitation:
- status = _BIND_STATUS_INVITED if invitation.status() in (_BIND_STATUS_DECLINED, _BIND_STATUS_INVALID) else None
- yield self._updateInvitation(invitation, mode=invitationBindModeFromXMLMap[type(ace)], status=status, summary=summary)
- else:
- invitation = yield self._createInvitation(
- shareeUID=shareeUID,
- mode=invitationBindModeFromXMLMap[type(ace)],
- summary=summary)
- # Send invite notification
- yield self.sendInviteNotification(invitation, request)
</del><ins>+ returnValue(result)
</ins><span class="cx">
</span><del>- returnValue(True)
</del><span class="cx">
</span><del>-
</del><span class="cx"> @inlineCallbacks
</span><span class="cx"> def uninviteSingleUserFromShare(self, userid, aces, request): #@UnusedVariable
</span><del>- # Cancel invites - we'll just use whatever userid we are given
</del><span class="cx">
</span><ins>+ # Cancel invites - we'll just use whatever userid we are given
</ins><span class="cx"> sharee = self.principalForCalendarUserAddress(userid)
</span><span class="cx"> if not sharee:
</span><span class="cx"> returnValue(False)
</span><span class="cx">
</span><del>- shareeUID = sharee.principalUID()
</del><ins>+ result = (yield self._newStoreObject.uninviteUserFromShare(sharee.principalUID()))
</ins><span class="cx">
</span><del>- invitation = yield self._invitationForShareeUID(shareeUID)
- if invitation:
- result = (yield self.uninviteFromShare(invitation, request))
- else:
- result = False
-
</del><span class="cx"> returnValue(result)
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def uninviteFromShare(self, invitation, request):
</span><span class="cx">
</span><del>- # Remove any shared calendar or address book
- sharee = self.principalForUID(invitation.shareeUID())
- if sharee:
- previousInvitationStatus = invitation.status()
- displayName = None
- if self.isCalendarCollection():
- shareeHomeResource = yield sharee.calendarHome(request)
- if shareeHomeResource is not None:
- displayName = yield shareeHomeResource.removeShareByUID(request, invitation.uid())
- elif self.isAddressBookCollection() or self.isGroup():
- shareeHomeResource = yield sharee.addressBookHome(request)
- if shareeHomeResource is not None:
- yield shareeHomeResource.removeShareByUID(request, invitation.uid())
-
- # If current user state is accepted then we send an invite with the new state, otherwise
- # we cancel any existing invites for the user
- if shareeHomeResource is not None:
- if previousInvitationStatus != _BIND_STATUS_ACCEPTED:
- yield self.removeInviteNotification(invitation, request)
- else:
- yield self.sendInviteNotification(invitation, request, displayName=displayName, notificationState="DELETED")
-
- # Direct shares for with valid sharee principal will already be deleted
- yield self._newStoreObject.unshareWithUID(invitation.shareeUID())
-
</del><ins>+ yield self._newStoreObject.uninviteFromShare(invitation)
</ins><span class="cx"> returnValue(True)
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -703,81 +539,6 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def sendInviteNotification(self, invitation, request, notificationState=None, displayName=None):
-
- ownerPrincipal = (yield self.ownerPrincipal(request))
- # FIXME: use urn:uuid in all cases
- if self.isCalendarCollection():
- owner = ownerPrincipal.principalURL()
- else:
- owner = "urn:uuid:" + ownerPrincipal.principalUID()
- ownerCN = ownerPrincipal.displayName()
- hosturl = (yield self.canonicalURL(request))
-
- # Locate notifications collection for user
- sharee = self.principalForUID(invitation.shareeUID())
- if sharee is None:
- raise ValueError("sharee is None but principalUID was valid before")
-
- # We need to look up the resource so that the response cache notifier is properly initialized
- notificationResource = (yield request.locateResource(sharee.notificationURL()))
- notifications = notificationResource._newStoreNotifications
-
- '''
- # Look for existing notification
- # oldnotification is not used don't query for it
- oldnotification = (yield notifications.notificationObjectWithUID(invitation.uid()))
- if oldnotification:
- # TODO: rollup changes?
- pass
- '''
-
- # Generate invite XML
- userid = "urn:uuid:" + invitation.shareeUID()
- state = notificationState if notificationState else invitation.status()
- summary = invitation.summary() if displayName is None else displayName
-
- typeAttr = {'shared-type': self.sharedResourceType()}
- xmltype = customxml.InviteNotification(**typeAttr)
- xmldata = customxml.Notification(
- customxml.DTStamp.fromString(DateTime.getNowUTC().getText()),
- customxml.InviteNotification(
- customxml.UID.fromString(invitation.uid()),
- element.HRef.fromString(userid),
- invitationBindStatusToXMLMap[state](),
- customxml.InviteAccess(invitationBindModeToXMLMap[invitation.mode()]()),
- customxml.HostURL(
- element.HRef.fromString(hosturl),
- ),
- customxml.Organizer(
- element.HRef.fromString(owner),
- customxml.CommonName.fromString(ownerCN),
- ),
- customxml.InviteSummary.fromString(summary),
- self.getSupportedComponentSet() if self.isCalendarCollection() else None,
- **typeAttr
- ),
- ).toxml()
-
- # Add to collections
- yield notifications.writeNotificationObject(invitation.uid(), xmltype, xmldata)
-
-
- @inlineCallbacks
- def removeInviteNotification(self, invitation, request):
-
- # Locate notifications collection for user
- sharee = self.principalForUID(invitation.shareeUID())
- if sharee is None:
- raise ValueError("sharee is None but principalUID was valid before")
- notificationResource = (yield request.locateResource(sharee.notificationURL()))
- notifications = notificationResource._newStoreNotifications
-
- # Add to collections
- yield notifications.removeNotificationObjectWithUID(invitation.uid())
-
-
- @inlineCallbacks
</del><span class="cx"> def _xmlHandleInvite(self, request, docroot):
</span><span class="cx"> yield self.authorize(request, (element.Read(), element.Write()))
</span><span class="cx"> result = (yield self._handleInvite(request, docroot))
</span><span class="lines">@@ -995,7 +756,7 @@
</span><span class="cx"> _BIND_STATUS_ACCEPTED : customxml.InviteStatusAccepted,
</span><span class="cx"> _BIND_STATUS_DECLINED : customxml.InviteStatusDeclined,
</span><span class="cx"> _BIND_STATUS_INVALID : customxml.InviteStatusInvalid,
</span><del>- "DELETED" : customxml.InviteStatusDeleted,
</del><ins>+ _BIND_STATUS_DELETED : customxml.InviteStatusDeleted,
</ins><span class="cx"> }
</span><span class="cx"> invitationBindStatusFromXMLMap = dict((v, k) for k, v in invitationBindStatusToXMLMap.iteritems())
</span><span class="cx">
</span><span class="lines">@@ -1005,12 +766,13 @@
</span><span class="cx"> }
</span><span class="cx"> invitationBindModeFromXMLMap = dict((v, k) for k, v in invitationBindModeToXMLMap.iteritems())
</span><span class="cx">
</span><del>-invitationAccessToBindModeMap = {
- "own": _BIND_MODE_OWN,
- "read-only": _BIND_MODE_READ,
- "read-write": _BIND_MODE_WRITE,
- }
-invitationAccessFromBindModeMap = dict((v, k) for k, v in invitationAccessToBindModeMap.iteritems())
</del><ins>+invitationAccessFromBindModeMap = {
+ _BIND_MODE_OWN: "own",
+ _BIND_MODE_READ: "read-only",
+ _BIND_MODE_WRITE: "read-write",
+ _BIND_MODE_DIRECT: "read-write",
+ _BIND_MODE_INDIRECT: "read-write",
+}
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> class SharedHomeMixin(LinkFollowerMixIn):
</span><span class="lines">@@ -1022,219 +784,30 @@
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def provisionShare(self, child, request=None):
</span><span class="cx"> """
</span><del>- If the given child resource (a L{SharedResourceMixin}) of this
- L{SharedHomeMixin} is a I{sharee}'s view of a shared calendar object,
- associate it with a L{Share}.
</del><ins>+ Set shared state and check access control.
</ins><span class="cx"> """
</span><del>- share = yield self._shareForStoreObject(child._newStoreObject, request)
- if share:
- child.setShare(share)
</del><ins>+ if child._newStoreObject is not None and not child._newStoreObject.owned():
+ ownerHomeURL = self._otherPrincipalHomeURL(child._newStoreObject.ownerHome().uid())
+ ownerView = yield child._newStoreObject.ownerView()
+ child.setShare(joinURL(ownerHomeURL, ownerView.name()))
</ins><span class="cx"> access = yield child._checkAccessControl()
</span><span class="cx"> if access is None:
</span><span class="cx"> returnValue(None)
</span><span class="cx"> returnValue(child)
</span><span class="cx">
</span><span class="cx">
</span><del>- @inlineCallbacks
- def _shareForStoreObject(self, storeObject, request=None):
- """
- Determine the L{Share} associated with the given child.
</del><ins>+ def _otherPrincipalHomeURL(self, otherUID):
+ pass
</ins><span class="cx">
</span><del>- @param child: A calendar or addressbook data store object, a child of
- the resource represented by this L{SharedHomeMixin} instance, which
- may be shared.
- @type child: L{txdav.caldav.icalendarstore.ICalendar} or
- L{txdav.carddav.iaddressbookstore.IAddressBook}
</del><span class="cx">
</span><del>- @return: a L{Share} if C{child} is not the owner's view of the share,
- or C{None}.
- @rtype: L{Share} or L{NoneType}
- """
- # Find a matching share
- # use "storeObject.shareUID is not None" to prevent partially shared address books form getting a share
- if storeObject is None or storeObject.owned():
- returnValue(None)
-
- # Get the shared object's URL - we may need to fake this if the sharer principal is missing or disabled
- url = None
- owner = self.principalForUID(storeObject.ownerHome().uid())
- from twistedcaldav.directory.principal import DirectoryCalendarPrincipalResource
- if isinstance(owner, DirectoryCalendarPrincipalResource):
-
- if not request:
- # FIXEME: Fake up a request that can be used to get the owner home resource
- class _FakeRequest(object):
- pass
- fakeRequest = _FakeRequest()
- setattr(fakeRequest, TRANSACTION_KEY, self._newStoreHome._txn)
- request = fakeRequest
-
- if self._newStoreHome._homeType == ECALENDARTYPE:
- ownerHomeCollection = yield owner.calendarHome(request)
- elif self._newStoreHome._homeType == EADDRESSBOOKTYPE:
- ownerHomeCollection = yield owner.addressBookHome(request)
-
- if ownerHomeCollection is not None:
- url = ownerHomeCollection.url()
-
- if url is None:
- url = "/calendars/__uids__/%s/" % (storeObject.ownerHome().uid(),)
-
- ownerHomeChild = yield storeObject.ownerHome().childWithID(storeObject._resourceID)
- if ownerHomeChild:
- assert ownerHomeChild != storeObject
- url = joinURL(url, ownerHomeChild.name())
- share = Share(shareeStoreObject=storeObject, ownerStoreObject=ownerHomeChild, url=url)
- else:
- for ownerHomeChild in (yield storeObject.ownerHome().children()):
- if ownerHomeChild.owned():
- sharedGroup = yield ownerHomeChild.objectResourceWithID(storeObject._resourceID)
- if sharedGroup:
- url = joinURL(url, ownerHomeChild.name(), sharedGroup.name())
- share = Share(shareeStoreObject=storeObject, ownerStoreObject=sharedGroup, url=url)
- break
-
- returnValue(share)
-
-
</del><span class="cx"> @inlineCallbacks
</span><del>- def _shareForUID(self, shareUID, request):
</del><ins>+ def acceptShare(self, request, inviteUID, summary):
</ins><span class="cx">
</span><del>- if shareUID is not None: # shareUID may be None for partially shared addressbooks
- shareeStoreObject = yield self._newStoreHome.objectWithShareUID(shareUID)
- if shareeStoreObject:
- share = yield self._shareForStoreObject(shareeStoreObject, request)
- if share:
- returnValue(share)
</del><ins>+ # Accept the share
+ shareeView = yield self._newStoreHome.acceptShare(inviteUID, summary)
</ins><span class="cx">
</span><del>- # find direct shares
- children = yield self._newStoreHome.children()
- for child in children:
- share = yield self._shareForStoreObject(child, request)
- if share and share.uid() == shareUID:
- returnValue(share)
-
- returnValue(None)
-
-
- @inlineCallbacks
- def acceptInviteShare(self, request, hostUrl, inviteUID, displayname=None):
-
- # Check for old share
- oldShare = yield self._shareForUID(inviteUID, request)
-
- # Send the invite reply then add the link
- yield self._changeShare(request, _BIND_STATUS_ACCEPTED, hostUrl, inviteUID, displayname)
- if oldShare:
- share = oldShare
- else:
- sharedResource = yield request.locateResource(hostUrl)
- shareeStoreObject = yield self._newStoreHome.objectWithShareUID(inviteUID)
-
- share = Share(shareeStoreObject=shareeStoreObject,
- ownerStoreObject=sharedResource._newStoreObject,
- url=hostUrl)
-
- response = yield self._acceptShare(request, not oldShare, share, displayname)
- returnValue(response)
-
-
- @inlineCallbacks
- def acceptDirectShare(self, request, hostUrl, resourceUID,
- displayname=None):
-
- # Just add the link
- oldShare = yield self._shareForUID(resourceUID, request)
- if oldShare:
- share = oldShare
- else:
- sharedCollection = yield request.locateResource(hostUrl)
- shareUID = yield sharedCollection._newStoreObject.shareWith(
- shareeHome=self._newStoreHome,
- mode=_BIND_MODE_DIRECT,
- status=_BIND_STATUS_ACCEPTED,
- message=displayname
- )
-
- shareeStoreObject = yield self._newStoreHome.objectWithShareUID(shareUID)
- share = Share(shareeStoreObject=shareeStoreObject,
- ownerStoreObject=sharedCollection._newStoreObject,
- url=hostUrl)
-
- response = yield self._acceptShare(request, not oldShare, share, displayname)
- returnValue(response)
-
-
- @inlineCallbacks
- def _acceptShare(self, request, isNewShare, share, displayname=None):
- """
- Mark a pending shared invitation I{to} this, the owner's collection, as
- accepted, generating the HTTP response to the request that accepted it.
-
- @param request: The HTTP request that is accepting it.
- @type request: L{twext.web2.iweb.IRequest}
-
- @param isNewShare: a boolean indicating whether this share is new.
- @type isNewShare: L{bool}
-
- @param share: The share referencing the proposed sharer and sharee.
- @type share: L{Share}
-
- @param displayname: the UTF-8 encoded contents of the display-name
- property on the resource to be created while accepting.
- @type displayname: L{bytes}
-
- @return: a L{twext.web2.iweb.IResponse} containing a serialized
- L{customxml.SharedAs} element as its body.
- @rtype: L{Deferred} firing L{XMLResponse}
- """
- # Get shared collection in non-share mode first
- sharedResource = yield request.locateResource(share.url())
- sharee = self.principalForUID(share.shareeUID())
-
- if sharedResource.isCalendarCollection():
- shareeHomeResource = yield sharee.calendarHome(request)
- sharedAsURL = joinURL(shareeHomeResource.url(), share.name())
- shareeCalender = yield request.locateResource(sharedAsURL)
- shareeCalender.setShare(share)
-
- # For calendars only, per-user displayname and color
- if displayname:
- yield shareeCalender.writeProperty(element.DisplayName.fromString(displayname), request)
-
- if isNewShare:
- # For a direct share we will copy any calendar-color over using the owners view
- if share.direct():
- try:
- color = yield sharedResource.readProperty(customxml.CalendarColor, request)
- except HTTPError:
- color = None
- if color:
- yield shareeCalender.writeProperty(customxml.CalendarColor.fromString(color), request)
-
- # Calendars always start out transparent and with empty default alarms
- yield shareeCalender._newStoreObject.setUsedForFreeBusy(False)
- yield shareeCalender._newStoreObject.setDefaultAlarm("empty", True, True)
- yield shareeCalender._newStoreObject.setDefaultAlarm("empty", True, False)
- yield shareeCalender._newStoreObject.setDefaultAlarm("empty", False, True)
- yield shareeCalender._newStoreObject.setDefaultAlarm("empty", False, False)
-
- elif sharedResource.isAddressBookCollection():
- shareeHomeResource = yield sharee.addressBookHome(request)
- sharedAsURL = joinURL(shareeHomeResource.url(), share.ownerUID())
- shareeAddressBook = yield request.locateResource(sharedAsURL)
- shareeAddressBook.setShare(share)
-
- elif sharedResource.isGroup():
- shareeHomeResource = yield sharee.addressBookHome(request)
- sharedAsURL = joinURL(shareeHomeResource.url(), share.ownerUID(), share.name())
- shareeGroup = yield request.locateResource(sharedAsURL)
- shareeGroup.setShare(share)
-
- # Notify client of changes
- yield self.notifyChanged()
-
</del><span class="cx"> # Return the URL of the shared collection
</span><ins>+ sharedAsURL = joinURL(self.url(), shareeView.shareName())
</ins><span class="cx"> returnValue(XMLResponse(
</span><span class="cx"> code=responsecode.OK,
</span><span class="cx"> element=customxml.SharedAs(
</span><span class="lines">@@ -1244,146 +817,13 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def removeShare(self, request, share):
- """
- Remove a shared collection named in resourceName
- """
</del><ins>+ def declineShare(self, request, inviteUID):
</ins><span class="cx">
</span><del>- if share.direct():
- yield self.removeDirectShare(request, share)
- returnValue(None)
- else:
- # Send a decline when an invite share is removed only
- result = yield self.declineShare(request, share.url(), share.uid())
- returnValue(result)
-
-
- @inlineCallbacks
- def removeShareByUID(self, request, shareUID):
- """
- Remove a shared collection but do not send a decline back. Return the
- current display name of the shared collection.
- """
-
- share = yield self._shareForUID(shareUID, request)
- if share:
- displayName = (yield self.removeDirectShare(request, share))
- returnValue(displayName)
- else:
- returnValue(None)
-
-
- @inlineCallbacks
- def removeDirectShare(self, request, share):
- """
- Remove a shared collection but do not send a decline back. Return the
- current display name of the shared collection.
- """
- # FIXME: only works for calendar
- shareURL = joinURL(self.url(), share.name())
- shared = (yield request.locateResource(shareURL))
- displayname = shared.displayName()
-
- if share.direct():
- yield share._ownerStoreObject.unshareWith(share._shareeStoreObject.viewerHome())
- else:
- yield share._ownerStoreObject.updateShare(share._shareeStoreObject, status=_BIND_STATUS_DECLINED)
-
- returnValue(displayname)
-
-
- @inlineCallbacks
- def declineShare(self, request, hostUrl, inviteUID):
-
</del><span class="cx"> # Remove it if it is in the DB
</span><del>- yield self.removeShareByUID(request, inviteUID)
- yield self._changeShare(request, _BIND_STATUS_DECLINED, hostUrl, inviteUID, processed=True)
</del><ins>+ yield self._newStoreHome.declineShare(inviteUID)
</ins><span class="cx"> returnValue(Response(code=responsecode.NO_CONTENT))
</span><span class="cx">
</span><span class="cx">
</span><del>- @inlineCallbacks
- def _changeShare(self, request, state, hostUrl, replytoUID, displayname=None, processed=False):
- """
- Accept or decline an invite to a shared collection.
- """
- # Change state in owner invite
- ownerPrincipal = (yield self.ownerPrincipal(request))
- ownerPrincipalUID = ownerPrincipal.principalUID()
- sharedResource = (yield request.locateResource(hostUrl))
- if sharedResource is None:
- # FIXME: have to return here rather than raise to allow removal of a share for a sharer
- # whose principal is no longer valid yet still exists in the store. Really we need to get rid of
- # locateResource calls and just do everything via store objects.
- returnValue(None)
- # Original shared collection is gone - nothing we can do except ignore it
- raise HTTPError(ErrorResponse(
- responsecode.FORBIDDEN,
- (customxml.calendarserver_namespace, "valid-request"),
- "Invalid shared collection",
- ))
-
- # Change the record
- if not processed:
- yield sharedResource.changeUserInviteState(request, replytoUID, ownerPrincipalUID, state, displayname)
-
- yield self.sendReply(request, ownerPrincipal, sharedResource, state, hostUrl, replytoUID, displayname)
-
-
- @inlineCallbacks
- def sendReply(self, request, shareePrincipal, sharedResource, state, hostUrl, replytoUID, displayname=None):
-
- # Locate notifications collection for owner
- owner = (yield sharedResource.ownerPrincipal(request))
- if owner is None:
- # FIXME: have to return here rather than raise to allow removal of a share for a sharer
- # whose principal is no longer valid yet still exists in the store. Really we need to get rid of
- # locateResource calls and just do everything via store objects.
- returnValue(None)
-
- notificationResource = (yield request.locateResource(owner.notificationURL()))
- notifications = notificationResource._newStoreNotifications
-
- # Generate invite XML
- notificationUID = "%s-reply" % (replytoUID,)
- xmltype = customxml.InviteReply()
-
- # FIXME: use urn:uuid in all cases
- if self._newStoreHome and self._newStoreHome._homeType == EADDRESSBOOKTYPE:
- cua = "urn:uuid:" + shareePrincipal.principalUID()
- else:
- # Prefer mailto:, otherwise use principal URL
- for cua in shareePrincipal.calendarUserAddresses():
- if cua.startswith("mailto:"):
- break
- else:
- cua = shareePrincipal.principalURL()
-
- commonName = shareePrincipal.displayName()
- record = shareePrincipal.record
-
- xmldata = customxml.Notification(
- customxml.DTStamp.fromString(DateTime.getNowUTC().getText()),
- customxml.InviteReply(
- *(
- (
- element.HRef.fromString(cua),
- invitationBindStatusToXMLMap[state](),
- customxml.HostURL(
- element.HRef.fromString(hostUrl),
- ),
- customxml.InReplyTo.fromString(replytoUID),
- ) + ((customxml.InviteSummary.fromString(displayname),) if displayname is not None else ())
- + ((customxml.CommonName.fromString(commonName),) if commonName is not None else ())
- + ((customxml.FirstNameProperty(record.firstName),) if record.firstName is not None else ())
- + ((customxml.LastNameProperty(record.lastName),) if record.lastName is not None else ())
- )
- ),
- ).toxml()
-
- # Add to collections
- yield notifications.writeNotificationObject(notificationUID, xmltype, xmldata)
-
-
</del><span class="cx"> def _handleInviteReply(self, request, invitereplydoc):
</span><span class="cx"> """
</span><span class="cx"> Handle a user accepting or declining a sharing invite
</span><span class="lines">@@ -1413,80 +853,6 @@
</span><span class="cx"> "Missing required XML elements",
</span><span class="cx"> ))
</span><span class="cx"> if accepted:
</span><del>- return self.acceptInviteShare(request, hostUrl, replytoUID, displayname=summary)
</del><ins>+ return self.acceptShare(request, replytoUID, summary=summary)
</ins><span class="cx"> else:
</span><del>- return self.declineShare(request, hostUrl, replytoUID)
-
-
-
-class Share(object):
- """
- A L{Share} represents information about a collection which has been shared
- from one user to another.
- """
-
- def __init__(self, ownerStoreObject, shareeStoreObject, url):
- """
- @param sharerHomeChild: The data store object representing the shared
- collection as present in the owner's home collection; the owner's
- reference.
- @type sharerHomeChild: L{txdav.caldav.icalendarstore.ICalendar}
-
- @param shareeHomeChild: The data store object representing the
- collection as present in the sharee's home collection; the sharee's
- reference.
- @type shareeHomeChild: L{txdav.caldav.icalendarstore.ICalendar}
-
- @param url: The URL referring to the sharer's version of the resource.
- @type url: L{bytes}
- """
- self._shareeStoreObject = shareeStoreObject
- self._ownerStoreObject = ownerStoreObject
- self._ownerResourceURL = url
-
-
- @classmethod
- def directUID(cls, shareeHome, ownerHomeChild):
- return "Direct-%s-%s" % (shareeHome._resourceID,
- ownerHomeChild._resourceID,)
-
-
- def uid(self):
- # Move to CommonHomeChild shareUID?
- if self._shareeStoreObject.shareMode() == _BIND_MODE_DIRECT:
- return self.directUID(shareeHome=self._shareeStoreObject.viewerHome(),
- ownerHomeChild=self._ownerStoreObject,)
- else:
- return self._shareeStoreObject.shareUID()
-
-
- def direct(self):
- """
- Is this L{Share} a "direct" share?
-
- @return: a boolean indicating whether it's direct.
- """
- return self._shareeStoreObject.shareMode() == _BIND_MODE_DIRECT
-
-
- def url(self):
- """
- @return: The URL to the owner's version of the shared collection.
- """
- return self._ownerResourceURL
-
-
- def name(self):
- return self._shareeStoreObject.name()
-
-
- def summary(self):
- return self._shareeStoreObject.shareMessage()
-
-
- def shareeUID(self):
- return self._shareeStoreObject.viewerHome().uid()
-
-
- def ownerUID(self):
- return self._shareeStoreObject.ownerHome().uid()
</del><ins>+ return self.declineShare(request, replytoUID)
</ins></span></pre></div>
<a id="CalendarServertrunktwistedcaldavstorebridgepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/storebridge.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/storebridge.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/twistedcaldav/storebridge.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -70,10 +70,10 @@
</span><span class="cx"> UIDExistsElsewhereError, InvalidUIDError, InvalidResourceMove, \
</span><span class="cx"> InvalidComponentForStoreError
</span><span class="cx"> from txdav.idav import PropertyChangeNotAllowedError
</span><del>-from txdav.xml import element as davxml
</del><ins>+from txdav.xml import element as davxml, element
</ins><span class="cx"> from txdav.xml.base import dav_namespace, WebDAVUnknownElement, encodeXMLName
</span><span class="cx">
</span><del>-from urlparse import urlsplit
</del><ins>+from urlparse import urlsplit, urljoin
</ins><span class="cx"> import hashlib
</span><span class="cx"> import time
</span><span class="cx"> import uuid
</span><span class="lines">@@ -84,6 +84,8 @@
</span><span class="cx"> TooManyInstancesError
</span><span class="cx"> from twistedcaldav.util import bestAcceptType
</span><span class="cx"> import collections
</span><ins>+from twistedcaldav.sharing import invitationBindStatusToXMLMap, \
+ invitationBindModeToXMLMap
</ins><span class="cx">
</span><span class="cx"> """
</span><span class="cx"> Wrappers to translate between the APIs in L{txdav.caldav.icalendarstore} and
</span><span class="lines">@@ -275,7 +277,7 @@
</span><span class="cx">
</span><span class="cx"> def owner_url(self):
</span><span class="cx"> if self.isShareeResource():
</span><del>- return joinURL(self._share.url(), "/")
</del><ins>+ return joinURL(self._share_url, "/")
</ins><span class="cx"> else:
</span><span class="cx"> return self.url()
</span><span class="cx">
</span><span class="lines">@@ -1640,23 +1642,23 @@
</span><span class="cx"> for invite in invites:
</span><span class="cx">
</span><span class="cx"> # Only want accepted invites
</span><del>- if invite.status() != _BIND_STATUS_ACCEPTED:
</del><ins>+ if invite.status != _BIND_STATUS_ACCEPTED:
</ins><span class="cx"> continue
</span><span class="cx">
</span><span class="cx"> userprivs = [
</span><span class="cx"> ]
</span><del>- if invite.mode() in (_BIND_MODE_READ, _BIND_MODE_WRITE,):
</del><ins>+ if invite.mode in (_BIND_MODE_READ, _BIND_MODE_WRITE,):
</ins><span class="cx"> userprivs.append(davxml.Privilege(davxml.Read()))
</span><span class="cx"> userprivs.append(davxml.Privilege(davxml.ReadACL()))
</span><span class="cx"> userprivs.append(davxml.Privilege(davxml.ReadCurrentUserPrivilegeSet()))
</span><del>- if invite.mode() in (_BIND_MODE_READ,):
</del><ins>+ if invite.mode in (_BIND_MODE_READ,):
</ins><span class="cx"> userprivs.append(davxml.Privilege(davxml.WriteProperties()))
</span><del>- if invite.mode() in (_BIND_MODE_WRITE,):
</del><ins>+ if invite.mode in (_BIND_MODE_WRITE,):
</ins><span class="cx"> userprivs.append(davxml.Privilege(davxml.Write()))
</span><span class="cx"> proxyprivs = list(userprivs)
</span><span class="cx"> proxyprivs.remove(davxml.Privilege(davxml.ReadACL()))
</span><span class="cx">
</span><del>- principal = self.principalForUID(invite.shareeUID())
</del><ins>+ principal = self.principalForUID(invite.shareeUID)
</ins><span class="cx"> aces += (
</span><span class="cx"> # Inheritable specific access for the resource's associated principal.
</span><span class="cx"> davxml.ACE(
</span><span class="lines">@@ -1951,10 +1953,10 @@
</span><span class="cx"> access control mechanism has dictate the home should no longer have
</span><span class="cx"> any access at all.
</span><span class="cx"> """
</span><del>- if invite.mode() in (_BIND_MODE_DIRECT,):
- ownerUID = invite.ownerUID()
</del><ins>+ if invite.mode in (_BIND_MODE_DIRECT,):
+ ownerUID = invite.ownerUID
</ins><span class="cx"> owner = self.principalForUID(ownerUID)
</span><del>- shareeUID = invite.shareeUID()
</del><ins>+ shareeUID = invite.shareeUID
</ins><span class="cx"> if owner.record.recordType == WikiDirectoryService.recordType_wikis:
</span><span class="cx"> # Access level comes from what the wiki has granted to the
</span><span class="cx"> # sharee
</span><span class="lines">@@ -1970,9 +1972,9 @@
</span><span class="cx"> returnValue(None)
</span><span class="cx"> else:
</span><span class="cx"> returnValue("original")
</span><del>- elif invite.mode() in (_BIND_MODE_READ,):
</del><ins>+ elif invite.mode in (_BIND_MODE_READ,):
</ins><span class="cx"> returnValue("read-only")
</span><del>- elif invite.mode() in (_BIND_MODE_WRITE,):
</del><ins>+ elif invite.mode in (_BIND_MODE_WRITE,):
</ins><span class="cx"> returnValue("read-write")
</span><span class="cx"> returnValue("original")
</span><span class="cx">
</span><span class="lines">@@ -1985,7 +1987,7 @@
</span><span class="cx"> for invite in invites:
</span><span class="cx">
</span><span class="cx"> # Only want accepted invites
</span><del>- if invite.status() != _BIND_STATUS_ACCEPTED:
</del><ins>+ if invite.status != _BIND_STATUS_ACCEPTED:
</ins><span class="cx"> continue
</span><span class="cx">
</span><span class="cx"> privileges = [
</span><span class="lines">@@ -1997,7 +1999,7 @@
</span><span class="cx"> if access in ("read-only", "read-write",):
</span><span class="cx"> userprivs.extend(privileges)
</span><span class="cx">
</span><del>- principal = self.principalForUID(invite.shareeUID())
</del><ins>+ principal = self.principalForUID(invite.shareeUID)
</ins><span class="cx"> aces += (
</span><span class="cx"> # Inheritable specific access for the resource's associated principal.
</span><span class="cx"> davxml.ACE(
</span><span class="lines">@@ -3108,29 +3110,12 @@
</span><span class="cx"> call super and provision group share
</span><span class="cx"> """
</span><span class="cx"> abObjectResource = yield super(AddressBookCollectionResource, self).makeChild(name)
</span><del>- if abObjectResource.exists() and abObjectResource._newStoreObject.shareUID() is not None:
- abObjectResource = yield self.parentResource().provisionShare(abObjectResource)
</del><ins>+ #if abObjectResource.exists() and abObjectResource._newStoreObject.shareUID() is not None:
+ # abObjectResource = yield self.parentResource().provisionShare(abObjectResource)
</ins><span class="cx"> returnValue(abObjectResource)
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def storeRemove(self, request):
- """
- handle remove of partially shared addressbook, else call super
- """
- if self.isShareeResource() and self._newStoreObject.shareUID() is None:
- log.debug("Removing shared collection %s" % (self,))
- for childname in (yield self.listChildren()):
- child = (yield request.locateChildResource(self, childname))
- if child.isShareeResource():
- yield child.storeRemove(request)
-
- returnValue(NO_CONTENT)
-
- returnValue((yield super(AddressBookCollectionResource, self).storeRemove(request)))
-
-
- @inlineCallbacks
</del><span class="cx"> def bulkCreate(self, indexedComponents, request, return_changed, xmlresponses, format):
</span><span class="cx"> """
</span><span class="cx"> bulk create allowing groups to contain member UIDs added during the same bulk create
</span><span class="lines">@@ -3666,13 +3651,6 @@
</span><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><del>- def addNotification(self, request, uid, xmltype, xmldata):
- return maybeDeferred(
- self._newStoreNotifications.writeNotificationObject,
- uid, xmltype, xmldata
- )
-
-
</del><span class="cx"> def deleteNotification(self, request, record):
</span><span class="cx"> return maybeDeferred(
</span><span class="cx"> self._newStoreNotifications.removeNotificationObjectWithName,
</span><span class="lines">@@ -3717,7 +3695,15 @@
</span><span class="cx"> qname = prop.qname()
</span><span class="cx">
</span><span class="cx"> if qname == customxml.NotificationType.qname():
</span><del>- returnValue(self._newStoreObject.xmlType())
</del><ins>+ jsontype = self._newStoreObject.notificationType()
+ if jsontype["notification-type"] == "invite-notification":
+ typeAttr = {"shared-type": jsontype["shared-type"]}
+ xmltype = customxml.InviteNotification(**typeAttr)
+ elif jsontype["notification-type"] == "invite-reply":
+ xmltype = customxml.InviteReply()
+ else:
+ raise HTTPError(responsecode.INTERNAL_SERVER_ERROR)
+ returnValue(customxml.NotificationType(xmltype))
</ins><span class="cx">
</span><span class="cx"> returnValue((yield super(StoreNotificationObjectFile, self).readProperty(prop, request)))
</span><span class="cx">
</span><span class="lines">@@ -3730,11 +3716,97 @@
</span><span class="cx"> return succeed(self._newStoreObject.size())
</span><span class="cx">
</span><span class="cx">
</span><ins>+ @inlineCallbacks
</ins><span class="cx"> def text(self, ignored=None):
</span><span class="cx"> assert ignored is None, "This is a notification object, not a notification"
</span><del>- return self._newStoreObject.xmldata()
</del><ins>+ jsondata = (yield self._newStoreObject.notificationData())
+ if jsondata["notification-type"] == "invite-notification":
+ ownerPrincipal = self.principalForUID(jsondata["owner"])
+ ownerCN = ownerPrincipal.displayName()
+ ownerHomeURL = ownerPrincipal.calendarHomeURLs()[0] if jsondata["shared-type"] == "calendar" else ownerPrincipal.addressBookHomeURLs()[0]
</ins><span class="cx">
</span><ins>+ # FIXME: use urn:uuid always?
+ if jsondata["shared-type"] == "calendar":
+ owner = ownerPrincipal.principalURL()
+ else:
+ owner = "urn:uuid:" + ownerPrincipal.principalUID()
</ins><span class="cx">
</span><ins>+ shareePrincipal = self.principalForUID(jsondata["sharee"])
+
+ if "supported-components" in jsondata:
+ comps = jsondata["supported-components"]
+ if comps:
+ comps = comps.split(",")
+ else:
+ comps = ical.allowedStoreComponents
+ supported = caldavxml.SupportedCalendarComponentSet(
+ *[caldavxml.CalendarComponent(name=item) for item in comps]
+ )
+ else:
+ supported = None
+
+ typeAttr = {"shared-type": jsondata["shared-type"]}
+ xmldata = customxml.Notification(
+ customxml.DTStamp.fromString(jsondata["dtstamp"]),
+ customxml.InviteNotification(
+ customxml.UID.fromString(jsondata["uid"]),
+ element.HRef.fromString("urn:uuid:" + jsondata["sharee"]),
+ invitationBindStatusToXMLMap[jsondata["status"]](),
+ customxml.InviteAccess(invitationBindModeToXMLMap[jsondata["access"]]()),
+ customxml.HostURL(
+ element.HRef.fromString(urljoin(ownerHomeURL, jsondata["ownerName"])),
+ ),
+ customxml.Organizer(
+ element.HRef.fromString(owner),
+ customxml.CommonName.fromString(ownerCN),
+ ),
+ customxml.InviteSummary.fromString(jsondata["summary"]),
+ supported,
+ **typeAttr
+ ),
+ )
+ elif jsondata["notification-type"] == "invite-reply":
+ ownerPrincipal = self.principalForUID(jsondata["owner"])
+ ownerHomeURL = ownerPrincipal.calendarHomeURLs()[0] if jsondata["shared-type"] == "calendar" else ownerPrincipal.addressBookHomeURLs()[0]
+
+ shareePrincipal = self.principalForUID(jsondata["sharee"])
+
+ # FIXME: use urn:uuid always?
+ if jsondata["shared-type"] == "calendar":
+ # Prefer mailto:, otherwise use principal URL
+ for cua in shareePrincipal.calendarUserAddresses():
+ if cua.startswith("mailto:"):
+ break
+ else:
+ cua = shareePrincipal.principalURL()
+ else:
+ cua = "urn:uuid:" + shareePrincipal.principalUID()
+
+ commonName = shareePrincipal.displayName()
+ record = shareePrincipal.record
+
+ typeAttr = {"shared-type": jsondata["shared-type"]}
+ xmldata = customxml.Notification(
+ customxml.DTStamp.fromString(jsondata["dtstamp"]),
+ customxml.InviteReply(
+ element.HRef.fromString(cua),
+ invitationBindStatusToXMLMap[jsondata["status"]](),
+ customxml.HostURL(
+ element.HRef.fromString(urljoin(ownerHomeURL, jsondata["ownerName"])),
+ ),
+ customxml.InReplyTo.fromString(jsondata["in-reply-to"]),
+ customxml.InviteSummary.fromString(jsondata["summary"]) if jsondata["summary"] else None,
+ customxml.CommonName.fromString(commonName) if commonName else None,
+ customxml.FirstNameProperty(record.firstName) if record.firstName else None,
+ customxml.LastNameProperty(record.lastName) if record.lastName else None,
+ #**typeAttr
+ ),
+ )
+ else:
+ raise HTTPError(responsecode.INTERNAL_SERVER_ERROR)
+ returnValue(xmldata.toxml())
+
+
</ins><span class="cx"> @requiresPermissions(davxml.Read())
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def http_GET(self, request):
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavtesttest_sharingpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/test/test_sharing.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/test/test_sharing.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/twistedcaldav/test/test_sharing.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -19,7 +19,7 @@
</span><span class="cx"> from twext.web2.http_headers import MimeType
</span><span class="cx"> from twext.web2.iweb import IResponse
</span><span class="cx">
</span><del>-from twisted.internet.defer import inlineCallbacks, returnValue, succeed
</del><ins>+from twisted.internet.defer import inlineCallbacks, returnValue
</ins><span class="cx">
</span><span class="cx"> from twistedcaldav import customxml
</span><span class="cx"> from twistedcaldav import sharing
</span><span class="lines">@@ -52,8 +52,7 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> class FakeHome(object):
</span><del>- def removeShareByUID(self, request, uid):
- pass
</del><ins>+ pass
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -105,6 +104,10 @@
</span><span class="cx"> returnValue(b)
</span><span class="cx">
</span><span class="cx">
</span><ins>+ def calendarHomeURLs(self):
+ return (self.homepath,)
+
+
</ins><span class="cx"> def principalURL(self):
</span><span class="cx"> return self.path
</span><span class="cx">
</span><span class="lines">@@ -142,22 +145,6 @@
</span><span class="cx"> return c
</span><span class="cx">
</span><span class="cx"> @patched
</span><del>- def sendInviteNotification(resourceSelf, record, request):
- """
- For testing purposes, sending an invite notification succeeds
- without doing anything.
- """
- return succeed(True)
-
- @patched
- def removeInviteNotification(resourceSelf, record, request):
- """
- For testing purposes, removing an invite notification succeeds
- without doing anything.
- """
- return succeed(True)
-
- @patched
</del><span class="cx"> def principalForCalendarUserAddress(resourceSelf, cuaddr):
</span><span class="cx"> if "bogus" in cuaddr:
</span><span class="cx"> return None
</span></span></pre></div>
<a id="CalendarServertrunktxdavbasedatastoreutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/base/datastore/util.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/base/datastore/util.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/txdav/base/datastore/util.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -95,7 +95,7 @@
</span><span class="cx"> # Home child objects by id
</span><span class="cx">
</span><span class="cx"> def keyForObjectWithResourceID(self, homeResourceID, resourceID):
</span><del>- return "objectWithName:%s:%s" % (homeResourceID, resourceID)
</del><ins>+ return "objectWithResourceID:%s:%s" % (homeResourceID, resourceID)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> # Home metadata (Created/Modified)
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/sql.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -14,6 +14,7 @@
</span><span class="cx"> # See the License for the specific language governing permissions and
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> ##
</span><ins>+from txdav.xml import element
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> """
</span><span class="lines">@@ -396,6 +397,8 @@
</span><span class="cx">
</span><span class="cx"> implements(ICalendarHome)
</span><span class="cx">
</span><ins>+ _homeType = ECALENDARTYPE
+
</ins><span class="cx"> # structured tables. (new, preferred)
</span><span class="cx"> _homeSchema = schema.CALENDAR_HOME
</span><span class="cx"> _bindSchema = schema.CALENDAR_BIND
</span><span class="lines">@@ -1245,6 +1248,44 @@
</span><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><ins>+ def sharedResourceType(self):
+ """
+ The sharing resource type
+ """
+ return "calendar"
+
+
+ @inlineCallbacks
+ def newShare(self, displayname=None):
+ """
+ Override in derived classes to do any specific operations needed when a share
+ is first accepted.
+ """
+
+ # For a direct share we will copy any displayname and calendar-color over using the owners view
+ if self.direct():
+ ownerView = yield self.ownerView()
+ try:
+ displayname = ownerView.properties()[PropertyName.fromElement(element.DisplayName)]
+ self.properties()[PropertyName.fromElement(element.DisplayName)] = displayname
+ except KeyError:
+ pass
+ try:
+ color = ownerView.properties()[PropertyName.fromElement(customxml.CalendarColor)]
+ self.properties()[PropertyName.fromElement(customxml.CalendarColor)] = color
+ except KeyError:
+ pass
+ elif displayname:
+ self.properties()[PropertyName.fromElement(element.DisplayName)] = element.DisplayName.fromString(displayname)
+
+ # Calendars always start out transparent and with empty default alarms
+ yield self.setUsedForFreeBusy(False)
+ yield self.setDefaultAlarm("empty", True, True)
+ yield self.setDefaultAlarm("empty", True, False)
+ yield self.setDefaultAlarm("empty", False, True)
+ yield self.setDefaultAlarm("empty", False, False)
+
+
</ins><span class="cx"> # FIXME: this is DAV-ish. Data store calendar objects don't have
</span><span class="cx"> # mime types. -wsv
</span><span class="cx"> def contentType(self):
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoretestcommonpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/test/common.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/test/common.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/common.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -41,21 +41,21 @@
</span><span class="cx"> from txdav.common.icommondatastore import ObjectResourceNameAlreadyExistsError
</span><span class="cx"> from txdav.common.inotifications import INotificationObject
</span><span class="cx"> from txdav.common.datastore.test.util import CommonCommonTests
</span><del>-from txdav.common.datastore.sql_tables import _BIND_MODE_WRITE, _BIND_MODE_READ
</del><span class="cx">
</span><span class="cx"> from txdav.caldav.icalendarstore import (
</span><span class="cx"> ICalendarObject, ICalendarHome,
</span><span class="cx"> ICalendar, ICalendarTransaction,
</span><span class="cx"> ComponentUpdateState)
</span><span class="cx">
</span><del>-from twistedcaldav.customxml import InviteNotification, InviteSummary
</del><span class="cx"> from txdav.common.datastore.test.util import transactionClean
</span><span class="cx"> from txdav.common.icommondatastore import ConcurrentModification
</span><span class="cx"> from twistedcaldav.ical import Component
</span><span class="cx"> from twistedcaldav.config import config
</span><span class="cx"> from calendarserver.push.util import PushPriority
</span><span class="cx">
</span><ins>+import json
</ins><span class="cx">
</span><ins>+
</ins><span class="cx"> storePath = FilePath(__file__).parent().child("calendar_store")
</span><span class="cx">
</span><span class="cx"> homeRoot = storePath.child("ho").child("me").child("home1")
</span><span class="lines">@@ -374,9 +374,11 @@
</span><span class="cx"> def notificationUnderTest(self):
</span><span class="cx"> txn = self.transactionUnderTest()
</span><span class="cx"> notifications = yield txn.notificationsWithUID("home1")
</span><del>- inviteNotification = InviteNotification()
- yield notifications.writeNotificationObject("abc", inviteNotification,
- inviteNotification.toxml())
</del><ins>+ yield notifications.writeNotificationObject(
+ "abc",
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ )
</ins><span class="cx"> notificationObject = yield notifications.notificationObjectWithUID("abc")
</span><span class="cx"> returnValue(notificationObject)
</span><span class="cx">
</span><span class="lines">@@ -399,10 +401,17 @@
</span><span class="cx"> """
</span><span class="cx"> txn = self.transactionUnderTest()
</span><span class="cx"> coll = yield txn.notificationsWithUID("home1")
</span><del>- invite1 = InviteNotification()
- yield coll.writeNotificationObject("1", invite1, invite1.toxml())
</del><ins>+ yield coll.writeNotificationObject(
+ "1",
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ )
</ins><span class="cx"> st = yield coll.syncToken()
</span><del>- yield coll.writeNotificationObject("2", invite1, invite1.toxml())
</del><ins>+ yield coll.writeNotificationObject(
+ "2",
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ )
</ins><span class="cx"> rev = self.token2revision(st)
</span><span class="cx"> yield coll.removeNotificationObjectWithUID("1")
</span><span class="cx"> st2 = yield coll.syncToken()
</span><span class="lines">@@ -424,14 +433,21 @@
</span><span class="cx"> notifications = yield self.transactionUnderTest().notificationsWithUID(
</span><span class="cx"> "home1"
</span><span class="cx"> )
</span><del>- inviteNotification = InviteNotification()
- yield notifications.writeNotificationObject("abc", inviteNotification,
- inviteNotification.toxml())
- inviteNotification2 = InviteNotification(InviteSummary("a summary"))
</del><span class="cx"> yield notifications.writeNotificationObject(
</span><del>- "abc", inviteNotification, inviteNotification2.toxml())
</del><ins>+ "abc",
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ )
+ yield notifications.writeNotificationObject(
+ "abc",
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ json.loads("{\"notification-type\":\"invite-notification\",\"summary\":\"a summary\"}"),
+ )
</ins><span class="cx"> abc = yield notifications.notificationObjectWithUID("abc")
</span><del>- self.assertEquals((yield abc.xmldata()), inviteNotification2.toxml())
</del><ins>+ self.assertEquals(
+ (yield abc.notificationData()),
+ json.loads("{\"notification-type\":\"invite-notification\",\"summary\":\"a summary\"}"),
+ )
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="lines">@@ -450,9 +466,11 @@
</span><span class="cx"> "home1"
</span><span class="cx"> )
</span><span class="cx"> self.notifierFactory.reset()
</span><del>- inviteNotification = InviteNotification()
- yield notifications.writeNotificationObject("abc", inviteNotification,
- inviteNotification.toxml())
</del><ins>+ yield notifications.writeNotificationObject(
+ "abc",
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ )
</ins><span class="cx">
</span><span class="cx"> # notify is called prior to commit
</span><span class="cx"> self.assertEquals(
</span><span class="lines">@@ -492,12 +510,16 @@
</span><span class="cx"> notifications = yield self.transactionUnderTest().notificationsWithUID(
</span><span class="cx"> "home1"
</span><span class="cx"> )
</span><del>- inviteNotification = InviteNotification()
- yield notifications.writeNotificationObject("abc", inviteNotification,
- inviteNotification.toxml())
- inviteNotification2 = InviteNotification(InviteSummary("a summary"))
</del><span class="cx"> yield notifications.writeNotificationObject(
</span><del>- "def", inviteNotification, inviteNotification2.toxml())
</del><ins>+ "abc",
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ )
+ yield notifications.writeNotificationObject(
+ "def",
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ json.loads("{\"notification-type\":\"invite-notification\",\"summary\":\"a summary\"}"),
+ )
</ins><span class="cx">
</span><span class="cx"> yield self.commit()
</span><span class="cx">
</span><span class="lines">@@ -951,156 +973,6 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def test_shareWith(self):
- """
- L{ICalendar.shareWith} will share a calendar with a given home UID.
- """
- cal = yield self.calendarUnderTest()
- other = yield self.homeUnderTest(name=OTHER_HOME_UID)
- newCalName = yield cal.shareWith(other, _BIND_MODE_WRITE)
- self.sharedName = newCalName
- yield self.commit()
- normalCal = yield self.calendarUnderTest()
- otherHome = yield self.homeUnderTest(name=OTHER_HOME_UID)
- otherCal = yield otherHome.childWithName(newCalName)
- self.assertNotIdentical(otherCal, None)
- self.assertEqual(
- (yield
- (yield otherCal.calendarObjectWithName("1.ics")).component()),
- (yield
- (yield normalCal.calendarObjectWithName("1.ics")).component())
- )
-
-
- @inlineCallbacks
- def test_shareAgainChangesMode(self):
- """
- If a calendar is already shared with a given calendar home,
- L{ICalendar.shareWith} will change the sharing mode.
- """
- yield self.test_shareWith()
- # yield self.commit() # txn is none? why?
- cal = yield self.calendarUnderTest()
- other = yield self.homeUnderTest(name=OTHER_HOME_UID)
- newName = yield cal.shareWith(other, _BIND_MODE_READ)
- otherCal = yield other.childWithName(self.sharedName)
-
- # Name should not change just because we updated the mode.
- self.assertEqual(newName, self.sharedName)
- self.assertNotIdentical(otherCal, None)
-
- invitedCals = yield cal.sharingInvites()
- self.assertEqual(len(invitedCals), 1)
- self.assertEqual(invitedCals[0].mode(), _BIND_MODE_READ)
-
-
- @inlineCallbacks
- def test_unshareWith(self, commit=False):
- """
- L{ICalendar.unshareWith} will remove a previously-shared calendar from
- another user's calendar home.
- """
- yield self.test_shareWith()
- if commit:
- yield self.commit()
- cal = yield self.calendarUnderTest()
- other = yield self.homeUnderTest(name=OTHER_HOME_UID)
- newName = yield cal.unshareWith(other)
- otherCal = yield other.childWithName(newName)
- self.assertIdentical(otherCal, None)
- invitedCals = yield cal.sharingInvites()
- self.assertEqual(len(invitedCals), 0)
-
-
- @inlineCallbacks
- def test_unshareSharerSide(self, commit=False):
- """
- Verify the coll.unshare( ) method works when called from the
- sharer's copy
- """
- yield self.test_shareWith()
- if commit:
- yield self.commit()
- cal = yield self.calendarUnderTest()
- other = yield self.homeUnderTest(name=OTHER_HOME_UID)
- otherCal = yield other.childWithName(self.sharedName)
- self.assertNotEqual(otherCal, None)
- yield cal.unshare()
- otherCal = yield other.childWithName(self.sharedName)
- self.assertEqual(otherCal, None)
- invitedCals = yield cal.sharingInvites()
- self.assertEqual(len(invitedCals), 0)
-
-
- @inlineCallbacks
- def test_unshareShareeSide(self, commit=False):
- """
- Verify the coll.unshare( ) method works when called from the
- sharee's copy
- """
- yield self.test_shareWith()
- if commit:
- yield self.commit()
- cal = yield self.calendarUnderTest()
- other = yield self.homeUnderTest(name=OTHER_HOME_UID)
- otherCal = yield other.childWithName(self.sharedName)
- self.assertNotEqual(otherCal, None)
- yield otherCal.unshare()
- otherCal = yield other.childWithName(self.sharedName)
- self.assertEqual(otherCal, None)
- invitedCals = yield cal.sharingInvites()
- self.assertEqual(len(invitedCals), 0)
-
-
- @inlineCallbacks
- def test_unshareWithInDifferentTransaction(self):
- """
- L{ICalendar.unshareWith} will remove a previously-shared calendar from
- another user's calendar home, assuming the sharing was committed in a
- previous transaction.
- """
- yield self.test_unshareWith(True)
-
-
- @inlineCallbacks
- def test_sharingInvites(self):
- """
- L{ICalendar.sharingInvites} returns an iterable of all versions of a shared
- calendar.
- """
- cal = yield self.calendarUnderTest()
- sharedBefore = yield cal.sharingInvites()
- # It's not shared yet; make sure sharingInvites doesn't include owner version.
- self.assertEqual(len(sharedBefore), 0)
- yield self.test_shareWith()
- # FIXME: don't know why this separate transaction is needed; remove it.
- yield self.commit()
- cal = yield self.calendarUnderTest()
- sharedAfter = yield cal.sharingInvites()
- self.assertEqual(len(sharedAfter), 1)
- self.assertEqual(sharedAfter[0].mode(), _BIND_MODE_WRITE)
- self.assertEqual(sharedAfter[0].shareeUID(), OTHER_HOME_UID)
-
-
- @inlineCallbacks
- def test_sharedNotifierID(self):
- yield self.test_shareWith()
- yield self.commit()
-
- home = yield self.homeUnderTest()
- self.assertEquals(home.notifierID(), ("CalDAV", "home1",))
- calendar = yield home.calendarWithName("calendar_1")
- self.assertEquals(calendar.notifierID(), ("CalDAV", "home1/calendar_1",))
- yield self.commit()
-
- home = yield self.homeUnderTest(name=OTHER_HOME_UID)
- self.assertEquals(home.notifierID(), ("CalDAV", OTHER_HOME_UID,))
- calendar = yield home.calendarWithName(self.sharedName)
- self.assertEquals(calendar.notifierID(), ("CalDAV", "home1/calendar_1",))
- yield self.commit()
-
-
- @inlineCallbacks
</del><span class="cx"> def test_hasCalendarResourceUIDSomewhereElse(self):
</span><span class="cx"> """
</span><span class="cx"> L{ICalendarHome.hasCalendarResourceUIDSomewhereElse} will determine if
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoretesttest_sqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -51,7 +51,7 @@
</span><span class="cx">
</span><span class="cx"> from txdav.base.propertystore.base import PropertyName
</span><span class="cx"> from txdav.caldav.datastore.test.common import CommonTests as CalendarCommonTests, \
</span><del>- test_event_text, OTHER_HOME_UID
</del><ins>+ test_event_text
</ins><span class="cx"> from txdav.caldav.datastore.test.test_file import setUpCalendarStore
</span><span class="cx"> from txdav.caldav.datastore.test.util import buildCalendarStore
</span><span class="cx"> from txdav.caldav.datastore.util import _migrateCalendar, migrateHome
</span><span class="lines">@@ -59,7 +59,7 @@
</span><span class="cx"> from txdav.common.datastore.sql import ECALENDARTYPE, CommonObjectResource
</span><span class="cx"> from txdav.common.datastore.sql_legacy import PostgresLegacyIndexEmulator
</span><span class="cx"> from txdav.common.datastore.sql_tables import schema, _BIND_MODE_DIRECT, \
</span><del>- _BIND_STATUS_ACCEPTED, _BIND_MODE_WRITE, _BIND_STATUS_INVITED
</del><ins>+ _BIND_STATUS_ACCEPTED
</ins><span class="cx"> from txdav.common.datastore.test.util import populateCalendarsFrom, \
</span><span class="cx"> CommonCommonTests
</span><span class="cx"> from txdav.common.icommondatastore import NoSuchObjectResourceError
</span><span class="lines">@@ -952,13 +952,13 @@
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def _defer1():
</span><del>- yield cal1.shareWith(shareeHome=sharerHome1, mode=_BIND_MODE_DIRECT, status=_BIND_STATUS_ACCEPTED, message="Shared Wiki Calendar")
</del><ins>+ yield cal1.directShareWithUser("uid2")
</ins><span class="cx"> yield txn1.commit()
</span><span class="cx"> d1 = _defer1()
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def _defer2():
</span><del>- yield cal2.shareWith(shareeHome=sharerHome2, mode=_BIND_MODE_DIRECT, status=_BIND_STATUS_ACCEPTED, message="Shared Wiki Calendar")
</del><ins>+ yield cal2.directShareWithUser("uid1")
</ins><span class="cx"> yield txn2.commit()
</span><span class="cx"> d2 = _defer2()
</span><span class="cx">
</span><span class="lines">@@ -1708,90 +1708,6 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def test_shareWithRevision(self):
- """
- Verify that bindRevision on calendars and shared calendars has the correct value.
- """
- cal = yield self.calendarUnderTest()
- self.assertEqual(cal._bindRevision, 0)
- other = yield self.homeUnderTest(name=OTHER_HOME_UID)
- newCalName = yield cal.shareWith(other, _BIND_MODE_WRITE)
- yield self.commit()
-
- normalCal = yield self.calendarUnderTest()
- self.assertEqual(normalCal._bindRevision, 0)
- otherHome = yield self.homeUnderTest(name=OTHER_HOME_UID)
- otherCal = yield otherHome.childWithName(newCalName)
- self.assertNotEqual(otherCal._bindRevision, 0)
-
-
- @inlineCallbacks
- def test_updateShareRevision(self):
- """
- Verify that bindRevision on calendars and shared calendars has the correct value.
- """
- cal = yield self.calendarUnderTest()
- self.assertEqual(cal._bindRevision, 0)
- other = yield self.homeUnderTest(name=OTHER_HOME_UID)
- newCalName = yield cal.shareWith(other, _BIND_MODE_WRITE, status=_BIND_STATUS_INVITED)
- yield self.commit()
-
- normalCal = yield self.calendarUnderTest()
- self.assertEqual(normalCal._bindRevision, 0)
- otherHome = yield self.homeUnderTest(name=OTHER_HOME_UID)
- otherCal = yield otherHome.invitedObjectWithShareUID(newCalName)
- self.assertEqual(otherCal._bindRevision, 0)
- yield self.commit()
-
- normalCal = yield self.calendarUnderTest()
- otherHome = yield self.homeUnderTest(name=OTHER_HOME_UID)
- otherCal = yield otherHome.invitedObjectWithShareUID(newCalName)
- yield normalCal.updateShare(otherCal, status=_BIND_STATUS_ACCEPTED)
- yield self.commit()
-
- normalCal = yield self.calendarUnderTest()
- self.assertEqual(normalCal._bindRevision, 0)
- otherHome = yield self.homeUnderTest(name=OTHER_HOME_UID)
- otherCal = yield otherHome.childWithName(newCalName)
- self.assertNotEqual(otherCal._bindRevision, 0)
-
-
- @inlineCallbacks
- def test_sharedRevisions(self):
- """
- Verify that resourceNamesSinceRevision returns all resources after initial bind and sync.
- """
- cal = yield self.calendarUnderTest()
- self.assertEqual(cal._bindRevision, 0)
- other = yield self.homeUnderTest(name=OTHER_HOME_UID)
- newCalName = yield cal.shareWith(other, _BIND_MODE_WRITE)
- yield self.commit()
-
- normalCal = yield self.calendarUnderTest()
- self.assertEqual(normalCal._bindRevision, 0)
- otherHome = yield self.homeUnderTest(name=OTHER_HOME_UID)
- otherCal = yield otherHome.childWithName(newCalName)
- self.assertNotEqual(otherCal._bindRevision, 0)
-
- changed, deleted = yield otherCal.resourceNamesSinceRevision(otherCal._bindRevision - 1)
- self.assertNotEqual(len(changed), 0)
- self.assertEqual(len(deleted), 0)
-
- changed, deleted = yield otherCal.resourceNamesSinceRevision(otherCal._bindRevision)
- self.assertEqual(len(changed), 0)
- self.assertEqual(len(deleted), 0)
-
- for depth in ("1", "infinity",):
- changed, deleted = yield otherHome.resourceNamesSinceRevision(otherCal._bindRevision - 1, depth)
- self.assertNotEqual(len(changed), 0)
- self.assertEqual(len(deleted), 0)
-
- changed, deleted = yield otherHome.resourceNamesSinceRevision(otherCal._bindRevision, depth)
- self.assertEqual(len(changed), 0)
- self.assertEqual(len(deleted), 0)
-
-
- @inlineCallbacks
</del><span class="cx"> def test_setAvailability(self):
</span><span class="cx"> """
</span><span class="cx"> Make sure a L{CalendarHome}.setAvailability() works.
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoretesttest_sql_sharingpyfromrev12016CalendarServerbranchesuserscdaboosharinginthestoretxdavcaldavdatastoretesttest_sql_sharingpy"></a>
<div class="copfile"><h4>Copied: CalendarServer/trunk/txdav/caldav/datastore/test/test_sql_sharing.py (from rev 12016, CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/test/test_sql_sharing.py) (0 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/test/test_sql_sharing.py         (rev 0)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/test_sql_sharing.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -0,0 +1,572 @@
</span><ins>+##
+# Copyright (c) 2005-2013 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.
+##
+
+
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.trial.unittest import TestCase
+
+from twext.python.clsprop import classproperty
+from txdav.common.datastore.test.util import CommonCommonTests, \
+ populateCalendarsFrom
+from txdav.caldav.datastore.test.util import buildCalendarStore
+from txdav.common.datastore.sql_tables import _BIND_MODE_READ, \
+ _BIND_STATUS_INVITED, _BIND_MODE_DIRECT, _BIND_STATUS_ACCEPTED
+
+
+class BaseSharingTests(CommonCommonTests, TestCase):
+ """
+ Test store-based calendar sharing.
+ """
+
+ @inlineCallbacks
+ def setUp(self):
+ yield super(BaseSharingTests, self).setUp()
+ self._sqlCalendarStore = yield buildCalendarStore(self, self.notifierFactory)
+ yield self.populate()
+
+
+ @inlineCallbacks
+ def populate(self):
+ yield populateCalendarsFrom(self.requirements, self.storeUnderTest())
+ self.notifierFactory.reset()
+
+ cal1 = """BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid1
+DTSTART:20131122T140000
+DURATION:PT1H
+CREATED:20060102T190000Z
+DTSTAMP:20051222T210507Z
+SUMMARY:event 1
+END:VEVENT
+END:VCALENDAR
+"""
+
+ @classproperty(cache=False)
+ def requirements(cls): #@NoSelf
+ return {
+ "user01": {
+ "calendar": {
+ "cal1.ics": (cls.cal1, None,),
+ },
+ "inbox": {
+ },
+ },
+ "user02": {
+ "calendar": {
+ },
+ "inbox": {
+ },
+ },
+ "user03": {
+ "calendar": {
+ },
+ "inbox": {
+ },
+ },
+ }
+
+
+ def storeUnderTest(self):
+ """
+ Create and return a L{CalendarStore} for testing.
+ """
+ return self._sqlCalendarStore
+
+
+ @inlineCallbacks
+ def _createShare(self):
+ # Invite
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ invites = yield calendar.sharingInvites()
+ self.assertEqual(len(invites), 0)
+
+ shareeView = yield calendar.inviteUserToShare("user02", _BIND_MODE_READ, "summary")
+ inviteUID = shareeView.shareUID()
+ yield self.commit()
+
+ # Accept
+ shareeHome = yield self.homeUnderTest(name="user02")
+ shareeView = yield shareeHome.acceptShare(inviteUID)
+ sharedName = shareeView.name()
+ yield self.commit()
+
+ returnValue(sharedName)
+
+
+
+class CalendarSharing(BaseSharingTests):
+
+ @inlineCallbacks
+ def test_no_shares(self):
+ """
+ Test that initially there are no shares.
+ """
+
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ invites = yield calendar.sharingInvites()
+ self.assertEqual(len(invites), 0)
+ self.assertFalse(calendar.isShared())
+
+
+ @inlineCallbacks
+ def test_invite_sharee(self):
+ """
+ Test invite/uninvite creates/removes shares and notifications.
+ """
+
+ # Invite
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ invites = yield calendar.sharingInvites()
+ self.assertEqual(len(invites), 0)
+ self.assertFalse(calendar.isShared())
+
+ shareeView = yield calendar.inviteUserToShare("user02", _BIND_MODE_READ, "summary")
+ invites = yield calendar.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ self.assertEqual(invites[0].uid, shareeView.shareUID())
+ self.assertEqual(invites[0].ownerUID, "user01")
+ self.assertEqual(invites[0].shareeUID, "user02")
+ self.assertEqual(invites[0].mode, _BIND_MODE_READ)
+ self.assertEqual(invites[0].status, _BIND_STATUS_INVITED)
+ self.assertEqual(invites[0].summary, "summary")
+ inviteUID = shareeView.shareUID()
+
+ sharedName = shareeView.name()
+ shared = yield self.calendarUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is None)
+
+ notifyHome = yield self.transactionUnderTest().notificationsWithUID("user02")
+ notifications = yield notifyHome.listNotificationObjects()
+ self.assertEqual(notifications, [inviteUID, ])
+
+ self.assertTrue(calendar.isShared())
+
+ yield self.commit()
+
+ # Uninvite
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ invites = yield calendar.sharingInvites()
+ self.assertEqual(len(invites), 1)
+
+ yield calendar.uninviteUserFromShare("user02")
+ invites = yield calendar.sharingInvites()
+ self.assertEqual(len(invites), 0)
+
+ notifyHome = yield self.transactionUnderTest().notificationsWithUID("user02")
+ notifications = yield notifyHome.listNotificationObjects()
+ self.assertEqual(notifications, [])
+
+ self.assertTrue(calendar.isShared())
+
+ yield self.commit()
+
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ self.assertTrue(calendar.isShared())
+ yield calendar.setShared(False)
+ self.assertFalse(calendar.isShared())
+
+
+ @inlineCallbacks
+ def test_accept_share(self):
+ """
+ Test that invite+accept creates shares and notifications.
+ """
+
+ # Invite
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ invites = yield calendar.sharingInvites()
+ self.assertEqual(len(invites), 0)
+ self.assertFalse(calendar.isShared())
+
+ shareeView = yield calendar.inviteUserToShare("user02", _BIND_MODE_READ, "summary")
+ invites = yield calendar.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ inviteUID = shareeView.shareUID()
+
+ sharedName = shareeView.name()
+ shared = yield self.calendarUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is None)
+
+ notifyHome = yield self.transactionUnderTest().notificationsWithUID("user02")
+ notifications = yield notifyHome.listNotificationObjects()
+ self.assertEqual(len(notifications), 1)
+
+ self.assertTrue(calendar.isShared())
+
+ yield self.commit()
+
+ # Accept
+ shareeHome = yield self.homeUnderTest(name="user02")
+ yield shareeHome.acceptShare(inviteUID)
+
+ shared = yield self.calendarUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is not None)
+
+ notifyHome = yield self.transactionUnderTest().notificationsWithUID("user01")
+ notifications = yield notifyHome.listNotificationObjects()
+ self.assertEqual(notifications, [inviteUID + "-reply", ])
+
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ self.assertTrue(calendar.isShared())
+
+ yield self.commit()
+
+ # Re-accept
+ shareeHome = yield self.homeUnderTest(name="user02")
+ yield shareeHome.acceptShare(inviteUID)
+
+ shared = yield self.calendarUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is not None)
+
+ notifyHome = yield self.transactionUnderTest().notificationsWithUID("user01")
+ notifications = yield notifyHome.listNotificationObjects()
+ self.assertEqual(notifications, [inviteUID + "-reply", ])
+
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ self.assertTrue(calendar.isShared())
+
+
+ @inlineCallbacks
+ def test_decline_share(self):
+ """
+ Test that invite+decline does not create shares but does create notifications.
+ """
+
+ # Invite
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ invites = yield calendar.sharingInvites()
+ self.assertEqual(len(invites), 0)
+ self.assertFalse(calendar.isShared())
+
+ shareeView = yield calendar.inviteUserToShare("user02", _BIND_MODE_READ, "summary")
+ invites = yield calendar.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ inviteUID = shareeView.shareUID()
+
+ sharedName = shareeView.name()
+ shared = yield self.calendarUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is None)
+
+ notifyHome = yield self.transactionUnderTest().notificationsWithUID("user02")
+ notifications = yield notifyHome.listNotificationObjects()
+ self.assertEqual(len(notifications), 1)
+
+ self.assertTrue(calendar.isShared())
+
+ yield self.commit()
+
+ # Decline
+ shareeHome = yield self.homeUnderTest(name="user02")
+ yield shareeHome.declineShare(inviteUID)
+
+ shared = yield self.calendarUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is None)
+
+ notifyHome = yield self.transactionUnderTest().notificationsWithUID("user01")
+ notifications = yield notifyHome.listNotificationObjects()
+ self.assertEqual(notifications, [inviteUID + "-reply", ])
+
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ self.assertTrue(calendar.isShared())
+
+ yield self.commit()
+
+ # Redecline
+ shareeHome = yield self.homeUnderTest(name="user02")
+ yield shareeHome.declineShare(inviteUID)
+
+ shared = yield self.calendarUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is None)
+
+ notifyHome = yield self.transactionUnderTest().notificationsWithUID("user01")
+ notifications = yield notifyHome.listNotificationObjects()
+ self.assertEqual(notifications, [inviteUID + "-reply", ])
+
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ self.assertTrue(calendar.isShared())
+
+
+ @inlineCallbacks
+ def test_accept_decline_share(self):
+ """
+ Test that invite+accept/decline creates/removes shares and notifications.
+ Decline via the home.
+ """
+
+ # Invite
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ invites = yield calendar.sharingInvites()
+ self.assertEqual(len(invites), 0)
+ self.assertFalse(calendar.isShared())
+
+ shareeView = yield calendar.inviteUserToShare("user02", _BIND_MODE_READ, "summary")
+ invites = yield calendar.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ inviteUID = shareeView.shareUID()
+
+ sharedName = shareeView.name()
+ shared = yield self.calendarUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is None)
+
+ notifyHome = yield self.transactionUnderTest().notificationsWithUID("user02")
+ notifications = yield notifyHome.listNotificationObjects()
+ self.assertEqual(len(notifications), 1)
+
+ self.assertTrue(calendar.isShared())
+
+ yield self.commit()
+
+ # Accept
+ shareeHome = yield self.homeUnderTest(name="user02")
+ yield shareeHome.acceptShare(inviteUID)
+
+ shared = yield self.calendarUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is not None)
+
+ notifyHome = yield self.transactionUnderTest().notificationsWithUID("user01")
+ notifications = yield notifyHome.listNotificationObjects()
+ self.assertEqual(notifications, [inviteUID + "-reply", ])
+
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ self.assertTrue(calendar.isShared())
+
+ yield self.commit()
+
+ # Decline
+ shareeHome = yield self.homeUnderTest(name="user02")
+ yield shareeHome.declineShare(inviteUID)
+
+ shared = yield self.calendarUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is None)
+
+ notifyHome = yield self.transactionUnderTest().notificationsWithUID("user01")
+ notifications = yield notifyHome.listNotificationObjects()
+ self.assertEqual(notifications, [inviteUID + "-reply", ])
+
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ self.assertTrue(calendar.isShared())
+
+
+ @inlineCallbacks
+ def test_accept_remove_share(self):
+ """
+ Test that invite+accept/decline creates/removes shares and notifications.
+ Decline via the shared collection (removal).
+ """
+
+ # Invite
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ invites = yield calendar.sharingInvites()
+ self.assertEqual(len(invites), 0)
+
+ shareeView = yield calendar.inviteUserToShare("user02", _BIND_MODE_READ, "summary")
+ invites = yield calendar.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ inviteUID = shareeView.shareUID()
+
+ sharedName = shareeView.name()
+ shared = yield self.calendarUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is None)
+
+ notifyHome = yield self.transactionUnderTest().notificationsWithUID("user02")
+ notifications = yield notifyHome.listNotificationObjects()
+ self.assertEqual(len(notifications), 1)
+
+ yield self.commit()
+
+ # Accept
+ shareeHome = yield self.homeUnderTest(name="user02")
+ yield shareeHome.acceptShare(inviteUID)
+
+ shared = yield self.calendarUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is not None)
+
+ notifyHome = yield self.transactionUnderTest().notificationsWithUID("user01")
+ notifications = yield notifyHome.listNotificationObjects()
+ self.assertEqual(notifications, [inviteUID + "-reply", ])
+
+ yield self.commit()
+
+ # Delete
+ shared = yield self.calendarUnderTest(home="user02", name=sharedName)
+ yield shared.deleteShare()
+
+ shared = yield self.calendarUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is None)
+
+ notifyHome = yield self.transactionUnderTest().notificationsWithUID("user01")
+ notifications = yield notifyHome.listNotificationObjects()
+ self.assertEqual(notifications, [inviteUID + "-reply", ])
+
+
+ @inlineCallbacks
+ def test_inviteProperties(self):
+
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ yield calendar.setUsedForFreeBusy(True)
+ yield self.commit()
+
+ shared_name = yield self._createShare()
+
+ shared = yield self.calendarUnderTest(home="user02", name=shared_name)
+ self.assertFalse(shared.isUsedForFreeBusy())
+
+
+ @inlineCallbacks
+ def test_direct_sharee(self):
+ """
+ Test invite/uninvite creates/removes shares and notifications.
+ """
+
+ # Invite
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ invites = yield calendar.sharingInvites()
+ self.assertEqual(len(invites), 0)
+ self.assertFalse(calendar.isShared())
+
+ shareeView = yield calendar.directShareWithUser("user02")
+ invites = yield calendar.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ self.assertEqual(invites[0].uid, shareeView.shareUID())
+ self.assertEqual(invites[0].ownerUID, "user01")
+ self.assertEqual(invites[0].shareeUID, "user02")
+ self.assertEqual(invites[0].mode, _BIND_MODE_DIRECT)
+ self.assertEqual(invites[0].status, _BIND_STATUS_ACCEPTED)
+
+ sharedName = shareeView.name()
+ shared = yield self.calendarUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is not None)
+
+ notifyHome = yield self.transactionUnderTest().notificationsWithUID("user02")
+ notifications = yield notifyHome.listNotificationObjects()
+ self.assertEqual(len(notifications), 0)
+
+ yield self.commit()
+
+ # Remove
+ shared = yield self.calendarUnderTest(home="user02", name=sharedName)
+ yield shared.deleteShare()
+
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ invites = yield calendar.sharingInvites()
+ self.assertEqual(len(invites), 0)
+
+ notifyHome = yield self.transactionUnderTest().notificationsWithUID("user02")
+ notifications = yield notifyHome.listNotificationObjects()
+ self.assertEqual(len(notifications), 0)
+
+
+ @inlineCallbacks
+ def test_sharedNotifierID(self):
+ shared_name = yield self._createShare()
+
+ home = yield self.homeUnderTest(name="user01")
+ self.assertEquals(home.notifierID(), ("CalDAV", "user01",))
+ calendar = yield home.calendarWithName("calendar")
+ self.assertEquals(calendar.notifierID(), ("CalDAV", "user01/calendar",))
+ yield self.commit()
+
+ home = yield self.homeUnderTest(name="user02")
+ self.assertEquals(home.notifierID(), ("CalDAV", "user02",))
+ calendar = yield home.calendarWithName(shared_name)
+ self.assertEquals(calendar.notifierID(), ("CalDAV", "user01/calendar",))
+ yield self.commit()
+
+
+
+class SharingRevisions(BaseSharingTests):
+ """
+ Test store-based sharing and interaction with revision table.
+ """
+
+ @inlineCallbacks
+ def test_shareWithRevision(self):
+ """
+ Verify that bindRevision on calendars and shared calendars has the correct value.
+ """
+ sharedName = yield self._createShare()
+
+ normalCal = yield self.calendarUnderTest(home="user01", name="calendar")
+ self.assertEqual(normalCal._bindRevision, 0)
+ otherCal = yield self.calendarUnderTest(home="user02", name=sharedName)
+ self.assertNotEqual(otherCal._bindRevision, 0)
+
+
+ @inlineCallbacks
+ def test_updateShareRevision(self):
+ """
+ Verify that bindRevision on calendars and shared calendars has the correct value.
+ """
+ # Invite
+ calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+ invites = yield calendar.sharingInvites()
+ self.assertEqual(len(invites), 0)
+
+ shareeView = yield calendar.inviteUserToShare("user02", _BIND_MODE_READ, "summary")
+ newCalName = shareeView.shareUID()
+ yield self.commit()
+
+ normalCal = yield self.calendarUnderTest(home="user01", name="calendar")
+ self.assertEqual(normalCal._bindRevision, 0)
+ otherHome = yield self.homeUnderTest(name="user02")
+ otherCal = yield otherHome.anyObjectWithShareUID(newCalName)
+ self.assertEqual(otherCal._bindRevision, 0)
+ yield self.commit()
+
+ shareeHome = yield self.homeUnderTest(name="user02")
+ shareeView = yield shareeHome.acceptShare(newCalName)
+ sharedName = shareeView.name()
+ yield self.commit()
+
+ normalCal = yield self.calendarUnderTest(home="user01", name="calendar")
+ self.assertEqual(normalCal._bindRevision, 0)
+ otherCal = yield self.calendarUnderTest(home="user02", name=sharedName)
+ self.assertNotEqual(otherCal._bindRevision, 0)
+
+
+ @inlineCallbacks
+ def test_sharedRevisions(self):
+ """
+ Verify that resourceNamesSinceRevision returns all resources after initial bind and sync.
+ """
+ sharedName = yield self._createShare()
+
+ normalCal = yield self.calendarUnderTest(home="user01", name="calendar")
+ self.assertEqual(normalCal._bindRevision, 0)
+ otherHome = yield self.homeUnderTest(name="user02")
+ otherCal = yield self.calendarUnderTest(home="user02", name=sharedName)
+ self.assertNotEqual(otherCal._bindRevision, 0)
+
+ changed, deleted = yield otherCal.resourceNamesSinceRevision(otherCal._bindRevision - 1)
+ self.assertNotEqual(len(changed), 0)
+ self.assertEqual(len(deleted), 0)
+
+ changed, deleted = yield otherCal.resourceNamesSinceRevision(otherCal._bindRevision)
+ self.assertEqual(len(changed), 0)
+ self.assertEqual(len(deleted), 0)
+
+ for depth in ("1", "infinity",):
+ changed, deleted = yield otherHome.resourceNamesSinceRevision(otherCal._bindRevision - 1, depth)
+ self.assertNotEqual(len(changed), 0)
+ self.assertEqual(len(deleted), 0)
+
+ changed, deleted = yield otherHome.resourceNamesSinceRevision(otherCal._bindRevision, depth)
+ self.assertEqual(len(changed), 0)
+ self.assertEqual(len(deleted), 0)
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcarddavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/carddav/datastore/sql.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/carddav/datastore/sql.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/txdav/carddav/datastore/sql.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -14,6 +14,7 @@
</span><span class="cx"> # See the License for the specific language governing permissions and
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> # #
</span><ins>+from txdav.xml import element
</ins><span class="cx">
</span><span class="cx"> """
</span><span class="cx"> SQL backend for CardDAV storage.
</span><span class="lines">@@ -41,8 +42,8 @@
</span><span class="cx"> from twistedcaldav import carddavxml, customxml
</span><span class="cx"> from twistedcaldav.config import config
</span><span class="cx"> from twistedcaldav.memcacher import Memcacher
</span><del>-from twistedcaldav.vcard import Component as VCard, InvalidVCardDataError, \
- vCardProductID, Property
</del><ins>+from twistedcaldav.vcard import Component as VCard, InvalidVCardDataError, Property, \
+ vCardProductID
</ins><span class="cx">
</span><span class="cx"> from txdav.base.propertystore.base import PropertyName
</span><span class="cx"> from txdav.base.propertystore.sql import PropertyStore
</span><span class="lines">@@ -55,14 +56,13 @@
</span><span class="cx"> from txdav.common.datastore.sql_tables import _ABO_KIND_PERSON, \
</span><span class="cx"> _ABO_KIND_GROUP, _ABO_KIND_RESOURCE, _ABO_KIND_LOCATION, schema, \
</span><span class="cx"> _BIND_MODE_OWN, _BIND_MODE_WRITE, _BIND_STATUS_ACCEPTED, \
</span><del>- _BIND_STATUS_DECLINED, _BIND_STATUS_INVITED
</del><ins>+ _BIND_STATUS_INVITED, _BIND_MODE_READ, _BIND_MODE_INDIRECT, \
+ _BIND_STATUS_DECLINED
</ins><span class="cx"> from txdav.common.icommondatastore import InternalDataStoreError, \
</span><span class="cx"> InvalidUIDError, UIDExistsError, ObjectResourceTooBigError, \
</span><span class="cx"> InvalidObjectResourceError, InvalidComponentForStoreError, \
</span><span class="cx"> AllRetriesFailed, ObjectResourceNameAlreadyExistsError
</span><span class="cx">
</span><del>-from uuid import uuid4
-
</del><span class="cx"> from zope.interface.declarations import implements
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -70,6 +70,8 @@
</span><span class="cx">
</span><span class="cx"> implements(IAddressBookHome)
</span><span class="cx">
</span><ins>+ _homeType = EADDRESSBOOKTYPE
+
</ins><span class="cx"> # structured tables. (new, preferred)
</span><span class="cx"> _homeSchema = schema.ADDRESSBOOK_HOME
</span><span class="cx"> _bindSchema = schema.SHARED_ADDRESSBOOK_BIND
</span><span class="lines">@@ -101,13 +103,36 @@
</span><span class="cx"> removeAddressBookWithName = CommonHome.removeChildWithName
</span><span class="cx">
</span><span class="cx">
</span><del>- @classproperty
- def _resourceIDAndHomeResourceIDFromOwnerQuery(cls): #@NoSelf
- home = cls._homeSchema
- return Select([home.RESOURCE_ID, home.ADDRESSBOOK_PROPERTY_STORE_ID],
- From=home, Where=home.OWNER_UID == Parameter("ownerUID"))
</del><ins>+ @classmethod
+ def homeColumns(cls):
+ """
+ Return a list of column names to retrieve when doing an ownerUID->home lookup.
+ """
</ins><span class="cx">
</span><ins>+ # Common behavior is to have created and modified
</ins><span class="cx">
</span><ins>+ return (
+ cls._homeSchema.RESOURCE_ID,
+ cls._homeSchema.OWNER_UID,
+ cls._homeSchema.ADDRESSBOOK_PROPERTY_STORE_ID,
+ )
+
+
+ @classmethod
+ def homeAttributes(cls):
+ """
+ Return a list of attributes names to map L{homeColumns} to.
+ """
+
+ # Common behavior is to have created and modified
+
+ return (
+ "_resourceID",
+ "_ownerUID",
+ "_addressbookPropertyStoreID",
+ )
+
+
</ins><span class="cx"> @inlineCallbacks
</span><span class="cx"> def initFromStore(self, no_cache=False):
</span><span class="cx"> """
</span><span class="lines">@@ -115,48 +140,27 @@
</span><span class="cx"> extra meta-data from the DB to avoid having to do DB queries for those
</span><span class="cx"> individually later.
</span><span class="cx"> """
</span><del>- result = yield self._cacher.get(self._ownerUID)
- if result is None:
- result = yield self._resourceIDAndHomeResourceIDFromOwnerQuery.on(
- self._txn, ownerUID=self._ownerUID)
- if result and not no_cache:
- yield self._cacher.set(self._ownerUID, result)
</del><span class="cx">
</span><del>- if result:
- self._resourceID, self._addressbookPropertyStoreID = result[0]
-
- queryCacher = self._txn._queryCacher
- if queryCacher:
- # Get cached copy
- cacheKey = queryCacher.keyForHomeMetaData(self._resourceID)
- data = yield queryCacher.get(cacheKey)
- else:
- data = None
- if data is None:
- # Don't have a cached copy
- data = (yield self._metaDataQuery.on(
- self._txn, resourceID=self._resourceID))[0]
- if queryCacher:
- # Cache the data
- yield queryCacher.setAfterCommit(self._txn, cacheKey, data)
-
- # self._created, self._modified = data
- yield self._loadPropertyStore()
-
- # created owned address book
</del><ins>+ result = yield super(AddressBookHome, self).initFromStore(no_cache)
+ if result is not None:
+ # Created owned address book
</ins><span class="cx"> addressbook = AddressBook(
</span><span class="cx"> home=self,
</span><del>- name="addressbook", resourceID=self._resourceID,
- mode=_BIND_MODE_OWN, status=_BIND_STATUS_ACCEPTED,
</del><ins>+ name="addressbook",
+ resourceID=self._resourceID,
+ mode=_BIND_MODE_OWN,
+ status=_BIND_STATUS_ACCEPTED,
</ins><span class="cx"> )
</span><del>- self._created, self._modified = data
</del><span class="cx"> yield addressbook._loadPropertyStore()
</span><del>- yield addressbook._initIsShared()
</del><ins>+
+ # Extra check for shared
+ invites = yield addressbook.sharingInvites()
+ if len(invites) != 0:
+ addressbook._bindMessage = "shared"
+
</ins><span class="cx"> self._addressbook = addressbook
</span><span class="cx">
</span><del>- returnValue(self)
- else:
- returnValue(None)
</del><ins>+ returnValue(result)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="lines">@@ -197,6 +201,22 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><ins>+ def anyObjectWithShareUID(self, shareUID):
+ """
+ Retrieve the child accepted or otherwise with the given bind identifier contained in this
+ home.
+
+ @param name: a string.
+ @return: an L{ICalendar} or C{None} if no such child exists.
+ """
+ result = yield super(AddressBookHome, self).anyObjectWithShareUID(shareUID)
+ if result is None:
+ result = yield AddressBookObject.objectWithBindName(self, shareUID, accepted=None)
+
+ returnValue(result)
+
+
+ @inlineCallbacks
</ins><span class="cx"> def removeUnacceptedShares(self):
</span><span class="cx"> """
</span><span class="cx"> Unbinds any collections that have been shared to this home but not yet
</span><span class="lines">@@ -204,6 +224,7 @@
</span><span class="cx"> """
</span><span class="cx"> super(AddressBookHome, self).removeUnacceptedShares()
</span><span class="cx">
</span><ins>+ # Remove group binds too
</ins><span class="cx"> bind = AddressBookObject._bindSchema
</span><span class="cx"> kwds = {"homeResourceID" : self._resourceID}
</span><span class="cx"> yield Delete(
</span><span class="lines">@@ -217,32 +238,6 @@
</span><span class="cx"> return self._addressbook
</span><span class="cx">
</span><span class="cx">
</span><del>- def shareeAddressBookName(self):
- return self.uid()
-
-
- def objectWithShareUID(self, shareUID):
- """
- Retrieve the child with the given bind identifier contained in this
- home.
-
- @param name: a string.
- @return: an L{ICalendar} or C{None} if no such child exists.
- """
- return self._childClass.objectWithBindName(self, shareUID, accepted=True)
-
-
- def invitedObjectWithShareUID(self, shareUID):
- """
- Retrieve the child invitation with the given bind identifier contained in this
- home.
-
- @param name: a string.
- @return: an L{ICalendar} or C{None} if no such child exists.
- """
- return self._childClass.objectWithBindName(self, shareUID, accepted=False)
-
-
</del><span class="cx"> @inlineCallbacks
</span><span class="cx"> def ownerHomeWithChildID(self, resourceID):
</span><span class="cx"> """
</span><span class="lines">@@ -344,44 +339,92 @@
</span><span class="cx"> Sharing code shared between AddressBook and AddressBookObject
</span><span class="cx"> """
</span><span class="cx">
</span><del>- def setShared(self, shared):
</del><ins>+ def sharedResourceType(self):
</ins><span class="cx"> """
</span><del>- Set an owned collection to shared or unshared state. Technically this is not useful as "shared"
- really means it has invitees, but the current sharing spec supports a notion of a shared collection
- that has not yet had invitees added. For the time being we will support that option by using a new
- MESSAGE value to indicate an owned collection that is "shared".
</del><ins>+ The sharing resource type
+ """
+ return "addressbook"
</ins><span class="cx">
</span><del>- @param shared: whether or not the owned collection is "shared"
- @type shared: C{bool}
</del><ins>+
+ @inlineCallbacks
+ def deleteShare(self):
</ins><span class="cx"> """
</span><del>- if self.owned():
- self._bindMessage = "shared" if shared else None
</del><ins>+ This share is being deleted - decline and decline shared groups too.
+ """
</ins><span class="cx">
</span><ins>+ ownerView = yield self.ownerView()
+ if self.direct():
+ yield ownerView.removeShare(self)
+ else:
+ if self.fullyShared():
+ yield self.declineShare()
+ else:
+ # Decline each shared group
+ acceptedGroupIDs = yield self.acceptedGroupIDs()
+ if acceptedGroupIDs:
+ rows = (yield self._objectResourceNamesWithResourceIDsQuery(acceptedGroupIDs).on(
+ self._txn, resourceIDs=acceptedGroupIDs
+ ))
+ groupNames = sorted([row[0] for row in rows])
+ for group in groupNames:
+ groupObject = yield self.objectResourceWithName(group)
+ yield groupObject.declineShare()
</ins><span class="cx">
</span><ins>+
+ def newShareName(self):
+ """
+ For shared address books the resource name of a share is the ownerUID of the owner's resource.
+ """
+ return self.ownerHome().uid()
+
+
</ins><span class="cx"> @inlineCallbacks
</span><del>- def _isSharedOrInvited(self):
</del><ins>+ def newShare(self, displayname=None):
</ins><span class="cx"> """
</span><del>- return True if this L{AddressBook} is shared or invited
</del><ins>+ Override in derived classes to do any specific operations needed when a share
+ is first accepted.
</ins><span class="cx"> """
</span><del>- sharedRows = []
- if self.owned():
- bind = self._bindSchema
- sharedRows = yield self._bindFor(
- (bind.RESOURCE_ID == Parameter("resourceID"))).on(
- self._txn, resourceID=self._resourceID,
- )
</del><span class="cx">
</span><del>- returnValue(bool(sharedRows))
</del><ins>+ # For a direct share we will copy any displayname over using the owners view
+ if self.direct():
+ ownerView = yield self.ownerView()
+ try:
+ displayname = ownerView.properties()[PropertyName.fromElement(element.DisplayName)]
+ self.properties()[PropertyName.fromElement(element.DisplayName)] = displayname
+ except KeyError:
+ pass
</ins><span class="cx">
</span><span class="cx">
</span><ins>+ def fullyShared(self):
+ return not self.owned() and not self.indirect() and self.accepted()
+
+
</ins><span class="cx"> @inlineCallbacks
</span><del>- def _initIsShared(self):
- isShared = yield self._isSharedOrInvited()
- self.setShared(isShared)
</del><ins>+ def _previousAcceptCount(self):
+ previouslyAcceptedBindCount = 1 if self.fullyShared() else 0
+ previouslyAcceptedBindCount += len((yield AddressBookObject._acceptedBindForHomeIDAndAddressBookID.on(
+ self._txn, homeID=self._home._resourceID, addressbookID=self._resourceID
+ )))
+ returnValue(previouslyAcceptedBindCount)
</ins><span class="cx">
</span><span class="cx">
</span><ins>+ @inlineCallbacks
+ def _changedStatus(self, previouslyAcceptedCount):
+ if self._bindStatus == _BIND_STATUS_ACCEPTED:
+ if 0 == previouslyAcceptedCount:
+ yield self._initSyncToken()
+ yield self._initBindRevision()
+ self._home._children[self._name] = self
+ self._home._children[self._resourceID] = self
+ elif self._bindStatus == _BIND_STATUS_DECLINED:
+ if 1 == previouslyAcceptedCount:
+ yield self._deletedSyncToken(sharedRemoval=True)
+ self._home._children.pop(self._name, None)
+ self._home._children.pop(self._resourceID, None)
</ins><span class="cx">
</span><del>-class AddressBook(CommonHomeChild, AddressBookSharingMixIn):
</del><ins>+
+
+class AddressBook(AddressBookSharingMixIn, CommonHomeChild):
</ins><span class="cx"> """
</span><span class="cx"> SQL-based implementation of L{IAddressBook}.
</span><span class="cx"> """
</span><span class="lines">@@ -396,11 +439,10 @@
</span><span class="cx"> _objectSchema = schema.ADDRESSBOOK_OBJECT
</span><span class="cx">
</span><span class="cx">
</span><del>- def __init__(self, home, name, resourceID, mode, status, revision=0, message=None, ownerHome=None, bindName=None):
</del><ins>+ def __init__(self, home, name, resourceID, mode, status, revision=0, message=None, ownerHome=None, ownerName=None):
</ins><span class="cx"> ownerName = ownerHome.addressbook().name() if ownerHome else None
</span><span class="cx"> super(AddressBook, self).__init__(home, name, resourceID, mode, status, revision=revision, message=message, ownerHome=ownerHome, ownerName=ownerName)
</span><span class="cx"> self._index = PostgresLegacyABIndexEmulator(self)
</span><del>- self._bindName = bindName
</del><span class="cx">
</span><span class="cx">
</span><span class="cx"> def __repr__(self):
</span><span class="lines">@@ -412,7 +454,8 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def setCreated(self, newValue):
</span><del>- self.ownerHome()._created = newValue
</del><ins>+ if newValue is not None:
+ self.ownerHome()._created = newValue
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def getModified(self):
</span><span class="lines">@@ -420,36 +463,13 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def setModified(self, newValue):
</span><del>- self.ownerHome()._modified = newValue
</del><ins>+ if newValue is not None:
+ self.ownerHome()._modified = newValue
</ins><span class="cx">
</span><span class="cx"> _created = property(getCreated, setCreated,)
</span><span class="cx"> _modified = property(getModified, setModified,)
</span><span class="cx">
</span><del>- ownerAddressBookHome = CommonHomeChild.ownerHome
- viewerAddressBookHome = CommonHomeChild.viewerHome
- addressbookObjects = CommonHomeChild.objectResources
- listAddressBookObjects = CommonHomeChild.listObjectResources
- addressbookObjectWithName = CommonHomeChild.objectResourceWithName
- addressbookObjectWithUID = CommonHomeChild.objectResourceWithUID
- createAddressBookObjectWithName = CommonHomeChild.createObjectResourceWithName
- addressbookObjectsSinceToken = CommonHomeChild.objectResourcesSinceToken
</del><span class="cx">
</span><del>-
- def shareeName(self):
- """
- The sharee's name for a shared address book is the sharer's home ownerUID.
- """
- return self.ownerHome().shareeAddressBookName()
-
-
- def bindNameIsResourceName(self):
- """
- For shared address books the resource name of an accepted share is not the same as the name
- in the bind table.
- """
- return False
-
-
</del><span class="cx"> @inlineCallbacks
</span><span class="cx"> def _loadPropertyStore(self, props=None):
</span><span class="cx"> if props is None:
</span><span class="lines">@@ -534,22 +554,23 @@
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def listObjectResources(self):
</span><span class="cx"> if self._objectNames is None:
</span><ins>+ # Check for non-group shared
</ins><span class="cx"> if self.owned() or self.fullyShared():
</span><del>- rows = yield self._objectResourceNamesQuery.on(
- self._txn, resourceID=self._resourceID)
</del><ins>+ yield super(AddressBook, self).listObjectResources()
+
+ # Group shared
</ins><span class="cx"> else:
</span><span class="cx"> acceptedGroupIDs = yield self.acceptedGroupIDs()
</span><span class="cx"> allowedObjectIDs = yield self.expandGroupIDs(self._txn, acceptedGroupIDs)
</span><span class="cx"> rows = (yield self._objectResourceNamesWithResourceIDsQuery(allowedObjectIDs).on(
</span><span class="cx"> self._txn, resourceIDs=allowedObjectIDs
</span><span class="cx"> ))
</span><del>- objectNames = [row[0] for row in rows]
</del><ins>+ self._objectNames = sorted([row[0] for row in rows])
</ins><span class="cx">
</span><del>- # account for fully-shared address book group
</del><ins>+ # Account for fully-shared address book group
</ins><span class="cx"> if self.fullyShared():
</span><del>- if not self._groupForSharedAddressBookName() in objectNames:
- objectNames.append(self._groupForSharedAddressBookName())
- self._objectNames = sorted(objectNames)
</del><ins>+ if not self._groupForSharedAddressBookName() in self._objectNames:
+ self._objectNames.append(self._groupForSharedAddressBookName())
</ins><span class="cx">
</span><span class="cx"> returnValue(self._objectNames)
</span><span class="cx">
</span><span class="lines">@@ -557,18 +578,19 @@
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def countObjectResources(self):
</span><span class="cx"> if self._objectNames is None:
</span><ins>+ # Check for non-group shared
</ins><span class="cx"> if self.owned() or self.fullyShared():
</span><del>- rows = yield self._objectCountQuery.on(
- self._txn, resourceID=self._resourceID
- )
- count = rows[0][0]
</del><ins>+ count = yield super(AddressBook, self).countObjectResources()
+
+ # Group shared
</ins><span class="cx"> else:
</span><span class="cx"> acceptedGroupIDs = yield self.acceptedGroupIDs()
</span><span class="cx"> count = len((yield self.expandGroupIDs(self._txn, acceptedGroupIDs)))
</span><span class="cx">
</span><del>- # account for fully-shared address book group
</del><ins>+ # Account for fully-shared address book group
</ins><span class="cx"> if self.fullyShared():
</span><span class="cx"> count += 1
</span><ins>+
</ins><span class="cx"> returnValue(count)
</span><span class="cx">
</span><span class="cx"> returnValue(len(self._objectNames))
</span><span class="lines">@@ -609,7 +631,7 @@
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def _groupForSharedAddressBookComponent(self):
</span><span class="cx">
</span><del>- n = self.shareeName()
</del><ins>+ n = self.viewerHome().uid()
</ins><span class="cx"> fn = n
</span><span class="cx"> uid = self._groupForSharedAddressBookUID()
</span><span class="cx">
</span><span class="lines">@@ -621,14 +643,18 @@
</span><span class="cx"> component = VCard.fromString(
</span><span class="cx"> """BEGIN:VCARD
</span><span class="cx"> VERSION:3.0
</span><del>-PRODID:%s
-UID:%s
-FN:%s
-N:%s;;;;
</del><ins>+PRODID:{prodid}
+UID:{uid}
+FN:{fn}
+N:{n};;;;
</ins><span class="cx"> X-ADDRESSBOOKSERVER-KIND:group
</span><span class="cx"> END:VCARD
</span><del>-""".replace("\n", "\r\n") % (vCardProductID, uid, n, fn,)
- )
</del><ins>+""".replace("\n", "\r\n").format(
+ prodid=vCardProductID,
+ uid=uid,
+ fn=fn,
+ n=n,
+ ))
</ins><span class="cx">
</span><span class="cx"> # then get member UIDs
</span><span class="cx"> abo = schema.ADDRESSBOOK_OBJECT
</span><span class="lines">@@ -660,6 +686,35 @@
</span><span class="cx">
</span><span class="cx"> @classmethod
</span><span class="cx"> @inlineCallbacks
</span><ins>+ def listObjects(cls, home):
+ """
+ Retrieve the names of the children with invitations in the given home. Make sure
+ to include the default owner address book.
+
+ @return: an iterable of C{str}s.
+ """
+
+ # Default address book
+ names = set([home.addressbook().name()])
+
+ # Fully shared address books
+ names |= set((yield super(AddressBook, cls).listObjects(home)))
+
+ # Group shared
+ groupRows = yield AddressBookObject._acceptedBindForHomeID.on(
+ home._txn, homeID=home._resourceID
+ )
+ for groupRow in groupRows:
+ bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = groupRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
+ ownerAddressBookID = yield AddressBookObject.ownerAddressBookIDFromGroupID(home._txn, resourceID)
+ ownerHome = yield home._txn.homeWithResourceID(home._homeType, ownerAddressBookID, create=True)
+ names |= set([ownerHome.uid()])
+
+ returnValue(tuple(names))
+
+
+ @classmethod
+ @inlineCallbacks
</ins><span class="cx"> def loadAllObjects(cls, home):
</span><span class="cx"> """
</span><span class="cx"> Load all L{CommonHomeChild} instances which are children of a given
</span><span class="lines">@@ -668,6 +723,7 @@
</span><span class="cx"> operations to keep this constant wrt the number of children. This is an
</span><span class="cx"> optimization for Depth:1 operations on the home.
</span><span class="cx"> """
</span><ins>+
</ins><span class="cx"> results = [home.addressbook()]
</span><span class="cx"> ownerHomeToDataRowMap = {}
</span><span class="cx">
</span><span class="lines">@@ -686,11 +742,11 @@
</span><span class="cx"> home._txn, homeID=home._resourceID
</span><span class="cx"> )
</span><span class="cx"> for groupBindRow in groupBindRows:
</span><del>- bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
</del><ins>+ bindMode, homeID, resourceID, name, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
</ins><span class="cx"> ownerAddressBookID = yield AddressBookObject.ownerAddressBookIDFromGroupID(home._txn, resourceID)
</span><span class="cx"> ownerHome = yield home.ownerHomeWithChildID(ownerAddressBookID)
</span><span class="cx"> if ownerHome not in ownerHomeToDataRowMap:
</span><del>- groupBindRow[0] = _BIND_MODE_WRITE
</del><ins>+ groupBindRow[0] = _BIND_MODE_INDIRECT
</ins><span class="cx"> groupBindRow[3] = None # bindName
</span><span class="cx"> groupBindRow[4] = None # bindStatus
</span><span class="cx"> groupBindRow[6] = None # bindMessage
</span><span class="lines">@@ -709,18 +765,19 @@
</span><span class="cx">
</span><span class="cx"> # Create the actual objects merging in properties
</span><span class="cx"> for ownerHome, dataRow in ownerHomeToDataRowMap.iteritems():
</span><del>- bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = dataRow[:cls.bindColumnCount] #@UnusedVariable
</del><ins>+ bindMode, homeID, resourceID, name, bindStatus, bindRevision, bindMessage = dataRow[:cls.bindColumnCount] #@UnusedVariable
</ins><span class="cx"> additionalBind = dataRow[cls.bindColumnCount:cls.bindColumnCount + len(cls.additionalBindColumns())]
</span><span class="cx"> metadata = dataRow[cls.bindColumnCount + len(cls.additionalBindColumns()):]
</span><span class="cx">
</span><span class="cx"> child = cls(
</span><span class="cx"> home=home,
</span><del>- name=ownerHome.shareeAddressBookName(),
</del><ins>+ name=ownerHome.uid(),
</ins><span class="cx"> resourceID=ownerHome._resourceID,
</span><del>- mode=bindMode, status=bindStatus,
</del><ins>+ mode=bindMode,
+ status=bindStatus,
</ins><span class="cx"> revision=bindRevision,
</span><del>- message=bindMessage, ownerHome=ownerHome,
- bindName=bindName
</del><ins>+ message=bindMessage,
+ ownerHome=ownerHome,
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx"> for attr, value in zip(cls.additionalBindAttributes(), additionalBind):
</span><span class="lines">@@ -750,231 +807,135 @@
</span><span class="cx">
</span><span class="cx"> @param name: a string; the name of the L{CommonHomeChild} to retrieve.
</span><span class="cx">
</span><del>- @return: an L{CommonHomeChild} or C{None} if no such child
- exists.
</del><ins>+ @return: an L{CommonHomeChild} or C{None} if no such child exists.
</ins><span class="cx"> """
</span><del>- if accepted and name == home.addressbook().name():
</del><ins>+
+ # Try owned address book first
+ if name == home.addressbook().name():
</ins><span class="cx"> returnValue(home.addressbook())
</span><del>- # shared address books only from this point on
</del><span class="cx">
</span><del>- rows = None
- queryCacher = home._txn._queryCacher
- ownerHome = None
</del><ins>+ # Try fully shared next
+ result = yield super(AddressBook, cls).objectWithName(home, name, accepted)
</ins><span class="cx">
</span><del>- if queryCacher:
- # Retrieve data from cache
- cacheKey = queryCacher.keyForObjectWithName(home._resourceID, name)
- cachedRows = yield queryCacher.get(cacheKey)
- if cachedRows and (cachedRows[0][4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
- rows = cachedRows
</del><ins>+ # Look for indirect shares
+ if result is None:
+ result = yield cls._indirectObjectWithNameOrID(home, name=name, accepted=accepted)
</ins><span class="cx">
</span><del>- if not rows:
- # name must be a home uid
- ownerHome = yield home._txn.addressbookHomeWithUID(name)
- if ownerHome:
- # see if address book resource id in bind table
- ownerAddressBook = ownerHome.addressbook()
- bindRows = yield cls._bindForResourceIDAndHomeID.on(
- home._txn, resourceID=ownerAddressBook._resourceID, homeID=home._resourceID
- )
- if bindRows and (bindRows[0][4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
- bindRows[0].insert(cls.bindColumnCount, ownerAddressBook._resourceID)
- bindRows[0].insert(cls.bindColumnCount + 1, bindRows[0][4]) # cachedStatus = bindStatus
- rows = bindRows
- else:
- groupBindRows = yield AddressBookObject._bindForHomeIDAndAddressBookID.on(
- home._txn, homeID=home._resourceID, addressbookID=ownerAddressBook._resourceID
- )
- for groupBindRow in groupBindRows:
- if (groupBindRow[4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
- groupBindRow.insert(AddressBookObject.bindColumnCount, ownerAddressBook._resourceID)
- groupBindRow.insert(AddressBookObject.bindColumnCount + 1, groupBindRow[4])
- groupBindRow[0] = _BIND_MODE_WRITE
- groupBindRow[3] = None # bindName
- groupBindRow[4] = None # bindStatus
- groupBindRow[6] = None # bindMessage
- rows = [groupBindRow]
- break
</del><ins>+ returnValue(result)
</ins><span class="cx">
</span><del>- if rows and queryCacher:
- # Cache the result
- queryCacher.setAfterCommit(home._txn, cacheKey, rows)
</del><span class="cx">
</span><del>- if not rows:
- returnValue(None)
-
- row = rows[0]
- bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage, ownerAddressBookID, cachedBindStatus = row[:cls.bindColumnCount + 2] #@UnusedVariable
-
- # if wrong status, exit here. Item is in queryCache
- if (cachedBindStatus == _BIND_STATUS_ACCEPTED) != bool(accepted):
- returnValue(None)
-
- ownerHome = yield home.ownerHomeWithChildID(ownerAddressBookID)
- child = cls(
- home=home,
- name=ownerHome.shareeAddressBookName(), resourceID=ownerAddressBookID,
- mode=bindMode, status=bindStatus,
- revision=bindRevision,
- message=bindMessage, ownerHome=ownerHome,
- bindName=bindName,
- )
- yield child.initFromStore()
- returnValue(child)
-
-
</del><span class="cx"> @classmethod
</span><span class="cx"> @inlineCallbacks
</span><del>- def objectWithBindName(cls, home, name, accepted):
</del><ins>+ def objectWithID(cls, home, resourceID, accepted=True):
</ins><span class="cx"> """
</span><del>- Retrieve the child or objectResource with the given bind name C{name} contained in the given
</del><ins>+ Retrieve the child with the given C{resourceID} contained in the given
</ins><span class="cx"> C{home}.
</span><span class="cx">
</span><span class="cx"> @param home: a L{CommonHome}.
</span><del>-
- @param name: a string; the name of the L{CommonHomeChild} to retrieve.
-
- @return: an L{CommonHomeChild} or L{ObjectResource} or C{None} if no such child
</del><ins>+ @param resourceID: a string.
+ @return: an L{CommonHomeChild} or C{None} if no such child
</ins><span class="cx"> exists.
</span><span class="cx"> """
</span><del>- bindRows = yield cls._bindForNameAndHomeID.on(home._txn, name=name, homeID=home._resourceID)
- if bindRows and (bindRows[0][4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
- bindRow = bindRows[0]
- bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = bindRow[:cls.bindColumnCount] #@UnusedVariable
</del><span class="cx">
</span><del>- # alt:
- # returnValue((yield cls.objectWithID(home, resourceID)))
- ownerHome = yield home.ownerHomeWithChildID(resourceID)
- if accepted:
- returnValue((yield home.childWithName(ownerHome.shareeAddressBookName())))
- else:
- returnValue((yield cls.objectWithName(home, ownerHome.shareeAddressBookName(), accepted=False)))
</del><ins>+ # Try owned address book first
+ if home._resourceID == resourceID:
+ returnValue(home.addressbook())
</ins><span class="cx">
</span><del>- groupBindRows = yield AddressBookObject._bindForNameAndHomeID.on(
- home._txn, name=name, homeID=home._resourceID
- )
- if groupBindRows and (groupBindRows[0][4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
- groupBindRow = groupBindRows[0]
- bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
</del><ins>+ # Try fully shared next
+ result = yield super(AddressBook, cls).objectWithID(home, resourceID, accepted)
</ins><span class="cx">
</span><del>- ownerAddressBookID = yield AddressBookObject.ownerAddressBookIDFromGroupID(home._txn, resourceID)
- # alt:
- # addressbook = yield cls.objectWithID(home, ownerAddressBookID)
- ownerHome = yield home.ownerHomeWithChildID(ownerAddressBookID)
- addressbook = yield home.childWithName(ownerHome.shareeAddressBookName())
- if not addressbook:
- addressbook = yield cls.objectWithName(home, ownerHome.shareeAddressBookName(), accepted=False)
- assert addressbook
</del><ins>+ # Look for indirect shares
+ if result is None:
+ result = yield cls._indirectObjectWithNameOrID(home, resourceID=resourceID, accepted=accepted)
</ins><span class="cx">
</span><del>- if accepted:
- returnValue((yield addressbook.objectResourceWithID(resourceID)))
- else:
- returnValue((yield AddressBookObject.objectWithID(addressbook, resourceID))) # avoids object cache
</del><ins>+ returnValue(result)
</ins><span class="cx">
</span><del>- returnValue(None)
</del><span class="cx">
</span><del>-
</del><span class="cx"> @classmethod
</span><span class="cx"> @inlineCallbacks
</span><del>- def objectWithID(cls, home, resourceID, accepted=True):
</del><ins>+ def _indirectObjectWithNameOrID(cls, home, name=None, resourceID=None, accepted=True):
+ # replaces objectWithName()
</ins><span class="cx"> """
</span><del>- Retrieve the child with the given C{resourceID} contained in the given
- C{home}.
</del><ins>+ Synthesize and indirect child for matching name or id based on whether shared groups exist.
</ins><span class="cx">
</span><span class="cx"> @param home: a L{CommonHome}.
</span><del>- @param resourceID: a string.
</del><ins>+
+ @param name: a string; the name of the L{CommonHomeChild} to retrieve.
+
</ins><span class="cx"> @return: an L{CommonHomeChild} or C{None} if no such child
</span><span class="cx"> exists.
</span><span class="cx"> """
</span><del>- if home._resourceID == resourceID:
- returnValue(home.addressbook())
</del><ins>+ rows = None
+ ownerHome = None
</ins><span class="cx">
</span><del>- bindRows = yield cls._bindForResourceIDAndHomeID.on(
- home._txn, resourceID=resourceID, homeID=home._resourceID
- )
- if bindRows and (bindRows[0][4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
- bindRow = bindRows[0]
- bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = bindRow[:cls.bindColumnCount] #@UnusedVariable
</del><ins>+ # TODO: add queryCacher support
</ins><span class="cx">
</span><del>- ownerHome = yield home.ownerHomeWithChildID(resourceID)
- if accepted:
- returnValue((yield home.childWithName(ownerHome.shareeAddressBookName())))
- else:
- returnValue((yield cls.objectWithName(home, ownerHome.shareeAddressBookName(), accepted=False)))
</del><ins>+ if rows is None:
+ # No cached copy
+ if name:
+ ownerHome = yield home._txn.addressbookHomeWithUID(name)
+ if ownerHome is None:
+ returnValue(None)
+ resourceID = ownerHome.addressbook()._resourceID
+ rows = yield AddressBookObject._bindForHomeIDAndAddressBookID.on(
+ home._txn, homeID=home._resourceID, addressbookID=resourceID
+ )
</ins><span class="cx">
</span><del>- groupBindRows = yield AddressBookObject._bindForHomeIDAndAddressBookID.on(
- home._txn, homeID=home._resourceID, addressbookID=resourceID
- )
- if groupBindRows and (groupBindRows[0][4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
- groupBindRow = groupBindRows[0]
- bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
</del><ins>+ if not rows:
+ returnValue(None)
</ins><span class="cx">
</span><del>- ownerAddressBookID = yield AddressBookObject.ownerAddressBookIDFromGroupID(home._txn, resourceID)
- ownerHome = yield home.ownerHomeWithChildID(ownerAddressBookID)
- if accepted:
- returnValue((yield home.childWithName(ownerHome.shareeAddressBookName())))
- else:
- returnValue((yield cls.objectWithName(home, ownerHome.shareeAddressBookName(), accepted=False)))
</del><ins>+ groupID = None
+ overallBindStatus = _BIND_STATUS_INVITED
+ minBindRevision = None
+ for row in rows:
+ bindMode, homeID, resourceGroupID, name, bindStatus, bindRevision, bindMessage = row[:cls.bindColumnCount] #@UnusedVariable
+ if groupID is None:
+ groupID = resourceGroupID
+ minBindRevision = min(minBindRevision, bindRevision) if minBindRevision is not None else bindRevision
+ if bindStatus == _BIND_STATUS_ACCEPTED:
+ overallBindStatus = _BIND_STATUS_ACCEPTED
</ins><span class="cx">
</span><del>- returnValue(None)
</del><ins>+ if accepted is not None and (overallBindStatus == _BIND_STATUS_ACCEPTED) != bool(accepted):
+ returnValue(None)
+ additionalBind = row[cls.bindColumnCount:cls.bindColumnCount + len(cls.additionalBindColumns())]
</ins><span class="cx">
</span><ins>+ if ownerHome is None:
+ ownerAddressBookID = yield AddressBookObject.ownerAddressBookIDFromGroupID(home._txn, groupID)
+ ownerHome = yield home.ownerHomeWithChildID(ownerAddressBookID)
</ins><span class="cx">
</span><del>- def shareUID(self):
- """
- @see: L{ICalendar.shareUID}
- """
- return self._bindName
-
-
- def fullyShared(self):
- return not self.owned() and self._bindStatus == _BIND_STATUS_ACCEPTED
-
-
- @classmethod
- @inlineCallbacks
- def listObjects(cls, home):
- """
- Retrieve the names of the children with invitations in the given home.
-
- @return: an iterable of C{str}s.
- """
- names = set([home.addressbook().name()])
-
- rows = yield cls._acceptedBindForHomeID.on(
- home._txn, homeID=home._resourceID
</del><ins>+ child = cls(
+ home=home,
+ name=ownerHome.uid(),
+ resourceID=resourceID,
+ mode=_BIND_MODE_INDIRECT,
+ status=overallBindStatus,
+ revision=minBindRevision,
+ message="",
+ ownerHome=ownerHome,
+ ownerName=ownerHome.uid()
</ins><span class="cx"> )
</span><del>- for row in rows:
- bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = row[:cls.bindColumnCount] #@UnusedVariable
- ownerHome = yield home._txn.homeWithResourceID(home._homeType, resourceID, create=True)
- names |= set([ownerHome.shareeAddressBookName()])
</del><ins>+ yield child.initFromStore(additionalBind)
+ returnValue(child)
</ins><span class="cx">
</span><del>- groupRows = yield AddressBookObject._acceptedBindForHomeID.on(
- home._txn, homeID=home._resourceID
- )
- for groupRow in groupRows:
- bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = groupRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
- ownerAddressBookID = yield AddressBookObject.ownerAddressBookIDFromGroupID(home._txn, resourceID)
- ownerHome = yield home._txn.homeWithResourceID(home._homeType, ownerAddressBookID, create=True)
- names |= set([ownerHome.shareeAddressBookName()])
- returnValue(tuple(names))
</del><span class="cx">
</span><del>-
</del><span class="cx"> @classmethod
</span><span class="cx"> def _memberIDsWithGroupIDsQuery(cls, groupIDs):
</span><span class="cx"> """
</span><span class="cx"> DAL query to load all object resource names for a home child.
</span><span class="cx"> """
</span><span class="cx"> aboMembers = schema.ABO_MEMBERS
</span><del>- return Select([aboMembers.MEMBER_ID], From=aboMembers,
- Where=aboMembers.GROUP_ID.In(Parameter("groupIDs", len(groupIDs))),
- )
</del><ins>+ return Select(
+ [aboMembers.MEMBER_ID],
+ From=aboMembers,
+ Where=aboMembers.GROUP_ID.In(Parameter("groupIDs", len(groupIDs))),
+ )
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> @classmethod
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def expandGroupIDs(cls, txn, groupIDs, includeGroupIDs=True):
</span><span class="cx"> """
</span><del>- Get all AddressBookObject resource IDs contains in the given shared groups with the given groupIDs
</del><ins>+ Get all AddressBookObject resource IDs contained in the given shared groups with the given groupIDs
</ins><span class="cx"> """
</span><span class="cx"> objectIDs = set(groupIDs) if includeGroupIDs else set()
</span><span class="cx"> examinedIDs = set()
</span><span class="lines">@@ -992,38 +953,49 @@
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def unacceptedGroupIDs(self):
</span><ins>+ """
+ Return the list of shared groups that have not yet been accepted.
+ """
</ins><span class="cx"> if self.owned():
</span><span class="cx"> returnValue([])
</span><span class="cx"> else:
</span><span class="cx"> groupBindRows = yield AddressBookObject._unacceptedBindForHomeIDAndAddressBookID.on(
</span><del>- self._txn, homeID=self._home._resourceID, addressbookID=self._resourceID
</del><ins>+ self._txn, homeID=self._home._resourceID, addressbookID=self._resourceID
</ins><span class="cx"> )
</span><span class="cx"> returnValue([groupBindRow[2] for groupBindRow in groupBindRows])
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def acceptedGroupIDs(self):
</span><ins>+ """
+ Return the list of accepted shared groups.
+ """
</ins><span class="cx"> if self.owned():
</span><span class="cx"> returnValue([])
</span><span class="cx"> else:
</span><span class="cx"> groupBindRows = yield AddressBookObject._acceptedBindForHomeIDAndAddressBookID.on(
</span><del>- self._txn, homeID=self._home._resourceID, addressbookID=self._resourceID
</del><ins>+ self._txn, homeID=self._home._resourceID, addressbookID=self._resourceID
</ins><span class="cx"> )
</span><span class="cx"> returnValue([groupBindRow[2] for groupBindRow in groupBindRows])
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def accessControlGroupIDs(self):
</span><ins>+ """
+ For each accepted shared group, determine what its access mode is and return the sets of read-only
+ and read-write groups. Handle the case where a read-only group is actually nested in a read-write
+ group by putting the read-only one into the read-write list.
+ """
</ins><span class="cx"> if self.owned():
</span><span class="cx"> returnValue(([], []))
</span><span class="cx"> else:
</span><span class="cx"> groupBindRows = yield AddressBookObject._acceptedBindForHomeIDAndAddressBookID.on(
</span><del>- self._txn, homeID=self._home._resourceID, addressbookID=self._resourceID
</del><ins>+ self._txn, homeID=self._home._resourceID, addressbookID=self._resourceID
</ins><span class="cx"> )
</span><span class="cx"> readWriteGroupIDs = []
</span><span class="cx"> readOnlyGroupIDs = []
</span><span class="cx"> for groupBindRow in groupBindRows:
</span><del>- bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
</del><ins>+ bindMode, homeID, resourceID, name, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
</ins><span class="cx"> if bindMode == _BIND_MODE_WRITE:
</span><span class="cx"> readWriteGroupIDs.append(resourceID)
</span><span class="cx"> else:
</span><span class="lines">@@ -1054,24 +1026,37 @@
</span><span class="cx"> # FIXME: Unused: Use for caching access
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def accessControlObjectIDs(self):
</span><ins>+ """
+ For each object resource in this collection, determine what its access mode is and return the sets of read-only
+ and read-write objects. Handle the case where a read-only group is actually nested in a read-write
+ group by putting the read-only one into the read-write list.
+ """
+
</ins><span class="cx"> readOnlyIDs = set()
</span><span class="cx"> readWriteIDs = set()
</span><del>- if self.owned() or self.fullyShared():
- rows = yield self._allColumnsWithParent(self)
- ids = set([row[1] for row in rows])
- if self.fullyShared():
- ids |= set([self._resourceID, ])
- if self.owned() or self._bindMode == _BIND_MODE_WRITE:
- returnValue(tuple(readOnlyIDs), tuple(readWriteIDs))
</del><ins>+
+ # All objects in the collection
+ rows = yield self._allColumnsWithParent(self)
+ ids = set([row[1] for row in rows])
+
+ # Everything is read-write
+ if self.owned() or self.fullyShared() and self._bindMode == _BIND_MODE_WRITE:
+ returnValue(tuple(readOnlyIDs), tuple(ids))
+
+ # Fully shared but mode is read-only
+ if self.fullyShared() and self._bindMode == _BIND_MODE_READ:
+ ids |= set([self._resourceID, ])
</ins><span class="cx"> readOnlyIDs = set(ids)
</span><span class="cx">
</span><ins>+ # Look for shared groups and for those that are read-write, transfer their object ids
+ # to the read-write set
</ins><span class="cx"> groupBindRows = yield AddressBookObject._acceptedBindForHomeIDAndAddressBookID.on(
</span><del>- self._txn, homeID=self._home._resourceID, addressbookID=self._resourceID
</del><ins>+ self._txn, homeID=self._home._resourceID, addressbookID=self._resourceID
</ins><span class="cx"> )
</span><span class="cx"> readWriteGroupIDs = []
</span><span class="cx"> readOnlyGroupIDs = []
</span><span class="cx"> for groupBindRow in groupBindRows:
</span><del>- bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
</del><ins>+ bindMode, homeID, resourceID, name, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
</ins><span class="cx"> if bindMode == _BIND_MODE_WRITE:
</span><span class="cx"> readWriteGroupIDs.append(resourceID)
</span><span class="cx"> else:
</span><span class="lines">@@ -1103,10 +1088,151 @@
</span><span class="cx"> readOnlyIDs, readWriteIDs = yield self.accessControlObjectIDs()
</span><span class="cx"> returnValue((readOnlyIDs + readWriteIDs))
</span><span class="cx">
</span><ins>+ # Convenient names for some methods
+ ownerAddressBookHome = CommonHomeChild.ownerHome
+ viewerAddressBookHome = CommonHomeChild.viewerHome
+ addressbookObjects = CommonHomeChild.objectResources
+ listAddressBookObjects = listObjectResources
+ countAddressBookObjects = countObjectResources
+ addressbookObjectWithName = CommonHomeChild.objectResourceWithName
+ addressbookObjectWithUID = CommonHomeChild.objectResourceWithUID
+ createAddressBookObjectWithName = CommonHomeChild.createObjectResourceWithName
+ addressbookObjectsSinceToken = CommonHomeChild.objectResourcesSinceToken
</ins><span class="cx">
</span><ins>+
+
+class AddressBookObjectSharingMixIn(SharingMixIn):
+ """
+ Sharing code for AddressBookObject
+ """
+
+ def sharedResourceType(self):
+ """
+ The sharing resource type
+ """
+ return "group"
+
+
+ #
+ # Lower level API
+ #
+
</ins><span class="cx"> @inlineCallbacks
</span><del>- def updateShare(self, shareeView, mode=None, status=None, message=None):
</del><ins>+ def ownerView(self):
</ins><span class="cx"> """
</span><ins>+ Return the owner resource counterpart of this shared resource.
+ """
+ # Get the child of the owner home that has the same resource id as the owned one
+ ownerView = yield self.ownerHome().addressbook().objectResourceWithID(self.id())
+ returnValue(ownerView)
+
+
+ @inlineCallbacks
+ def shareeView(self, shareeUID):
+ """
+ Return the shared resource counterpart of this owned resource for the specified sharee.
+ """
+
+ # Get the shared address book, then the child within
+ shareeAdbk = yield self.addressbook().shareeView(shareeUID)
+ shareeView = (yield shareeAdbk.objectResourceWithID(self.id())) if shareeAdbk is not None else None
+ returnValue(shareeView if shareeView is not None and shareeView.shareMode() is not None else None)
+
+
+ @inlineCallbacks
+ def shareWith(self, shareeHome, mode, status=None, summary=None):
+ """
+ Share this (owned) L{AddressBookObject} with another home.
+
+ @param shareeHome: The home of the sharee.
+ @type shareeHome: L{CommonHome}
+
+ @param mode: The sharing mode; L{_BIND_MODE_READ} or
+ L{_BIND_MODE_WRITE} or L{_BIND_MODE_DIRECT}
+ @type mode: L{str}
+
+ @param status: The sharing status; L{_BIND_STATUS_INVITED} or
+ L{_BIND_STATUS_ACCEPTED}
+ @type mode: L{str}
+
+ @param summary: The proposed message to go along with the share, which
+ will be used as the default display name.
+ @type summary: L{str}
+
+ @return: the name of the shared group in the sharee home.
+ @rtype: L{str}
+ """
+
+ if status is None:
+ status = _BIND_STATUS_ACCEPTED
+
+ @inlineCallbacks
+ def doInsert(subt):
+ newName = self.newShareName()
+ yield self._bindInsertQuery.on(
+ subt,
+ homeID=shareeHome._resourceID,
+ resourceID=self._resourceID,
+ name=newName,
+ mode=mode,
+ bindStatus=status,
+ message=summary
+ )
+ returnValue(newName)
+ try:
+ bindName = yield self._txn.subtransaction(doInsert)
+ except AllRetriesFailed:
+ group = yield self.shareeView(shareeHome.uid())
+ yield self.updateShare(
+ group, mode=mode, status=status,
+ summary=summary
+ )
+ bindName = group.name()
+ else:
+ if status == _BIND_STATUS_ACCEPTED:
+ shareeView = yield shareeHome.anyObjectWithShareUID(bindName)
+ yield shareeView.addressbook()._initSyncToken()
+ yield shareeView._initBindRevision()
+
+ queryCacher = self._txn._queryCacher
+ if queryCacher:
+ cacheKey = queryCacher.keyForObjectWithName(shareeHome._resourceID, self.addressbook().name())
+ queryCacher.invalidateAfterCommit(self._txn, cacheKey)
+
+ yield self.setShared(True)
+
+ # Must send notification to ensure cache invalidation occurs
+ yield self.notifyChanged()
+
+ returnValue(bindName)
+
+
+ @inlineCallbacks
+ def createShare(self, shareeUID, mode, summary=None):
+ """
+ Create a new shared resource. If the mode is direct, the share is created in accepted state,
+ otherwise the share is created in invited state.
+ """
+
+ if self._kind == _ABO_KIND_GROUP:
+ shareeView = yield super(AddressBookObjectSharingMixIn, self).createShare(shareeUID, mode, summary)
+ returnValue(shareeView)
+ else:
+ returnValue(None)
+
+
+ @inlineCallbacks
+ def unshare(self):
+ """
+ Unshares a group, regardless of which "direction" it was shared.
+ """
+ if self._kind == _ABO_KIND_GROUP:
+ yield super(AddressBookObjectSharingMixIn, self).unshare()
+
+
+ @inlineCallbacks
+ def updateShare(self, shareeView, mode=None, status=None, summary=None):
+ """
</ins><span class="cx"> Update share mode, status, and message for a home child shared with
</span><span class="cx"> this (owned) L{CommonHomeChild}.
</span><span class="cx">
</span><span class="lines">@@ -1122,9 +1248,9 @@
</span><span class="cx"> L{_BIND_STATUS_INVALID} or None to not update
</span><span class="cx"> @type status: L{str}
</span><span class="cx">
</span><del>- @param message: The proposed message to go along with the share, which
</del><ins>+ @param summary: The proposed message to go along with the share, which
</ins><span class="cx"> will be used as the default display name, or None to not update
</span><del>- @type message: L{str}
</del><ins>+ @type summary: L{str}
</ins><span class="cx">
</span><span class="cx"> @return: the name of the shared item in the sharee's home.
</span><span class="cx"> @rtype: a L{Deferred} which fires with a L{str}
</span><span class="lines">@@ -1134,23 +1260,27 @@
</span><span class="cx">
</span><span class="cx"> # remove None parameters, and substitute None for empty string
</span><span class="cx"> bind = self._bindSchema
</span><del>- columnMap = dict([(k, v if v != "" else None)
- for k, v in {bind.BIND_MODE:mode,
- bind.BIND_STATUS:status,
- bind.MESSAGE:message}.iteritems() if v is not None])
</del><ins>+ columnMap = dict([(k, v if v != "" else None) for k, v in {
+ bind.BIND_MODE:mode,
+ bind.BIND_STATUS:status,
+ bind.MESSAGE:summary
+ }.iteritems() if v is not None])
</ins><span class="cx">
</span><span class="cx"> if len(columnMap):
</span><span class="cx">
</span><span class="cx"> # count accepted
</span><span class="cx"> if status is not None:
</span><del>- previouslyAcceptedBindCount = 1 if shareeView.fullyShared() else 0
- previouslyAcceptedBindCount += len((yield AddressBookObject._acceptedBindForHomeIDAndAddressBookID.on(
- self._txn, homeID=shareeView.viewerHome()._resourceID, addressbookID=shareeView._resourceID
- )))
</del><ins>+ previouslyAcceptedBindCount = 1 if self.addressbook().fullyShared() else 0
+ previouslyAcceptedBindCount += len((
+ yield AddressBookObject._acceptedBindForHomeIDAndAddressBookID.on(
+ self._txn, homeID=shareeView.viewerHome()._resourceID, addressbookID=self.addressbook()._resourceID
+ )
+ ))
</ins><span class="cx">
</span><del>- bindNameRows = yield self._updateBindColumnsQuery(columnMap).on(
</del><ins>+ yield self._updateBindColumnsQuery(columnMap).on(
</ins><span class="cx"> self._txn,
</span><del>- resourceID=self._resourceID, homeID=shareeView.viewerHome()._resourceID
</del><ins>+ resourceID=self._resourceID,
+ homeID=shareeView.addressbook().viewerHome()._resourceID
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx"> # update affected attributes
</span><span class="lines">@@ -1161,51 +1291,26 @@
</span><span class="cx"> shareeView._bindStatus = columnMap[bind.BIND_STATUS]
</span><span class="cx"> if shareeView._bindStatus == _BIND_STATUS_ACCEPTED:
</span><span class="cx"> if 0 == previouslyAcceptedBindCount:
</span><del>- yield shareeView._initSyncToken()
</del><ins>+ yield shareeView.addressbook()._initSyncToken()
</ins><span class="cx"> yield shareeView._initBindRevision()
</span><del>- shareeView.viewerHome()._children[self.shareeName()] = shareeView
- shareeView.viewerHome()._children[shareeView._resourceID] = shareeView
- elif shareeView._bindStatus == _BIND_STATUS_DECLINED:
</del><ins>+ shareeView.viewerHome()._children[shareeView.addressbook().name()] = shareeView.addressbook()
+ shareeView.viewerHome()._children[shareeView.addressbook().id()] = shareeView.addressbook()
+ elif shareeView._bindStatus != _BIND_STATUS_INVITED:
</ins><span class="cx"> if 1 == previouslyAcceptedBindCount:
</span><del>- yield shareeView._deletedSyncToken(sharedRemoval=True)
- shareeView.viewerHome()._children.pop(self.shareeName(), None)
- shareeView.viewerHome()._children.pop(shareeView._resourceID, None)
</del><ins>+ yield shareeView.addressbook()._deletedSyncToken(sharedRemoval=True)
+ shareeView.viewerHome()._children.pop(shareeView.addressbook().name(), None)
+ shareeView.viewerHome()._children.pop(shareeView.addressbook().id(), None)
</ins><span class="cx">
</span><del>- if message is not None:
</del><ins>+ if summary is not None:
</ins><span class="cx"> shareeView._bindMessage = columnMap[bind.MESSAGE]
</span><span class="cx">
</span><del>- queryCacher = self._txn._queryCacher
- if queryCacher:
- cacheKey = queryCacher.keyForObjectWithName(shareeView.viewerHome()._resourceID, self.shareeName())
- queryCacher.invalidateAfterCommit(self._txn, cacheKey)
-
- shareeView._name = bindNameRows[0][0]
-
</del><span class="cx"> # Must send notification to ensure cache invalidation occurs
</span><del>- yield self.notifyPropertyChanged()
</del><ins>+ yield self.notifyChanged()
</ins><span class="cx">
</span><del>- returnValue(shareeView._name)
</del><span class="cx">
</span><del>-
</del><span class="cx"> @inlineCallbacks
</span><del>- def shareWith(self, shareeHome, mode, status=None, message=None):
</del><ins>+ def removeShare(self, shareeView):
</ins><span class="cx"> """
</span><del>- call super and set isShared = True
- """
- bindName = yield super(AddressBook, self).shareWith(shareeHome, mode, status, message)
-
- queryCacher = self._txn._queryCacher
- if queryCacher:
- cacheKey = queryCacher.keyForObjectWithName(shareeHome._resourceID, self.shareeName())
- queryCacher.invalidateAfterCommit(self._txn, cacheKey)
-
- self.setShared(True)
- returnValue(bindName)
-
-
- @inlineCallbacks
- def unshareWith(self, shareeHome):
- """
</del><span class="cx"> Remove the shared version of this (owned) L{CommonHomeChild} from the
</span><span class="cx"> referenced L{CommonHome}.
</span><span class="cx">
</span><span class="lines">@@ -1214,46 +1319,104 @@
</span><span class="cx"> @param shareeHome: The home with which this L{CommonHomeChild} was
</span><span class="cx"> previously shared.
</span><span class="cx">
</span><del>- @return: a L{Deferred} which will fire with the previous shareUID
</del><ins>+ @return: a L{Deferred} which will fire with the previously-used name.
</ins><span class="cx"> """
</span><del>- sharedAddressBook = yield shareeHome.addressbookWithName(self.shareeName())
</del><ins>+
+ shareeHome = shareeView.addressbook().viewerHome()
+ sharedAddressBook = yield shareeHome.addressbookWithName(self.addressbook().name())
+
</ins><span class="cx"> if sharedAddressBook:
</span><span class="cx">
</span><span class="cx"> acceptedBindCount = 1 if sharedAddressBook.fullyShared() else 0
</span><del>- acceptedBindCount += len((yield AddressBookObject._acceptedBindForHomeIDAndAddressBookID.on(
</del><ins>+ acceptedBindCount += len((
+ yield AddressBookObject._acceptedBindForHomeIDAndAddressBookID.on(
</ins><span class="cx"> self._txn, homeID=shareeHome._resourceID, addressbookID=sharedAddressBook._resourceID
</span><del>- )))
</del><ins>+ )
+ ))
+
</ins><span class="cx"> if acceptedBindCount == 1:
</span><span class="cx"> yield sharedAddressBook._deletedSyncToken(sharedRemoval=True)
</span><del>- shareeHome._children.pop(self.shareeName(), None)
- shareeHome._children.pop(sharedAddressBook._resourceID, None)
- elif not sharedAddressBook.fullyShared():
- # FIXME: remove objects for this group only using self.removeObjectResource
- self._objectNames = None
</del><ins>+ shareeHome._children.pop(shareeView.addressbook().name(), None)
+ shareeHome._children.pop(shareeView.addressbook().id(), None)
</ins><span class="cx">
</span><span class="cx"> # Must send notification to ensure cache invalidation occurs
</span><del>- yield self.notifyPropertyChanged()
</del><ins>+ yield self.notifyChanged()
</ins><span class="cx">
</span><ins>+ # Must send notification to ensure cache invalidation occurs
+ yield self.notifyChanged()
+
</ins><span class="cx"> # delete binds including invites
</span><del>- deletedBindNameRows = yield self._deleteBindForResourceIDAndHomeID.on(self._txn, resourceID=self._resourceID,
- homeID=shareeHome._resourceID
</del><ins>+ yield self._deleteBindForResourceIDAndHomeID.on(
+ self._txn,
+ resourceID=self._resourceID,
+ homeID=shareeHome._resourceID,
</ins><span class="cx"> )
</span><del>- if deletedBindNameRows:
- deletedBindName = deletedBindNameRows[0][0]
- queryCacher = self._txn._queryCacher
- if queryCacher:
- cacheKey = queryCacher.keyForObjectWithName(shareeHome._resourceID, self.shareeName())
- queryCacher.invalidateAfterCommit(self._txn, cacheKey)
- else:
- deletedBindName = None
</del><span class="cx">
</span><del>- self._initIsShared()
- returnValue(deletedBindName)
</del><ins>+ queryCacher = self._txn._queryCacher
+ if queryCacher:
+ cacheKey = queryCacher.keyForObjectWithName(shareeHome._resourceID, self.addressbook().name())
+ queryCacher.invalidateAfterCommit(self._txn, cacheKey)
</ins><span class="cx">
</span><span class="cx">
</span><ins>+ @inlineCallbacks
+ def sharingInvites(self):
+ """
+ Retrieve the list of all L{SharingInvitation} for this L{CommonHomeChild}, irrespective of mode.
</ins><span class="cx">
</span><del>-class AddressBookObject(CommonObjectResource, AddressBookSharingMixIn):
</del><ins>+ @return: L{SharingInvitation} objects
+ @rtype: a L{Deferred} which fires with a L{list} of L{SharingInvitation}s.
+ """
+ if not self.owned() or self._kind != _ABO_KIND_GROUP:
+ returnValue([])
</ins><span class="cx">
</span><ins>+ # Get all binds
+ acceptedRows = yield self._sharedInvitationBindForResourceID.on(
+ self._txn, resourceID=self._resourceID, homeID=self.addressbook()._home._resourceID
+ )
+
+ result = []
+ for homeUID, homeRID, resourceID, resourceName, bindMode, bindStatus, bindMessage in acceptedRows: #@UnusedVariable
+ invite = SharingInvitation(
+ resourceName,
+ self.addressbook()._home.name(),
+ self.addressbook()._home.id(),
+ homeUID,
+ homeRID,
+ bindMode,
+ bindStatus,
+ bindMessage,
+ )
+ result.append(invite)
+ returnValue(result)
+
+
+ @inlineCallbacks
+ def _initBindRevision(self):
+ # FIXME: not sure about all this revision stuff
+ yield self.addressbook()._initBindRevision()
+
+ bind = self._bindSchema
+ yield self._updateBindColumnsQuery(
+ {bind.BIND_REVISION : Parameter("revision"), }
+ ).on(
+ self._txn,
+ revision=self.addressbook()._bindRevision,
+ resourceID=self._resourceID,
+ homeID=self.viewerHome()._resourceID,
+ )
+ yield self.invalidateQueryCache()
+
+
+ def shareUID(self):
+ """
+ @see: L{ICalendar.shareUID}
+ """
+ return self._bindName if self._bindName else self._name
+
+
+
+class AddressBookObject(CommonObjectResource, AddressBookObjectSharingMixIn):
+
</ins><span class="cx"> implements(IAddressBookObject)
</span><span class="cx">
</span><span class="cx"> _homeSchema = schema.ADDRESSBOOK_HOME
</span><span class="lines">@@ -1318,7 +1481,7 @@
</span><span class="cx"> yield self.unshare() # storebridge should already have done this
</span><span class="cx"> else:
</span><span class="cx"> # handled in storebridge as unshare, should not be here. assert instead?
</span><del>- if self.isGroupForSharedAddressBook() or self.shareUID():
</del><ins>+ if self.isGroupForSharedAddressBook() or self._bindMode is not None:
</ins><span class="cx"> raise HTTPError(FORBIDDEN)
</span><span class="cx">
</span><span class="cx"> if not self.owned() and not self.addressbook().fullyShared():
</span><span class="lines">@@ -1365,17 +1528,16 @@
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def readWriteAccess(self):
</span><span class="cx"> assert not self.owned(), "Don't call items in owned address book"
</span><del>- yield None
</del><span class="cx">
</span><del>- #shared address book group is always read-only
</del><ins>+ # Shared address book group always read-only
</ins><span class="cx"> if self.isGroupForSharedAddressBook():
</span><span class="cx"> returnValue(False)
</span><span class="cx">
</span><del>- # if fully shared and rw, must be RW since sharing group read-only has no affect
</del><ins>+ # If fully shared and rw, must be RW since sharing group read-only has no affect
</ins><span class="cx"> if self.addressbook().fullyShared() and self.addressbook().shareMode() == _BIND_MODE_WRITE:
</span><span class="cx"> returnValue(True)
</span><span class="cx">
</span><del>- #otherwise, must be in a read-write group
</del><ins>+ # Otherwise, must be in a read-write group
</ins><span class="cx"> readWriteGroupIDs = yield self.addressbook().readWriteGroupIDs()
</span><span class="cx"> readWriteIDs = yield self.addressbook().expandGroupIDs(self._txn, readWriteGroupIDs)
</span><span class="cx"> returnValue(self._resourceID in readWriteIDs)
</span><span class="lines">@@ -1413,7 +1575,39 @@
</span><span class="cx"> Where=obj.RESOURCE_ID == Parameter("resourceID"),)
</span><span class="cx">
</span><span class="cx">
</span><ins>+ @classmethod
</ins><span class="cx"> @inlineCallbacks
</span><ins>+ def objectWithBindName(cls, home, name, accepted):
+ """
+ Retrieve the objectResource with the given bind name C{name} contained in the given
+ C{home}.
+
+ @param home: a L{CommonHome}.
+
+ @param name: a string; the name of the L{CommonHomeChild} to retrieve.
+
+ @return: an L{ObjectResource} or C{None} if no such resource exists.
+ """
+
+ groupBindRows = yield cls._bindForNameAndHomeID.on(
+ home._txn, name=name, homeID=home._resourceID
+ )
+ if groupBindRows:
+ groupBindRow = groupBindRows[0]
+ bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
+
+ if accepted is not None and (bindStatus == _BIND_STATUS_ACCEPTED) != bool(accepted):
+ returnValue(None)
+
+ ownerAddressBookID = yield cls.ownerAddressBookIDFromGroupID(home._txn, resourceID)
+ ownerHome = yield home.ownerHomeWithChildID(ownerAddressBookID)
+ addressbook = yield home.anyObjectWithShareUID(ownerHome.uid())
+ returnValue((yield addressbook.objectResourceWithID(resourceID)))
+
+ returnValue(None)
+
+
+ @inlineCallbacks
</ins><span class="cx"> def initFromStore(self):
</span><span class="cx"> """
</span><span class="cx"> Initialise this object from the store. We read in and cache all the
</span><span class="lines">@@ -1423,25 +1617,13 @@
</span><span class="cx">
</span><span class="cx"> @return: L{self} if object exists in the DB, else C{None}
</span><span class="cx"> """
</span><del>- rows = None
</del><ins>+ abo = None
</ins><span class="cx"> if self.owned() or self.addressbook().fullyShared(): # owned or fully shared
</span><del>- if self._name:
- rows = yield self._allColumnsWithParentAndName.on(
- self._txn, name=self._name,
- parentID=self._parentCollection._resourceID
- )
- elif self._uid:
- rows = yield self._allColumnsWithParentAndUID.on(
- self._txn, uid=self._uid,
- parentID=self._parentCollection._resourceID
- )
- elif self._resourceID:
- rows = yield self._allColumnsWithParentAndID.on(
- self._txn, resourceID=self._resourceID,
- parentID=self._parentCollection._resourceID
- )
</del><ins>+ abo = yield super(AddressBookObject, self).initFromStore()
</ins><span class="cx">
</span><del>- if not rows and self.addressbook().fullyShared(): # perhaps add special group
</del><ins>+ # Might be special group
+ if abo is None and self.addressbook().fullyShared():
+ rows = None
</ins><span class="cx"> if self._name:
</span><span class="cx"> if self._name == self.addressbook()._groupForSharedAddressBookName():
</span><span class="cx"> rows = [self.addressbook()._groupForSharedAddressBookRow()]
</span><span class="lines">@@ -1451,9 +1633,16 @@
</span><span class="cx"> elif self._resourceID:
</span><span class="cx"> if self.isGroupForSharedAddressBook():
</span><span class="cx"> rows = [self.addressbook()._groupForSharedAddressBookRow()]
</span><ins>+
+ if rows:
+ self._initFromRow(tuple(rows[0]))
+ yield self._loadPropertyStore()
+ abo = self
+
</ins><span class="cx"> else:
</span><span class="cx"> acceptedGroupIDs = yield self.addressbook().acceptedGroupIDs()
</span><span class="cx"> allowedObjectIDs = yield self.addressbook().expandGroupIDs(self._txn, acceptedGroupIDs)
</span><ins>+ rows = None
</ins><span class="cx"> if self._name:
</span><span class="cx"> if allowedObjectIDs:
</span><span class="cx"> rows = (yield self._allColumnsWithResourceIDsAndName(allowedObjectIDs).on(
</span><span class="lines">@@ -1474,10 +1663,12 @@
</span><span class="cx"> rows = (yield self._allColumnsWithResourceID.on(
</span><span class="cx"> self._txn, resourceID=self._resourceID,
</span><span class="cx"> ))
</span><ins>+ if rows:
+ self._initFromRow(tuple(rows[0]))
+ yield self._loadPropertyStore()
+ abo = self
</ins><span class="cx">
</span><del>- if rows:
- self._initFromRow(tuple(rows[0]))
-
</del><ins>+ if abo is not None:
</ins><span class="cx"> if self._kind == _ABO_KIND_GROUP:
</span><span class="cx">
</span><span class="cx"> groupBindRows = yield AddressBookObject._bindForResourceIDAndHomeID.on(
</span><span class="lines">@@ -1491,11 +1682,11 @@
</span><span class="cx"> self._bindStatus = bindStatus
</span><span class="cx"> self._bindMessage = bindMessage
</span><span class="cx"> self._bindName = bindName
</span><ins>+ else:
+ invites = yield self.sharingInvites()
+ if len(invites):
+ self._bindMessage = "shared"
</ins><span class="cx">
</span><del>- yield self._initIsShared()
-
- yield self._loadPropertyStore()
-
</del><span class="cx"> returnValue(self)
</span><span class="cx"> else:
</span><span class="cx"> returnValue(None)
</span><span class="lines">@@ -1618,7 +1809,7 @@
</span><span class="cx">
</span><span class="cx"> def validAddressDataCheck(self, component, inserting): #@UnusedVariable
</span><span class="cx"> """
</span><del>- Check that the calendar data is valid iCalendar.
</del><ins>+ Check that the calendar data is valid IAddressBook.
</ins><span class="cx"> @return: tuple: (True/False if the calendar data is valid,
</span><span class="cx"> log message string).
</span><span class="cx"> """
</span><span class="lines">@@ -1702,7 +1893,7 @@
</span><span class="cx"> if self._kind == _ABO_KIND_GROUP: # optimization
</span><span class="cx"> invites = yield self.sharingInvites()
</span><span class="cx"> for invite in invites:
</span><del>- shareeHome = (yield self._txn.homeWithResourceID(self.addressbook()._home._homeType, invite.shareeHomeID()))
</del><ins>+ shareeHome = (yield self._txn.homeWithResourceID(self.addressbook()._home._homeType, invite.shareeHomeID))
</ins><span class="cx"> yield self._changeAddressBookRevision(shareeHome.addressbook(), inserting)
</span><span class="cx"> # one is enough because all have the same resourceID
</span><span class="cx"> break
</span><span class="lines">@@ -2047,25 +2238,6 @@
</span><span class="cx"> return MimeType.fromString("text/vcard; charset=utf-8")
</span><span class="cx">
</span><span class="cx">
</span><del>- def owned(self):
- return self.addressbook().owned()
-
-
- def ownerHome(self):
- return self.addressbook().ownerHome()
-
-
- def viewerHome(self):
- return self.addressbook().viewerHome()
-
-
- def shareUID(self):
- """
- @see: L{ICalendar.shareUID}
- """
- return self._bindName
-
-
</del><span class="cx"> @classmethod
</span><span class="cx"> def metadataColumns(cls):
</span><span class="cx"> """
</span><span class="lines">@@ -2098,6 +2270,13 @@
</span><span class="cx"> return self.addressbook().notifyChanged()
</span><span class="cx">
</span><span class="cx">
</span><ins>+ def notifyPropertyChanged(self):
+ """
+ Send notifications when properties on this object change.
+ """
+ return self.addressbook().notifyPropertyChanged()
+
+
</ins><span class="cx"> @classproperty
</span><span class="cx"> def _addressbookIDForResourceID(cls): #@NoSelf
</span><span class="cx"> obj = cls._objectSchema
</span><span class="lines">@@ -2114,281 +2293,6 @@
</span><span class="cx"> returnValue(ownerAddressBookIDRows[0][0])
</span><span class="cx">
</span><span class="cx">
</span><del>- @inlineCallbacks
- def sharingInvites(self):
- """
- Retrieve the list of all L{SharingInvitation} for this L{CommonHomeChild}, irrespective of mode.
-
- @return: L{SharingInvitation} objects
- @rtype: a L{Deferred} which fires with a L{list} of L{SharingInvitation}s.
- """
- if not self.owned():
- returnValue([])
-
- # get all accepted binds
- acceptedRows = yield self._sharedInvitationBindForResourceID.on(
- self._txn, resourceID=self._resourceID, homeID=self.addressbook()._home._resourceID
- )
-
- result = []
- for homeUID, homeRID, resourceID, resourceName, bindMode, bindStatus, bindMessage in acceptedRows: #@UnusedVariable
- invite = SharingInvitation(
- resourceName,
- self.addressbook()._home.name(),
- self.addressbook()._home._resourceID,
- homeUID,
- homeRID,
- resourceID,
- self.addressbook().shareeName(),
- bindMode,
- bindStatus,
- bindMessage,
- )
- result.append(invite)
- returnValue(result)
-
-
- @inlineCallbacks
- def unshare(self):
- """
- Unshares a group, regardless of which "direction" it was shared.
- """
- if self._kind == _ABO_KIND_GROUP:
- if self.owned():
- # This collection may be shared to others
- invites = yield self.sharingInvites()
- for invite in invites:
- shareeHome = (yield self._txn.homeWithResourceID(self.addressbook()._home._homeType, invite.shareeHomeID()))
- (yield self.unshareWith(shareeHome))
- else:
- # This collection is shared to me
- ownerAddressBook = self.addressbook().ownerHome().addressbook()
- ownerGroup = yield ownerAddressBook.objectResourceWithID(self._resourceID)
- if ownerGroup:
- yield ownerGroup.unshareWith(self._home)
-
-
- @inlineCallbacks
- def unshareWith(self, shareeHome):
- """
- Remove the shared version of this (owned) L{CommonHomeChild} from the
- referenced L{CommonHome}.
-
- @see: L{CommonHomeChild.shareWith}
-
- @param shareeHome: The home with which this L{CommonHomeChild} was
- previously shared.
-
- @return: a L{Deferred} which will fire with the previously-used name.
- """
- sharedAddressBook = yield shareeHome.addressbookWithName(self.addressbook().shareeName())
-
- if sharedAddressBook:
-
- acceptedBindCount = 1 if sharedAddressBook.fullyShared() else 0
- acceptedBindCount += len((
- yield AddressBookObject._acceptedBindForHomeIDAndAddressBookID.on(
- self._txn, homeID=shareeHome._resourceID, addressbookID=sharedAddressBook._resourceID
- )
- ))
-
- if acceptedBindCount == 1:
- yield sharedAddressBook._deletedSyncToken(sharedRemoval=True)
- shareeHome._children.pop(self.addressbook().shareeName(), None)
- shareeHome._children.pop(self.addressbook()._resourceID, None)
-
- # Must send notification to ensure cache invalidation occurs
- yield self.notifyChanged()
-
- # delete binds including invites
- deletedBindNameRows = yield self._deleteBindForResourceIDAndHomeID.on(
- self._txn, resourceID=self._resourceID,
- homeID=shareeHome._resourceID
- )
- if deletedBindNameRows:
- deletedBindName = deletedBindNameRows[0][0]
- queryCacher = self._txn._queryCacher
- if queryCacher:
- cacheKey = queryCacher.keyForObjectWithName(shareeHome._resourceID, self.addressbook().shareeName())
- queryCacher.invalidateAfterCommit(self._txn, cacheKey)
- else:
- deletedBindName = None
-
- yield self._initIsShared()
- returnValue(deletedBindName)
-
-
- @inlineCallbacks
- def shareWith(self, shareeHome, mode, status=None, message=None):
- """
- Share this (owned) L{AddressBookObject} with another home.
-
- @param shareeHome: The home of the sharee.
- @type shareeHome: L{CommonHome}
-
- @param mode: The sharing mode; L{_BIND_MODE_READ} or
- L{_BIND_MODE_WRITE} or L{_BIND_MODE_DIRECT}
- @type mode: L{str}
-
- @param status: The sharing status; L{_BIND_STATUS_INVITED} or
- L{_BIND_STATUS_ACCEPTED}
- @type mode: L{str}
-
- @param message: The proposed message to go along with the share, which
- will be used as the default display name.
- @type mode: L{str}
-
- @return: the name of the shared group in the sharee home.
- @rtype: L{str}
- """
-
- if status is None:
- status = _BIND_STATUS_ACCEPTED
-
- @inlineCallbacks
- def doInsert(subt):
- newName = str(uuid4())
- yield self._bindInsertQuery.on(
- subt, homeID=shareeHome._resourceID,
- resourceID=self._resourceID, name=newName,
- mode=mode, bindStatus=status, message=message
- )
- returnValue(newName)
- try:
- bindName = yield self._txn.subtransaction(doInsert)
- except AllRetriesFailed:
- # FIXME: catch more specific exception
- groupBindRows = yield self._bindForResourceIDAndHomeID.on(
- self._txn, resourceID=self._resourceID, homeID=shareeHome._resourceID
- )
- groupBindRow = groupBindRows[0]
- bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = groupBindRow[:self.bindColumnCount] #@UnusedVariable
- if bindStatus == _BIND_STATUS_ACCEPTED:
- group = yield shareeHome.objectWithShareUID(bindName)
- else:
- group = yield shareeHome.invitedObjectWithShareUID(bindName)
- bindName = yield self.updateShare(
- group, mode=mode, status=status,
- message=message
- )
- else:
- if status == _BIND_STATUS_ACCEPTED:
- shareeView = yield shareeHome.objectWithShareUID(bindName)
- yield shareeView.addressbook()._initSyncToken()
- yield shareeView._initBindRevision()
-
- queryCacher = self._txn._queryCacher
- if queryCacher:
- cacheKey = queryCacher.keyForObjectWithName(shareeHome._resourceID, self.addressbook().shareeName())
- queryCacher.invalidateAfterCommit(self._txn, cacheKey)
-
- # Must send notification to ensure cache invalidation occurs
- yield self.notifyChanged()
- self.setShared(True)
- returnValue(bindName)
-
-
- @inlineCallbacks
- def _initBindRevision(self):
- yield self.addressbook()._initBindRevision()
-
- bind = self._bindSchema
- yield self._updateBindColumnsQuery(
- {bind.BIND_REVISION : Parameter("revision"), }).on(
- self._txn,
- revision=self.addressbook()._bindRevision,
- resourceID=self._resourceID,
- homeID=self.viewerHome()._resourceID,
- )
- yield self.invalidateQueryCache()
-
-
- @inlineCallbacks
- def updateShare(self, shareeView, mode=None, status=None, message=None):
- """
- Update share mode, status, and message for a home child shared with
- this (owned) L{CommonHomeChild}.
-
- @param shareeView: The sharee home child that shares this.
- @type shareeView: L{CommonHomeChild}
-
- @param mode: The sharing mode; L{_BIND_MODE_READ} or
- L{_BIND_MODE_WRITE} or None to not update
- @type mode: L{str}
-
- @param status: The sharing status; L{_BIND_STATUS_INVITED} or
- L{_BIND_STATUS_ACCEPTED} or L{_BIND_STATUS_DECLINED} or
- L{_BIND_STATUS_INVALID} or None to not update
- @type status: L{str}
-
- @param message: The proposed message to go along with the share, which
- will be used as the default display name, or None to not update
- @type message: L{str}
-
- @return: the name of the shared item in the sharee's home.
- @rtype: a L{Deferred} which fires with a L{str}
- """
- # TODO: raise a nice exception if shareeView is not, in fact, a shared
- # version of this same L{CommonHomeChild}
-
- # remove None parameters, and substitute None for empty string
- bind = self._bindSchema
- columnMap = dict([(k, v if v != "" else None)
- for k, v in {bind.BIND_MODE:mode,
- bind.BIND_STATUS:status,
- bind.MESSAGE:message}.iteritems() if v is not None])
-
- if len(columnMap):
-
- # count accepted
- if status is not None:
- previouslyAcceptedBindCount = 1 if self.addressbook().fullyShared() else 0
- previouslyAcceptedBindCount += len((
- yield AddressBookObject._acceptedBindForHomeIDAndAddressBookID.on(
- self._txn, homeID=shareeView.viewerHome()._resourceID, addressbookID=self.addressbook()._resourceID
- )
- ))
-
- bindNameRows = yield self._updateBindColumnsQuery(columnMap).on(
- self._txn,
- resourceID=self._resourceID, homeID=shareeView.viewerHome()._resourceID
- )
-
- # update affected attributes
- if mode is not None:
- shareeView._bindMode = columnMap[bind.BIND_MODE]
-
- if status is not None:
- shareeView._bindStatus = columnMap[bind.BIND_STATUS]
- if shareeView._bindStatus == _BIND_STATUS_ACCEPTED:
- if 0 == previouslyAcceptedBindCount:
- yield shareeView.addressbook()._initSyncToken()
- yield shareeView._initBindRevision()
- shareeView.viewerHome()._children[self.addressbook().shareeName()] = shareeView.addressbook()
- shareeView.viewerHome()._children[shareeView._resourceID] = shareeView.addressbook()
- elif shareeView._bindStatus != _BIND_STATUS_INVITED:
- if 1 == previouslyAcceptedBindCount:
- yield shareeView.addressbook()._deletedSyncToken(sharedRemoval=True)
- shareeView.viewerHome()._children.pop(self.addressbook().shareeName(), None)
- shareeView.viewerHome()._children.pop(shareeView._resourceID, None)
-
- if message is not None:
- shareeView._bindMessage = columnMap[bind.MESSAGE]
-
- # safer to just invalidate in all cases rather than calculate when to invalidate
- queryCacher = self._txn._queryCacher
- if queryCacher:
- cacheKey = queryCacher.keyForObjectWithName(shareeView.viewerHome()._resourceID, self.addressbook().shareeName())
- queryCacher.invalidateAfterCommit(self._txn, cacheKey)
-
- shareeView._name = bindNameRows[0][0]
-
- # Must send notification to ensure cache invalidation occurs
- yield self.notifyChanged()
-
- returnValue(shareeView._name)
-
-
</del><span class="cx"> @classproperty
</span><span class="cx"> def _acceptedBindForHomeIDAndAddressBookID(cls): #@NoSelf
</span><span class="cx"> bind = cls._bindSchema
</span></span></pre></div>
<a id="CalendarServertrunktxdavcarddavdatastoretesttest_sqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/carddav/datastore/test/test_sql.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/carddav/datastore/test/test_sql.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/txdav/carddav/datastore/test/test_sql.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -22,7 +22,7 @@
</span><span class="cx"> from twext.enterprise.dal.syntax import Select, Parameter
</span><span class="cx">
</span><span class="cx"> from twisted.internet import reactor
</span><del>-from twisted.internet.defer import inlineCallbacks, returnValue, DeferredList
</del><ins>+from twisted.internet.defer import inlineCallbacks, returnValue
</ins><span class="cx"> from twisted.internet.task import deferLater
</span><span class="cx">
</span><span class="cx"> from twisted.trial import unittest
</span><span class="lines">@@ -40,9 +40,7 @@
</span><span class="cx">
</span><span class="cx"> from txdav.common.icommondatastore import NoSuchObjectResourceError
</span><span class="cx"> from txdav.common.datastore.sql import EADDRESSBOOKTYPE, CommonObjectResource
</span><del>-from txdav.common.datastore.sql_tables import _ABO_KIND_PERSON, _ABO_KIND_GROUP, \
- schema, _BIND_MODE_DIRECT, _BIND_STATUS_ACCEPTED, _BIND_MODE_WRITE, \
- _BIND_STATUS_INVITED
</del><ins>+from txdav.common.datastore.sql_tables import _ABO_KIND_PERSON, _ABO_KIND_GROUP, schema
</ins><span class="cx"> from txdav.common.datastore.test.util import buildStore
</span><span class="cx">
</span><span class="cx"> from txdav.xml.rfc2518 import GETContentLanguage, ResourceType
</span><span class="lines">@@ -741,13 +739,13 @@
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def _defer1():
</span><del>- yield ab1.shareWith(shareeHome=sharerHome1, mode=_BIND_MODE_DIRECT, status=_BIND_STATUS_ACCEPTED, message="Shared Wiki AddressBook")
</del><ins>+ yield ab1.directShareWithUser("uid2")
</ins><span class="cx"> yield txn1.commit()
</span><span class="cx"> d1 = _defer1()
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def _defer2():
</span><del>- yield ab2.shareWith(shareeHome=sharerHome2, mode=_BIND_MODE_DIRECT, status=_BIND_STATUS_ACCEPTED, message="Shared Wiki AddressBook")
</del><ins>+ yield ab2.directShareWithUser("uid1")
</ins><span class="cx"> yield txn2.commit()
</span><span class="cx"> d2 = _defer2()
</span><span class="cx">
</span><span class="lines">@@ -865,250 +863,3 @@
</span><span class="cx"> obj = (yield self.addressbookObjectUnderTest())
</span><span class="cx"> addressbookObject = (yield home.objectResourceWithID(obj._resourceID))
</span><span class="cx"> self.assertNotEquals(addressbookObject, None)
</span><del>-
-
- @inlineCallbacks
- def test_shareWithRevision(self):
- """
- Verify that bindRevision on addressbooks and shared addressbooks has the correct value.
- """
- ab = yield self.addressbookUnderTest()
- self.assertEqual(ab._bindRevision, 0)
- other = yield self.homeUnderTest(name="home2")
- newABShareUID = yield ab.shareWith(other, _BIND_MODE_WRITE)
- yield self.commit()
-
- normalAB = yield self.addressbookUnderTest()
- self.assertEqual(normalAB._bindRevision, 0)
- otherHome = yield self.homeUnderTest(name="home2")
- otherAB = yield otherHome.objectWithShareUID(newABShareUID)
- self.assertNotEqual(otherAB._bindRevision, 0)
-
-
- @inlineCallbacks
- def test_shareGroupWithRevision(self):
- """
- Verify that bindRevision on addressbooks and shared groups has the correct value.
- """
- ab = yield self.addressbookUnderTest(home="home3")
- self.assertEqual(ab._bindRevision, 0)
- group = yield ab.objectResourceWithName("4.vcf")
- other = yield self.homeUnderTest(name="home2")
- newGroupShareUID = yield group.shareWith(other, _BIND_MODE_WRITE)
- yield self.commit()
-
- normalAB = yield self.addressbookUnderTest(home="home3")
- self.assertEqual(normalAB._bindRevision, 0)
- otherHome = yield self.homeUnderTest(name="home2")
- otherGroup = yield otherHome.objectWithShareUID(newGroupShareUID)
- otherAB = otherGroup.addressbook()
- self.assertNotEqual(otherAB._bindRevision, 0)
-
-
- @inlineCallbacks
- def test_updateShareRevision(self):
- """
- Verify that bindRevision on addressbooks and shared addressbooks has the correct value.
- """
- ab = yield self.addressbookUnderTest()
- self.assertEqual(ab._bindRevision, 0)
- other = yield self.homeUnderTest(name="home2")
- newABShareUID = yield ab.shareWith(other, _BIND_MODE_WRITE, status=_BIND_STATUS_INVITED)
- yield self.commit()
-
- normalAB = yield self.addressbookUnderTest()
- self.assertEqual(normalAB._bindRevision, 0)
- otherHome = yield self.homeUnderTest(name="home2")
- otherAB = yield otherHome.invitedObjectWithShareUID(newABShareUID)
- self.assertEqual(otherAB._bindRevision, 0)
- yield self.commit()
-
- normalAB = yield self.addressbookUnderTest()
- otherHome = yield self.homeUnderTest(name="home2")
- otherAB = yield otherHome.invitedObjectWithShareUID(newABShareUID)
- yield normalAB.updateShare(otherAB, status=_BIND_STATUS_ACCEPTED)
- yield self.commit()
-
- normalAB = yield self.addressbookUnderTest()
- self.assertEqual(normalAB._bindRevision, 0)
- otherHome = yield self.homeUnderTest(name="home2")
- otherAB = yield otherHome.objectWithShareUID(newABShareUID)
- self.assertNotEqual(otherAB._bindRevision, 0)
-
-
- @inlineCallbacks
- def test_updateSharedGroupRevision(self):
- """
- Verify that bindRevision on addressbooks and shared addressbooks has the correct value.
- """
- ab = yield self.addressbookUnderTest(home="home3")
- self.assertEqual(ab._bindRevision, 0)
- group = yield ab.objectResourceWithName("4.vcf")
- other = yield self.homeUnderTest(name="home2")
- newGroupShareUID = yield group.shareWith(other, _BIND_MODE_WRITE, status=_BIND_STATUS_INVITED)
- yield self.commit()
-
- normalAB = yield self.addressbookUnderTest(home="home3")
- self.assertEqual(normalAB._bindRevision, 0)
- otherHome = yield self.homeUnderTest(name="home2")
- otherGroup = yield otherHome.invitedObjectWithShareUID(newGroupShareUID)
- otherAB = otherGroup.addressbook()
- self.assertEqual(otherAB._bindRevision, 0)
- yield self.commit()
-
- normalAB = yield self.addressbookUnderTest(home="home3")
- normalGroup = yield normalAB.objectResourceWithName("4.vcf")
- otherHome = yield self.homeUnderTest(name="home2")
- otherGroup = yield otherHome.invitedObjectWithShareUID(newGroupShareUID)
- yield normalGroup.updateShare(otherGroup, status=_BIND_STATUS_ACCEPTED)
- yield self.commit()
-
- normalAB = yield self.addressbookUnderTest(home="home3")
- self.assertEqual(normalAB._bindRevision, 0)
- otherHome = yield self.homeUnderTest(name="home2")
- otherGroup = yield otherHome.objectWithShareUID(newGroupShareUID)
- otherAB = otherGroup.addressbook()
- self.assertNotEqual(otherAB._bindRevision, 0)
-
-
- @inlineCallbacks
- def test_sharedRevisions(self):
- """
- Verify that resourceNamesSinceRevision returns all resources after initial bind and sync.
- """
- ab = yield self.addressbookUnderTest()
- self.assertEqual(ab._bindRevision, 0)
- other = yield self.homeUnderTest(name="home2")
- newABShareUID = yield ab.shareWith(other, _BIND_MODE_WRITE)
- yield self.commit()
-
- normalAB = yield self.addressbookUnderTest()
- self.assertEqual(normalAB._bindRevision, 0)
- otherHome = yield self.homeUnderTest(name="home2")
- otherAB = yield otherHome.objectWithShareUID(newABShareUID)
- self.assertNotEqual(otherAB._bindRevision, 0)
-
- changed, deleted = yield otherAB.resourceNamesSinceRevision(otherAB._bindRevision - 1)
- self.assertNotEqual(len(changed), 0)
- self.assertEqual(len(deleted), 0)
-
- changed, deleted = yield otherAB.resourceNamesSinceRevision(otherAB._bindRevision)
- self.assertEqual(len(changed), 0)
- self.assertEqual(len(deleted), 0)
-
- for depth in ("1", "infinity",):
- changed, deleted = yield otherHome.resourceNamesSinceRevision(otherAB._bindRevision - 1, depth)
- self.assertNotEqual(len(changed), 0)
- self.assertEqual(len(deleted), 0)
-
- changed, deleted = yield otherHome.resourceNamesSinceRevision(otherAB._bindRevision, depth)
- self.assertEqual(len(changed), 0)
- self.assertEqual(len(deleted), 0)
-
-
- @inlineCallbacks
- def test_sharedGroupRevisions(self):
- """
- Verify that resourceNamesSinceRevision returns all resources after initial bind and sync.
- """
- ab = yield self.addressbookUnderTest(home="home3")
- self.assertEqual(ab._bindRevision, 0)
- group = yield ab.objectResourceWithName("4.vcf")
- other = yield self.homeUnderTest(name="home2")
- newGroupShareUID = yield group.shareWith(other, _BIND_MODE_WRITE)
- yield self.commit()
-
- normalAB = yield self.addressbookUnderTest(home="home3")
- self.assertEqual(normalAB._bindRevision, 0)
- otherHome = yield self.homeUnderTest(name="home2")
- otherGroup = yield otherHome.objectWithShareUID(newGroupShareUID)
- otherAB = otherGroup.addressbook()
- self.assertNotEqual(otherAB._bindRevision, 0)
-
- changed, deleted = yield otherAB.resourceNamesSinceRevision(otherAB._bindRevision - 1)
- self.assertNotEqual(len(changed), 0)
- self.assertEqual(len(deleted), 0)
-
- changed, deleted = yield otherAB.resourceNamesSinceRevision(otherAB._bindRevision)
- self.assertEqual(len(changed), 0)
- self.assertEqual(len(deleted), 0)
-
- for depth in ("1", "infinity",):
- changed, deleted = yield otherHome.resourceNamesSinceRevision(otherAB._bindRevision - 1, depth)
- self.assertNotEqual(len(changed), 0)
- self.assertEqual(len(deleted), 0)
-
- changed, deleted = yield otherHome.resourceNamesSinceRevision(otherAB._bindRevision, depth)
- self.assertEqual(len(changed), 0)
- self.assertEqual(len(deleted), 0)
-
-
- @inlineCallbacks
- def test_addressbookRevisionChangeConcurrency(self):
- """
- Test that two concurrent attempts to add resources in two separate
- calendar homes does not deadlock on the revision table update.
- """
-
- # Make sure homes are provisioned
- txn = self.transactionUnderTest()
- home_uid1 = yield txn.homeWithUID(EADDRESSBOOKTYPE, "user01", create=True)
- home_uid2 = yield txn.homeWithUID(EADDRESSBOOKTYPE, "user02", create=True)
- self.assertNotEqual(home_uid1, None)
- self.assertNotEqual(home_uid2, None)
- yield self.commit()
-
- # Create first events in different calendar homes
- txn1 = self._sqlStore.newTransaction()
- txn2 = self._sqlStore.newTransaction()
-
- addressbook_uid1_in_txn1 = yield self.addressbookUnderTest(txn1, "addressbook", "user01")
- addressbook_uid2_in_txn2 = yield self.addressbookUnderTest(txn2, "addressbook", "user02")
-
- data = """BEGIN:VCARD
-VERSION:3.0
-PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-UID:data%(ctr)s
-FN:Data %(ctr)s
-N:Sub Group;;;;
-REV:20120503T194243Z
-END:VCARD
-
-"""
-
- component = VComponent.fromString(data % {"ctr": 1})
- yield addressbook_uid1_in_txn1.createAddressBookObjectWithName("data1.ics", component)
-
- component = VComponent.fromString(data % {"ctr": 2})
- yield addressbook_uid2_in_txn2.createAddressBookObjectWithName("data2.ics", component)
-
- # Setup deferreds to run concurrently and create second events in the calendar homes
- # previously used by the other transaction - this could create the deadlock.
- @inlineCallbacks
- def _defer_uid3():
- addressbook_uid1_in_txn2 = yield self.addressbookUnderTest(txn2, "addressbook", "user01")
- component = VComponent.fromString(data % {"ctr": 3})
- yield addressbook_uid1_in_txn2.createAddressBookObjectWithName("data3.ics", component)
- yield txn2.commit()
- d1 = _defer_uid3()
-
- @inlineCallbacks
- def _defer_uid4():
- addressbook_uid2_in_txn1 = yield self.addressbookUnderTest(txn1, "addressbook", "user02")
- component = VComponent.fromString(data % {"ctr": 4})
- yield addressbook_uid2_in_txn1.createAddressBookObjectWithName("data4.ics", component)
- yield txn1.commit()
- d2 = _defer_uid4()
-
- # Now do the concurrent provision attempt
- yield DeferredList([d1, d2])
-
- # Verify we did not have a deadlock and all resources have been created.
- vcarddata1 = yield self.addressbookObjectUnderTest(name="data1.ics", addressbook_name="addressbook", home="user01")
- vcarddata2 = yield self.addressbookObjectUnderTest(name="data2.ics", addressbook_name="addressbook", home="user02")
- vcarddata3 = yield self.addressbookObjectUnderTest(name="data3.ics", addressbook_name="addressbook", home="user01")
- vcarddata4 = yield self.addressbookObjectUnderTest(name="data4.ics", addressbook_name="addressbook", home="user02")
- self.assertNotEqual(vcarddata1, None)
- self.assertNotEqual(vcarddata2, None)
- self.assertNotEqual(vcarddata3, None)
- self.assertNotEqual(vcarddata4, None)
</del></span></pre></div>
<a id="CalendarServertrunktxdavcarddavdatastoretesttest_sql_sharingpyfromrev12016CalendarServerbranchesuserscdaboosharinginthestoretxdavcarddavdatastoretesttest_sql_sharingpy"></a>
<div class="copfile"><h4>Copied: CalendarServer/trunk/txdav/carddav/datastore/test/test_sql_sharing.py (from rev 12016, CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/carddav/datastore/test/test_sql_sharing.py) (0 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/carddav/datastore/test/test_sql_sharing.py         (rev 0)
+++ CalendarServer/trunk/txdav/carddav/datastore/test/test_sql_sharing.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -0,0 +1,1248 @@
</span><ins>+##
+# Copyright (c) 2005-2013 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.
+##
+
+
+from twisted.internet.defer import inlineCallbacks, returnValue, DeferredList
+from twisted.trial.unittest import TestCase
+
+from twistedcaldav.vcard import Component as VCard, Component
+from twext.python.clsprop import classproperty
+from txdav.common.datastore.test.util import CommonCommonTests, buildStore
+from txdav.common.datastore.sql_tables import _BIND_MODE_READ, \
+ _BIND_STATUS_INVITED, _BIND_MODE_DIRECT, _BIND_STATUS_ACCEPTED, \
+ _BIND_MODE_WRITE
+
+
+
+class BaseSharingTests(CommonCommonTests, TestCase):
+ """
+ Test store-based address book sharing.
+ """
+
+ @inlineCallbacks
+ def setUp(self):
+ yield super(BaseSharingTests, self).setUp()
+ self._sqlStore = yield buildStore(self, self.notifierFactory)
+ yield self.populate()
+
+
+ @inlineCallbacks
+ def populate(self):
+ populateTxn = self.storeUnderTest().newTransaction()
+ for homeUID in self.requirements:
+ addressbooks = self.requirements[homeUID]
+ if addressbooks is not None:
+ home = yield populateTxn.addressbookHomeWithUID(homeUID, True)
+ addressbook = home.addressbook()
+
+ addressbookObjNames = addressbooks[addressbook.name()]
+ if addressbookObjNames is not None:
+ for objectName in addressbookObjNames:
+ objData = addressbookObjNames[objectName]
+ yield addressbook.createAddressBookObjectWithName(
+ objectName, VCard.fromString(objData)
+ )
+
+ yield populateTxn.commit()
+ self.notifierFactory.reset()
+
+ # Data to populate
+ card1 = """BEGIN:VCARD
+VERSION:3.0
+UID:card1
+FN:Card 1
+N:card1;;;;
+END:VCARD
+"""
+
+ card2 = """BEGIN:VCARD
+VERSION:3.0
+UID:card2
+FN:Card 2
+N:card2;;;;
+END:VCARD
+"""
+
+ card3 = """BEGIN:VCARD
+VERSION:3.0
+UID:card3
+FN:Card 3
+N:card3;;;;
+END:VCARD
+"""
+
+ group1 = """BEGIN:VCARD
+VERSION:3.0
+UID:group1
+FN:Group 1
+N:group1;;;;
+X-ADDRESSBOOKSERVER-KIND:group
+X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:card1
+X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:card2
+END:VCARD
+"""
+
+ group2 = """BEGIN:VCARD
+VERSION:3.0
+UID:group2
+FN:Group 2
+N:group2;;;;
+X-ADDRESSBOOKSERVER-KIND:group
+X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:card1
+X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:card3
+X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:foreign
+END:VCARD
+"""
+
+
+ @classproperty(cache=False)
+ def requirements(cls): #@NoSelf
+ return {
+ "user01": {
+ "addressbook": {
+ "card1.vcf": cls.card1,
+ "card2.vcf": cls.card2,
+ "card3.vcf": cls.card3,
+ "group1.vcf": cls.group1,
+ "group2.vcf": cls.group2,
+ },
+ },
+ "user02": {
+ "addressbook": {
+ },
+ },
+ "user03": {
+ "addressbook": {
+ },
+ },
+ }
+
+ fully_shared_children = ["addressbook.vcf", "group1.vcf", "group2.vcf", "card1.vcf", "card2.vcf", "card3.vcf", ]
+ all_children = ["group1.vcf", "group2.vcf", "card1.vcf", "card2.vcf", "card3.vcf", ]
+ group1_children = ["group1.vcf", "card1.vcf", "card2.vcf", ]
+ group2_children = ["group2.vcf", "card1.vcf", "card3.vcf", ]
+
+
+ def storeUnderTest(self):
+ """
+ Create and return a L{CalendarStore} for testing.
+ """
+ return self._sqlStore
+
+
+ @inlineCallbacks
+ def _createShare(self, mode=_BIND_MODE_READ):
+ inviteUID = yield self._inviteShare(mode)
+ sharedName = yield self._acceptShare(inviteUID)
+ returnValue(sharedName)
+
+
+ @inlineCallbacks
+ def _inviteShare(self, mode=_BIND_MODE_READ):
+ # Invite
+ addressbook = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ invites = yield addressbook.sharingInvites()
+ self.assertEqual(len(invites), 0)
+
+ shareeView = yield addressbook.inviteUserToShare("user02", mode, "summary")
+ inviteUID = shareeView.shareUID()
+ yield self.commit()
+
+ returnValue(inviteUID)
+
+
+ @inlineCallbacks
+ def _acceptShare(self, inviteUID):
+ # Accept
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ shareeView = yield shareeHome.acceptShare(inviteUID)
+ sharedName = shareeView.name()
+ yield self.commit()
+
+ returnValue(sharedName)
+
+
+ @inlineCallbacks
+ def _createGroupShare(self, groupname="group1.vcf", mode=_BIND_MODE_READ):
+ inviteUID = yield self._inviteGroupShare(groupname, mode)
+ sharedName = yield self._acceptGroupShare(inviteUID)
+ returnValue(sharedName)
+
+
+ @inlineCallbacks
+ def _inviteGroupShare(self, groupname="group1.vcf", mode=_BIND_MODE_READ):
+ # Invite
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name=groupname)
+ shareeView = yield group.inviteUserToShare("user02", mode, "summary")
+ inviteUID = shareeView.shareUID()
+ yield self.commit()
+
+ returnValue(inviteUID)
+
+
+ @inlineCallbacks
+ def _acceptGroupShare(self, inviteUID):
+ # Accept
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.acceptShare(inviteUID)
+ yield self.commit()
+
+ returnValue(inviteUID)
+
+
+ @inlineCallbacks
+ def _check_notifications(self, home, items):
+ notifyHome = yield self.transactionUnderTest().notificationsWithUID(home)
+ notifications = yield notifyHome.listNotificationObjects()
+ self.assertEqual(set(notifications), set(items))
+
+
+ @inlineCallbacks
+ def _check_addressbook(self, home, addressbook_name, child_names):
+ sharedParent = yield self.addressbookUnderTest(home=home, name=addressbook_name)
+ self.assertTrue(sharedParent is not None, msg="Missing parent:{}".format(addressbook_name))
+
+ children = yield sharedParent.listAddressBookObjects()
+ self.assertEqual(set(children), set(child_names))
+
+ number = yield sharedParent.countAddressBookObjects()
+ self.assertEqual(number, len(child_names))
+
+ for child in child_names:
+ shared = yield self.addressbookObjectUnderTest(home=home, addressbook_name=addressbook_name, name=child)
+ self.assertTrue(shared is not None, msg="Missing child:{}".format(child))
+
+
+ @inlineCallbacks
+ def _check_read_only(self, home, addressbook_name, child_names):
+ for child in child_names:
+ shared = yield self.addressbookObjectUnderTest(home=home, addressbook_name=addressbook_name, name=child)
+ rw_mode = yield shared.readWriteAccess()
+ self.assertFalse(rw_mode)
+
+
+ @inlineCallbacks
+ def _check_read_write(self, home, addressbook_name, child_names):
+ for child in child_names:
+ shared = yield self.addressbookObjectUnderTest(home=home, addressbook_name=addressbook_name, name=child)
+ rw_mode = yield shared.readWriteAccess()
+ self.assertTrue(rw_mode, msg="Wrong mode: {}".format(child))
+
+
+
+class AddressBookSharing(BaseSharingTests):
+ """
+ Test store-based address book sharing.
+ """
+ @inlineCallbacks
+ def test_no_shares(self):
+ """
+ Test that initially there are no shares.
+ """
+
+ addressbook = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ invites = yield addressbook.sharingInvites()
+ self.assertEqual(len(invites), 0)
+ self.assertFalse(addressbook.isShared())
+
+
+ @inlineCallbacks
+ def test_invite_sharee(self):
+ """
+ Test invite/uninvite creates/removes shares and notifications.
+ """
+
+ # Invite
+ addressbook = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ invites = yield addressbook.sharingInvites()
+ self.assertEqual(len(invites), 0)
+ self.assertFalse(addressbook.isShared())
+
+ shareeView = yield addressbook.inviteUserToShare("user02", _BIND_MODE_READ, "summary")
+ invites = yield addressbook.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ self.assertEqual(invites[0].uid, shareeView.shareUID())
+ self.assertEqual(invites[0].ownerUID, "user01")
+ self.assertEqual(invites[0].shareeUID, "user02")
+ self.assertEqual(invites[0].mode, _BIND_MODE_READ)
+ self.assertEqual(invites[0].status, _BIND_STATUS_INVITED)
+ self.assertEqual(invites[0].summary, "summary")
+ inviteUID = shareeView.shareUID()
+
+ sharedName = shareeView.name()
+ shared = yield self.addressbookUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is None)
+
+ yield self._check_notifications("user02", [inviteUID, ])
+
+ self.assertTrue(addressbook.isShared())
+
+ yield self.commit()
+
+ # Uninvite
+ addressbook = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ invites = yield addressbook.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ self.assertTrue(addressbook.isShared())
+
+ yield addressbook.uninviteUserFromShare("user02")
+ invites = yield addressbook.sharingInvites()
+ self.assertEqual(len(invites), 0)
+
+ yield self._check_notifications("user02", [])
+
+ self.assertTrue(addressbook.isShared())
+
+ yield self.commit()
+
+ addressbook = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ self.assertFalse(addressbook.isShared())
+
+
+ @inlineCallbacks
+ def test_accept_share(self):
+ """
+ Test that invite+accept creates shares and notifications.
+ """
+
+ # Invite
+ addressbook = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ invites = yield addressbook.sharingInvites()
+ self.assertEqual(len(invites), 0)
+ self.assertFalse(addressbook.isShared())
+
+ shareeView = yield addressbook.inviteUserToShare("user02", _BIND_MODE_READ, "summary")
+ invites = yield addressbook.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ inviteUID = shareeView.shareUID()
+
+ sharedName = shareeView.name()
+ shared = yield self.addressbookUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is None)
+
+ yield self._check_notifications("user02", [inviteUID, ])
+
+ self.assertTrue(addressbook.isShared())
+
+ yield self.commit()
+
+ # Accept
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.acceptShare(inviteUID)
+
+ shared = yield self.addressbookUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is not None)
+
+ yield self._check_addressbook("user02", "user01", self.fully_shared_children)
+ yield self._check_notifications("user01", [inviteUID + "-reply", ])
+
+ addressbook = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ self.assertTrue(addressbook.isShared())
+
+ yield self.commit()
+
+ # Re-accept
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.acceptShare(inviteUID)
+
+ shared = yield self.addressbookUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is not None)
+
+ yield self._check_addressbook("user02", "user01", self.fully_shared_children)
+ yield self._check_notifications("user01", [inviteUID + "-reply", ])
+
+ addressbook = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ self.assertTrue(addressbook.isShared())
+
+
+ @inlineCallbacks
+ def test_decline_share(self):
+ """
+ Test that invite+decline does not create shares but does create notifications.
+ """
+
+ # Invite
+ addressbook = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ invites = yield addressbook.sharingInvites()
+ self.assertEqual(len(invites), 0)
+ self.assertFalse(addressbook.isShared())
+
+ shareeView = yield addressbook.inviteUserToShare("user02", _BIND_MODE_READ, "summary")
+ invites = yield addressbook.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ inviteUID = shareeView.shareUID()
+
+ sharedName = shareeView.name()
+ shared = yield self.addressbookUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is None)
+
+ yield self._check_notifications("user02", [inviteUID, ])
+
+ self.assertTrue(addressbook.isShared())
+
+ yield self.commit()
+
+ # Decline
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.declineShare(inviteUID)
+
+ shared = yield self.addressbookUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is None)
+
+ yield self._check_notifications("user01", [inviteUID + "-reply", ])
+
+ addressbook = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ self.assertTrue(addressbook.isShared())
+
+ yield self.commit()
+
+ # Redecline
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.declineShare(inviteUID)
+
+ shared = yield self.addressbookUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is None)
+
+ yield self._check_notifications("user01", [inviteUID + "-reply", ])
+
+ addressbook = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ self.assertTrue(addressbook.isShared())
+
+
+ @inlineCallbacks
+ def test_accept_decline_share(self):
+ """
+ Test that invite+accept/decline creates/removes shares and notifications.
+ Decline via the home.
+ """
+
+ # Invite
+ addressbook = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ invites = yield addressbook.sharingInvites()
+ self.assertEqual(len(invites), 0)
+
+ shareeView = yield addressbook.inviteUserToShare("user02", _BIND_MODE_READ, "summary")
+ invites = yield addressbook.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ inviteUID = shareeView.shareUID()
+
+ sharedName = shareeView.name()
+ shared = yield self.addressbookUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is None)
+
+ yield self._check_notifications("user02", [inviteUID, ])
+
+ yield self.commit()
+
+ # Accept
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.acceptShare(inviteUID)
+
+ shared = yield self.addressbookUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is not None)
+
+ yield self._check_addressbook("user02", "user01", self.fully_shared_children)
+ yield self._check_notifications("user01", [inviteUID + "-reply", ])
+
+ yield self.commit()
+
+ # Decline
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.declineShare(inviteUID)
+
+ shared = yield self.addressbookUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is None)
+
+ yield self._check_notifications("user01", [inviteUID + "-reply", ])
+
+
+ @inlineCallbacks
+ def test_accept_remove_share(self):
+ """
+ Test that invite+accept/decline creates/removes shares and notifications.
+ Decline via the shared collection (removal).
+ """
+
+ # Invite
+ addressbook = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ invites = yield addressbook.sharingInvites()
+ self.assertEqual(len(invites), 0)
+
+ shareeView = yield addressbook.inviteUserToShare("user02", _BIND_MODE_READ, "summary")
+ invites = yield addressbook.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ inviteUID = shareeView.shareUID()
+
+ sharedName = shareeView.name()
+ shared = yield self.addressbookUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is None)
+
+ yield self._check_notifications("user02", [inviteUID, ])
+
+ yield self.commit()
+
+ # Accept
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.acceptShare(inviteUID)
+
+ shared = yield self.addressbookUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is not None)
+
+ yield self._check_addressbook("user02", "user01", self.fully_shared_children)
+ yield self._check_notifications("user01", [inviteUID + "-reply", ])
+
+ yield self.commit()
+
+ # Delete
+ shared = yield self.addressbookUnderTest(home="user02", name=sharedName)
+ yield shared.deleteShare()
+
+ shared = yield self.addressbookUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is None)
+
+ yield self._check_notifications("user01", [inviteUID + "-reply", ])
+
+
+ @inlineCallbacks
+ def test_direct_sharee(self):
+ """
+ Test invite/uninvite creates/removes shares and notifications.
+ """
+
+ # Invite
+ addressbook = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ invites = yield addressbook.sharingInvites()
+ self.assertEqual(len(invites), 0)
+
+ shareeView = yield addressbook.directShareWithUser("user02")
+ invites = yield addressbook.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ self.assertEqual(invites[0].uid, shareeView.shareUID())
+ self.assertEqual(invites[0].ownerUID, "user01")
+ self.assertEqual(invites[0].shareeUID, "user02")
+ self.assertEqual(invites[0].mode, _BIND_MODE_DIRECT)
+ self.assertEqual(invites[0].status, _BIND_STATUS_ACCEPTED)
+
+ sharedName = shareeView.name()
+ shared = yield self.addressbookUnderTest(home="user02", name=sharedName)
+ self.assertTrue(shared is not None)
+
+ yield self._check_addressbook("user02", "user01", self.fully_shared_children)
+ yield self._check_notifications("user02", [])
+
+ yield self.commit()
+
+ # Remove
+ shared = yield self.addressbookUnderTest(home="user02", name=sharedName)
+ yield shared.deleteShare()
+
+ addressbook = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ invites = yield addressbook.sharingInvites()
+ self.assertEqual(len(invites), 0)
+
+ yield self._check_notifications("user02", [])
+
+
+ @inlineCallbacks
+ def test_sharedNotifierID(self):
+ shared_name = yield self._createShare()
+
+ home = yield self.addressbookHomeUnderTest(name="user01")
+ self.assertEquals(home.notifierID(), ("CardDAV", "user01",))
+ addressbook = yield home.addressbookWithName("addressbook")
+ self.assertEquals(addressbook.notifierID(), ("CardDAV", "user01/addressbook",))
+ yield self.commit()
+
+ home = yield self.addressbookHomeUnderTest(name="user02")
+ self.assertEquals(home.notifierID(), ("CardDAV", "user02",))
+ addressbook = yield home.addressbookWithName(shared_name)
+ self.assertEquals(addressbook.notifierID(), ("CardDAV", "user01/addressbook",))
+ yield self.commit()
+
+
+
+class GroupSharing(BaseSharingTests):
+ """
+ Test store-based group book sharing.
+ """
+
+ @inlineCallbacks
+ def test_no_shares(self):
+ """
+ Test that initially there are no shares.
+ """
+
+ addressbook = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ invites = yield addressbook.sharingInvites()
+ self.assertEqual(len(invites), 0)
+
+
+ @inlineCallbacks
+ def test_invite_sharee(self):
+ """
+ Test invite/uninvite creates/removes shares and notifications.
+ """
+
+ # Invite
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name="group1.vcf")
+ invites = yield group.sharingInvites()
+ self.assertEqual(len(invites), 0)
+ self.assertFalse(group.isShared())
+
+ shareeView = yield group.inviteUserToShare("user02", _BIND_MODE_READ, "summary")
+ invites = yield group.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ self.assertEqual(invites[0].uid, shareeView.shareUID())
+ self.assertEqual(invites[0].ownerUID, "user01")
+ self.assertEqual(invites[0].shareeUID, "user02")
+ self.assertEqual(invites[0].mode, _BIND_MODE_READ)
+ self.assertEqual(invites[0].status, _BIND_STATUS_INVITED)
+ self.assertEqual(invites[0].summary, "summary")
+ inviteUID = shareeView.shareUID()
+
+ self.assertTrue(group.isShared())
+
+ yield self.commit()
+
+ sharedParent = yield self.addressbookUnderTest(home="user02", name="user01")
+ self.assertTrue(sharedParent is None)
+
+ yield self._check_notifications("user02", [inviteUID, ])
+
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name="group1.vcf")
+ self.assertTrue(group.isShared())
+
+ yield self.commit()
+
+ # Uninvite
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name="group1.vcf")
+ invites = yield group.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ self.assertTrue(group.isShared())
+
+ yield group.uninviteUserFromShare("user02")
+ invites = yield group.sharingInvites()
+ self.assertEqual(len(invites), 0)
+ self.assertTrue(group.isShared())
+
+ yield self._check_notifications("user02", [])
+
+ yield self.commit()
+
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name="group1.vcf")
+ self.assertFalse(group.isShared())
+
+
+ @inlineCallbacks
+ def test_accept_share(self):
+ """
+ Test that invite+accept creates shares and notifications.
+ """
+
+ # Invite
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name="group1.vcf")
+ invites = yield group.sharingInvites()
+ self.assertEqual(len(invites), 0)
+ self.assertFalse(group.isShared())
+
+ shareeView = yield group.inviteUserToShare("user02", _BIND_MODE_READ, "summary")
+ invites = yield group.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ inviteUID = shareeView.shareUID()
+
+ sharedParent = yield self.addressbookUnderTest(home="user02", name="user01")
+ self.assertTrue(sharedParent is None)
+
+ yield self._check_notifications("user02", [inviteUID, ])
+
+ self.assertTrue(group.isShared())
+
+ yield self.commit()
+
+ # Accept
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.acceptShare(inviteUID)
+
+ yield self._check_addressbook("user02", "user01", self.group1_children)
+ yield self._check_notifications("user01", [inviteUID + "-reply", ])
+
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name="group1.vcf")
+ self.assertTrue(group.isShared())
+
+ yield self.commit()
+
+ # Re-accept
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.acceptShare(inviteUID)
+
+ yield self._check_addressbook("user02", "user01", self.group1_children)
+ yield self._check_notifications("user01", [inviteUID + "-reply", ])
+
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name="group1.vcf")
+ self.assertTrue(group.isShared())
+
+
+ @inlineCallbacks
+ def test_decline_share(self):
+ """
+ Test that invite+decline does not create shares but does create notifications.
+ """
+
+ # Invite
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name="group1.vcf")
+ invites = yield group.sharingInvites()
+ self.assertEqual(len(invites), 0)
+ self.assertFalse(group.isShared())
+
+ shareeView = yield group.inviteUserToShare("user02", _BIND_MODE_READ, "summary")
+ invites = yield group.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ inviteUID = shareeView.shareUID()
+
+ sharedParent = yield self.addressbookUnderTest(home="user02", name="user01")
+ self.assertTrue(sharedParent is None)
+
+ yield self._check_notifications("user02", [inviteUID, ])
+
+ self.assertTrue(group.isShared())
+
+ yield self.commit()
+
+ # Decline
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.declineShare(inviteUID)
+
+ sharedParent = yield self.addressbookUnderTest(home="user02", name="user01")
+ self.assertTrue(sharedParent is None)
+
+ yield self._check_notifications("user01", [inviteUID + "-reply", ])
+
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name="group1.vcf")
+ self.assertTrue(group.isShared())
+
+ yield self.commit()
+
+ # Re-decline
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.declineShare(inviteUID)
+
+ sharedParent = yield self.addressbookUnderTest(home="user02", name="user01")
+ self.assertTrue(sharedParent is None)
+
+ yield self._check_notifications("user01", [inviteUID + "-reply", ])
+
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name="group1.vcf")
+ self.assertTrue(group.isShared())
+
+
+ @inlineCallbacks
+ def test_accept_decline_share(self):
+ """
+ Test that invite+accept/decline creates/removes shares and notifications.
+ Decline via the home.
+ """
+
+ # Invite
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name="group1.vcf")
+ invites = yield group.sharingInvites()
+ self.assertEqual(len(invites), 0)
+ self.assertFalse(group.isShared())
+
+ shareeView = yield group.inviteUserToShare("user02", _BIND_MODE_READ, "summary")
+ invites = yield group.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ inviteUID = shareeView.shareUID()
+
+ sharedParent = yield self.addressbookUnderTest(home="user02", name="user01")
+ self.assertTrue(sharedParent is None)
+
+ yield self._check_notifications("user02", [inviteUID, ])
+
+ self.assertTrue(group.isShared())
+
+ yield self.commit()
+
+ # Accept
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.acceptShare(inviteUID)
+
+ yield self._check_addressbook("user02", "user01", self.group1_children)
+ yield self._check_notifications("user01", [inviteUID + "-reply", ])
+
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name="group1.vcf")
+ self.assertTrue(group.isShared())
+
+ yield self.commit()
+
+ # Decline
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.declineShare(inviteUID)
+
+ sharedParent = yield self.addressbookUnderTest(home="user02", name="user01")
+ self.assertTrue(sharedParent is None)
+
+ yield self._check_notifications("user01", [inviteUID + "-reply", ])
+
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name="group1.vcf")
+ self.assertTrue(group.isShared())
+
+
+ @inlineCallbacks
+ def test_accept_remove_share(self):
+ """
+ Test that invite+accept/decline creates/removes shares and notifications.
+ Decline via the shared collection (removal).
+ """
+
+ # Invite
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name="group1.vcf")
+ invites = yield group.sharingInvites()
+ self.assertEqual(len(invites), 0)
+
+ shareeView = yield group.inviteUserToShare("user02", _BIND_MODE_READ, "summary")
+ invites = yield group.sharingInvites()
+ self.assertEqual(len(invites), 1)
+ inviteUID = shareeView.shareUID()
+
+ sharedParent = yield self.addressbookUnderTest(home="user02", name="user01")
+ self.assertTrue(sharedParent is None)
+
+ yield self._check_notifications("user02", [inviteUID, ])
+
+ yield self.commit()
+
+ # Accept
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.acceptShare(inviteUID)
+
+ yield self._check_addressbook("user02", "user01", self.group1_children)
+ yield self._check_notifications("user01", [inviteUID + "-reply", ])
+
+ yield self.commit()
+
+ # Delete
+ group = yield self.addressbookObjectUnderTest(home="user02", addressbook_name="user01", name="group1.vcf")
+ yield group.deleteShare()
+
+ sharedParent = yield self.addressbookUnderTest(home="user02", name="user01")
+ self.assertTrue(sharedParent is None)
+
+ yield self._check_notifications("user01", [inviteUID + "-reply", ])
+
+
+ @inlineCallbacks
+ def test_accept_two_groups(self):
+ """
+ Test that accept of two groups works.
+ """
+
+ # Two shares
+ inviteUID1 = yield self._createGroupShare(groupname="group1.vcf")
+ inviteUID2 = yield self._createGroupShare(groupname="group2.vcf")
+
+ yield self._check_addressbook("user02", "user01", self.all_children)
+ yield self._check_notifications("user01", [inviteUID1 + "-reply", inviteUID2 + "-reply", ])
+
+
+ @inlineCallbacks
+ def test_accept_uninvite_two_groups(self):
+ """
+ Test that accept of two groups works, then uninvite each one.
+ """
+
+ # Two shares
+ inviteUID1 = yield self._createGroupShare(groupname="group1.vcf")
+ inviteUID2 = yield self._createGroupShare(groupname="group2.vcf")
+
+ yield self._check_addressbook("user02", "user01", self.all_children)
+ yield self._check_notifications("user01", [inviteUID1 + "-reply", inviteUID2 + "-reply", ])
+
+ yield self.commit()
+
+ # Uninvite one
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name="group1.vcf")
+ yield group.uninviteUserFromShare("user02")
+ invites = yield group.sharingInvites()
+ self.assertEqual(len(invites), 0)
+
+ yield self._check_addressbook("user02", "user01", self.group2_children)
+
+ shared = yield self.addressbookObjectUnderTest(home="user02", addressbook_name="user01", name="group1.vcf")
+ self.assertTrue(shared is None)
+ shared = yield self.addressbookObjectUnderTest(home="user02", addressbook_name="user01", name="card2.vcf")
+ self.assertTrue(shared is None)
+
+ yield self.commit()
+
+ # Uninvite other
+ group = yield self.addressbookObjectUnderTest(home="user02", addressbook_name="user01", name="group2.vcf")
+ yield group.uninviteUserFromShare("user02")
+ invites = yield group.sharingInvites()
+ self.assertEqual(len(invites), 0)
+
+ sharedParent = yield self.addressbookUnderTest(home="user02", name="user01")
+ self.assertTrue(sharedParent is None)
+
+
+ @inlineCallbacks
+ def test_accept_decline_two_groups(self):
+ """
+ Test that accept of two groups works, then decline each one.
+ """
+
+ # Two shares
+ inviteUID1 = yield self._createGroupShare(groupname="group1.vcf")
+ inviteUID2 = yield self._createGroupShare(groupname="group2.vcf")
+
+ yield self._check_addressbook("user02", "user01", self.all_children)
+ yield self._check_notifications("user01", [inviteUID1 + "-reply", inviteUID2 + "-reply", ])
+
+ yield self.commit()
+
+ # Decline one
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.declineShare(inviteUID1)
+
+ yield self._check_addressbook("user02", "user01", self.group2_children)
+
+ shared = yield self.addressbookObjectUnderTest(home="user02", addressbook_name="user01", name="group1.vcf")
+ self.assertTrue(shared is None)
+ shared = yield self.addressbookObjectUnderTest(home="user02", addressbook_name="user01", name="card2.vcf")
+ self.assertTrue(shared is None)
+
+ yield self.commit()
+
+ # Decline other
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.declineShare(inviteUID2)
+
+ sharedParent = yield self.addressbookUnderTest(home="user02", name="user01")
+ self.assertTrue(sharedParent is None)
+
+
+ @inlineCallbacks
+ def test_accept_two_groups_different_access(self):
+ """
+ Test that accept of two groups works, then uninvite each one.
+ """
+
+ # Two shares
+ inviteUID1 = yield self._createGroupShare(groupname="group1.vcf")
+ inviteUID2 = yield self._createGroupShare(groupname="group2.vcf", mode=_BIND_MODE_WRITE)
+
+ yield self._check_addressbook("user02", "user01", self.all_children)
+ yield self._check_notifications("user01", [inviteUID1 + "-reply", inviteUID2 + "-reply", ])
+
+ # Read only for all, write for group2's items
+ yield self._check_read_only("user02", "user01", ["group1.vcf", "card2.vcf", ])
+ yield self._check_read_write("user02", "user01", ["group2.vcf", "card1.vcf", "card3.vcf", ])
+
+ yield self.commit()
+
+ # Decline one
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.declineShare(inviteUID2)
+
+ yield self._check_addressbook("user02", "user01", self.group1_children)
+
+ yield self._check_read_only("user02", "user01", ["group1.vcf", "card1.vcf", "card2.vcf", ])
+
+ shared = yield self.addressbookObjectUnderTest(home="user02", addressbook_name="user01", name="group2.vcf")
+ self.assertTrue(shared is None)
+ shared = yield self.addressbookObjectUnderTest(home="user02", addressbook_name="user01", name="card3.vcf")
+ self.assertTrue(shared is None)
+
+ yield self.commit()
+
+ # Decline other
+ shareeHome = yield self.addressbookHomeUnderTest(name="user02")
+ yield shareeHome.declineShare(inviteUID1)
+
+ sharedParent = yield self.addressbookUnderTest(home="user02", name="user01")
+ self.assertTrue(sharedParent is None)
+
+
+
+class MixedSharing(BaseSharingTests):
+ """
+ Test store-based combined address book and group book sharing.
+ """
+
+ @inlineCallbacks
+ def test_addressbook_ro_then_groups(self):
+
+ # Share address book read-only
+ shareeName = yield self._createShare()
+ yield self._check_addressbook("user02", "user01", self.fully_shared_children)
+ yield self._check_read_only("user02", "user01", self.all_children)
+ yield self._check_read_write("user02", "user01", [])
+ yield self._check_notifications("user02", [shareeName, ])
+
+ # Add group1 read-write
+ inviteUID1 = yield self._createGroupShare(groupname="group1.vcf", mode=_BIND_MODE_WRITE)
+
+ yield self._check_addressbook("user02", "user01", self.fully_shared_children)
+ yield self._check_read_only("user02", "user01", ["group2.vcf", "card3.vcf", ])
+ yield self._check_read_write("user02", "user01", ["group1.vcf", "card1.vcf", "card2.vcf", ])
+ yield self._check_notifications("user02", [shareeName, inviteUID1, ])
+
+ # Add group2 read-write
+ inviteUID2 = yield self._createGroupShare(groupname="group2.vcf", mode=_BIND_MODE_WRITE)
+
+ yield self._check_addressbook("user02", "user01", self.fully_shared_children)
+ yield self._check_read_only("user02", "user01", [])
+ yield self._check_read_write("user02", "user01", self.all_children)
+ yield self._check_notifications("user02", [shareeName, inviteUID1, inviteUID2])
+
+ # Uninvite group1
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name="group1.vcf")
+ yield group.uninviteUserFromShare("user02")
+
+ yield self._check_addressbook("user02", "user01", self.fully_shared_children)
+ yield self._check_read_only("user02", "user01", ["group1.vcf", "card2.vcf", ])
+ yield self._check_read_write("user02", "user01", ["group2.vcf", "card1.vcf", "card3.vcf", ])
+
+ # Uninvite group2
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name="group2.vcf")
+ yield group.uninviteUserFromShare("user02")
+
+ yield self._check_addressbook("user02", "user01", self.fully_shared_children)
+ yield self._check_read_only("user02", "user01", self.all_children)
+ yield self._check_read_write("user02", "user01", [])
+
+
+ @inlineCallbacks
+ def test_addressbook_ro_then_group_no_accept(self):
+
+ # Share address book read-only
+ shareeName = yield self._createShare()
+ yield self._check_addressbook("user02", "user01", self.fully_shared_children)
+ yield self._check_read_only("user02", "user01", self.all_children)
+ yield self._check_read_write("user02", "user01", [])
+ yield self._check_notifications("user02", [shareeName, ])
+
+ # Add group1 read-write - but do not accept
+ group = yield self.addressbookObjectUnderTest(home="user01", addressbook_name="addressbook", name="group1.vcf")
+ invited = yield group.inviteUserToShare("user02", _BIND_MODE_WRITE, "summary")
+ yield self._check_notifications("user02", [shareeName, invited.shareUID(), ])
+
+ yield self._check_addressbook("user02", "user01", self.fully_shared_children)
+ yield self._check_read_only("user02", "user01", self.all_children)
+ yield self._check_read_write("user02", "user01", [])
+
+
+
+class SharingRevisions(BaseSharingTests):
+ """
+ Test store-based sharing and interaction with revision table.
+ """
+
+ @inlineCallbacks
+ def test_shareWithRevision(self):
+ """
+ Verify that bindRevision on addressbooks and shared addressbooks has the correct value.
+ """
+ yield self._createShare()
+
+ normalAB = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ self.assertEqual(normalAB._bindRevision, 0)
+ otherAB = yield self.addressbookUnderTest(home="user02", name="user01")
+ self.assertNotEqual(otherAB._bindRevision, 0)
+
+
+ @inlineCallbacks
+ def test_shareGroupWithRevision(self):
+ """
+ Verify that bindRevision on addressbooks and shared groups has the correct value.
+ """
+
+ yield self._createGroupShare(groupname="group1.vcf")
+
+ normalAB = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ self.assertEqual(normalAB._bindRevision, 0)
+ otherAB = yield self.addressbookUnderTest(home="user02", name="user01")
+ self.assertNotEqual(otherAB._bindRevision, 0)
+
+
+ @inlineCallbacks
+ def test_updateShareRevision(self):
+ """
+ Verify that bindRevision on addressbooks and shared addressbooks has the correct value.
+ """
+ newABShareUID = yield self._inviteShare()
+
+ normalAB = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ self.assertEqual(normalAB._bindRevision, 0)
+ otherHome = yield self.addressbookHomeUnderTest(name="user02")
+ otherAB = yield otherHome.anyObjectWithShareUID("user01")
+ self.assertEqual(otherAB._bindRevision, 0)
+ yield self.commit()
+
+ yield self._acceptShare(newABShareUID)
+
+ normalAB = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ self.assertEqual(normalAB._bindRevision, 0)
+ otherAB = yield self.addressbookUnderTest(home="user02", name="user01")
+ self.assertNotEqual(otherAB._bindRevision, 0)
+
+
+ @inlineCallbacks
+ def test_updateSharedGroupRevision(self):
+ """
+ Verify that bindRevision on addressbooks and shared addressbooks has the correct value.
+ """
+ newGroupShareUID = yield self._inviteGroupShare(groupname="group1.vcf")
+
+ normalAB = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ self.assertEqual(normalAB._bindRevision, 0)
+ otherHome = yield self.addressbookHomeUnderTest(name="user02")
+ otherAB = yield otherHome.anyObjectWithShareUID("user01")
+ self.assertEqual(otherAB._bindRevision, 0)
+ yield self.commit()
+
+ yield self._acceptGroupShare(newGroupShareUID)
+
+ normalAB = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ self.assertEqual(normalAB._bindRevision, 0)
+ otherAB = yield self.addressbookUnderTest(home="user02", name="user01")
+ self.assertNotEqual(otherAB._bindRevision, 0)
+
+
+# @inlineCallbacks
+ def test_sharedRevisions(self):
+ """
+ Verify that resourceNamesSinceRevision returns all resources after initial bind and sync.
+ """
+
+ yield self._createShare()
+
+ normalAB = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ self.assertEqual(normalAB._bindRevision, 0)
+ otherAB = yield self.addressbookUnderTest(home="user02", name="user01")
+ self.assertNotEqual(otherAB._bindRevision, 0)
+
+ changed, deleted = yield otherAB.resourceNamesSinceRevision(otherAB._bindRevision - 1)
+ self.assertNotEqual(len(changed), 0)
+ self.assertEqual(len(deleted), 0)
+
+ changed, deleted = yield otherAB.resourceNamesSinceRevision(otherAB._bindRevision)
+ self.assertEqual(len(changed), 0)
+ self.assertEqual(len(deleted), 0)
+
+ otherHome = yield self.addressbookHomeUnderTest(name="user02")
+ for depth in ("1", "infinity",):
+ changed, deleted = yield otherHome.resourceNamesSinceRevision(otherAB._bindRevision - 1, depth)
+ self.assertNotEqual(len(changed), 0)
+ self.assertEqual(len(deleted), 0)
+
+ changed, deleted = yield otherHome.resourceNamesSinceRevision(otherAB._bindRevision, depth)
+ self.assertEqual(len(changed), 0)
+ self.assertEqual(len(deleted), 0)
+
+
+ @inlineCallbacks
+ def test_sharedGroupRevisions(self):
+ """
+ Verify that resourceNamesSinceRevision returns all resources after initial bind and sync.
+ """
+
+ yield self._createGroupShare("group1.vcf")
+
+ normalAB = yield self.addressbookUnderTest(home="user01", name="addressbook")
+ self.assertEqual(normalAB._bindRevision, 0)
+ otherAB = yield self.addressbookUnderTest(home="user02", name="user01")
+ self.assertNotEqual(otherAB._bindRevision, 0)
+
+ changed, deleted = yield otherAB.resourceNamesSinceRevision(otherAB._bindRevision - 1)
+ self.assertNotEqual(len(changed), 0)
+ self.assertEqual(len(deleted), 0)
+
+ changed, deleted = yield otherAB.resourceNamesSinceRevision(otherAB._bindRevision)
+ self.assertEqual(len(changed), 0)
+ self.assertEqual(len(deleted), 0)
+
+ otherHome = yield self.addressbookHomeUnderTest(name="user02")
+ for depth in ("1", "infinity",):
+ changed, deleted = yield otherHome.resourceNamesSinceRevision(otherAB._bindRevision - 1, depth)
+ self.assertNotEqual(len(changed), 0)
+ self.assertEqual(len(deleted), 0)
+
+ changed, deleted = yield otherHome.resourceNamesSinceRevision(otherAB._bindRevision, depth)
+ self.assertEqual(len(changed), 0)
+ self.assertEqual(len(deleted), 0)
+
+
+ @inlineCallbacks
+ def test_addressbookRevisionChangeConcurrency(self):
+ """
+ Test that two concurrent attempts to add resources in two separate
+ calendar homes does not deadlock on the revision table update.
+ """
+
+ # Create first events in different addressbook homes
+ txn1 = self._sqlStore.newTransaction()
+ txn2 = self._sqlStore.newTransaction()
+
+ addressbook_uid1_in_txn1 = yield self.addressbookUnderTest(txn1, "addressbook", "user01")
+ addressbook_uid2_in_txn2 = yield self.addressbookUnderTest(txn2, "addressbook", "user02")
+
+ data = """BEGIN:VCARD
+VERSION:3.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+UID:data%(ctr)s
+FN:Data %(ctr)s
+N:Sub Group;;;;
+REV:20120503T194243Z
+END:VCARD
+
+"""
+
+ component = Component.fromString(data % {"ctr": 1})
+ yield addressbook_uid1_in_txn1.createAddressBookObjectWithName("data1.ics", component)
+
+ component = Component.fromString(data % {"ctr": 2})
+ yield addressbook_uid2_in_txn2.createAddressBookObjectWithName("data2.ics", component)
+
+ # Setup deferreds to run concurrently and create second events in the calendar homes
+ # previously used by the other transaction - this could create the deadlock.
+ @inlineCallbacks
+ def _defer_uid3():
+ addressbook_uid1_in_txn2 = yield self.addressbookUnderTest(txn2, "addressbook", "user01")
+ component = Component.fromString(data % {"ctr": 3})
+ yield addressbook_uid1_in_txn2.createAddressBookObjectWithName("data3.ics", component)
+ yield txn2.commit()
+ d1 = _defer_uid3()
+
+ @inlineCallbacks
+ def _defer_uid4():
+ addressbook_uid2_in_txn1 = yield self.addressbookUnderTest(txn1, "addressbook", "user02")
+ component = Component.fromString(data % {"ctr": 4})
+ yield addressbook_uid2_in_txn1.createAddressBookObjectWithName("data4.ics", component)
+ yield txn1.commit()
+ d2 = _defer_uid4()
+
+ # Now do the concurrent provision attempt
+ yield DeferredList([d1, d2])
+
+ # Verify we did not have a deadlock and all resources have been created.
+ vcarddata1 = yield self.addressbookObjectUnderTest(name="data1.ics", addressbook_name="addressbook", home="user01")
+ vcarddata2 = yield self.addressbookObjectUnderTest(name="data2.ics", addressbook_name="addressbook", home="user02")
+ vcarddata3 = yield self.addressbookObjectUnderTest(name="data3.ics", addressbook_name="addressbook", home="user01")
+ vcarddata4 = yield self.addressbookObjectUnderTest(name="data4.ics", addressbook_name="addressbook", home="user02")
+ self.assertNotEqual(vcarddata1, None)
+ self.assertNotEqual(vcarddata2, None)
+ self.assertNotEqual(vcarddata3, None)
+ self.assertNotEqual(vcarddata4, None)
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastorefilepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/file.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/file.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/txdav/common/datastore/file.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -58,6 +58,7 @@
</span><span class="cx"> from errno import EEXIST, ENOENT
</span><span class="cx"> from zope.interface import implements, directlyProvides
</span><span class="cx">
</span><ins>+import json
</ins><span class="cx"> import uuid
</span><span class="cx"> from twistedcaldav.sql import AbstractSQLDatabase, db_prefix
</span><span class="cx"> import os
</span><span class="lines">@@ -1499,17 +1500,17 @@
</span><span class="cx"> return self.notificationObjectWithName(name)
</span><span class="cx">
</span><span class="cx">
</span><del>- def writeNotificationObject(self, uid, xmltype, xmldata):
</del><ins>+ def writeNotificationObject(self, uid, notificationtype, notificationdata):
</ins><span class="cx"> name = uid + ".xml"
</span><span class="cx"> if name.startswith("."):
</span><span class="cx"> raise ObjectResourceNameNotAllowedError(name)
</span><span class="cx">
</span><span class="cx"> objectResource = NotificationObject(name, self)
</span><del>- objectResource.setData(uid, xmltype, xmldata)
</del><ins>+ objectResource.setData(uid, notificationtype, notificationdata)
</ins><span class="cx"> self._cachedObjectResources[name] = objectResource
</span><span class="cx">
</span><span class="cx"> # Update database
</span><del>- self.retrieveOldIndex().addOrUpdateRecord(NotificationRecord(uid, name, xmltype.name))
</del><ins>+ self.retrieveOldIndex().addOrUpdateRecord(NotificationRecord(uid, name, notificationtype))
</ins><span class="cx">
</span><span class="cx"> self.notifyChanged()
</span><span class="cx">
</span><span class="lines">@@ -1572,15 +1573,16 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @writeOperation
</span><del>- def setData(self, uid, xmltype, xmldata, inserting=False):
</del><ins>+ def setData(self, uid, notificationtype, notificationdata, inserting=False):
</ins><span class="cx">
</span><span class="cx"> rname = uid + ".xml"
</span><span class="cx"> self._parentCollection.retrieveOldIndex().addOrUpdateRecord(
</span><del>- NotificationRecord(uid, rname, xmltype.name)
</del><ins>+ NotificationRecord(uid, rname, notificationtype)
</ins><span class="cx"> )
</span><span class="cx">
</span><del>- self._xmldata = xmldata
- md5 = hashlib.md5(xmldata).hexdigest()
</del><ins>+ self._notificationdata = notificationdata
+ notificationtext = json.dumps(self._notificationdata)
+ md5 = hashlib.md5(notificationtext).hexdigest()
</ins><span class="cx">
</span><span class="cx"> def do():
</span><span class="cx"> backup = None
</span><span class="lines">@@ -1591,7 +1593,7 @@
</span><span class="cx"> try:
</span><span class="cx"> # FIXME: concurrency problem; if this write is interrupted
</span><span class="cx"> # halfway through, the underlying file will be corrupt.
</span><del>- fh.write(xmldata)
</del><ins>+ fh.write(notificationtext)
</ins><span class="cx"> finally:
</span><span class="cx"> fh.close()
</span><span class="cx"> def undo():
</span><span class="lines">@@ -1610,7 +1612,7 @@
</span><span class="cx">
</span><span class="cx"> props = self.properties()
</span><span class="cx"> props[PropertyName(*GETContentType.qname())] = GETContentType.fromString(generateContentType(MimeType("text", "xml", params={"charset": "utf-8"})))
</span><del>- props[PropertyName.fromElement(NotificationType)] = NotificationType(xmltype)
</del><ins>+ props[PropertyName.fromElement(NotificationType)] = NotificationType(json.dumps(notificationtype))
</ins><span class="cx"> props[PropertyName.fromElement(TwistedGETContentMD5)] = TwistedGETContentMD5.fromString(md5)
</span><span class="cx">
</span><span class="cx"> # FIXME: the property store's flush() method may already have been
</span><span class="lines">@@ -1620,11 +1622,11 @@
</span><span class="cx"> # manipulation methods won't work.
</span><span class="cx"> self._transaction.addOperation(self.properties().flush, "post-update property flush")
</span><span class="cx">
</span><del>- _xmldata = None
</del><ins>+ _notificationdata = None
</ins><span class="cx">
</span><del>- def xmldata(self):
- if self._xmldata is not None:
- return self._xmldata
</del><ins>+ def notificationData(self):
+ if self._notificationdata is not None:
+ return self._notificationdata
</ins><span class="cx"> try:
</span><span class="cx"> fh = self._path.open()
</span><span class="cx"> except IOError, e:
</span><span class="lines">@@ -1638,14 +1640,14 @@
</span><span class="cx"> finally:
</span><span class="cx"> fh.close()
</span><span class="cx">
</span><del>- return text
</del><ins>+ return json.loads(text)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def uid(self):
</span><span class="cx"> return self._uid
</span><span class="cx">
</span><span class="cx">
</span><del>- def xmlType(self):
</del><ins>+ def notificationType(self):
</ins><span class="cx"> # NB This is the NotificationType property element
</span><span class="cx"> return self.properties()[PropertyName.fromElement(NotificationType)]
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/sql.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -14,6 +14,9 @@
</span><span class="cx"> # See the License for the specific language governing permissions and
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> ##
</span><ins>+from collections import namedtuple
+from txdav.xml import element
+from txdav.base.propertystore.base import PropertyName
</ins><span class="cx">
</span><span class="cx"> """
</span><span class="cx"> SQL data store.
</span><span class="lines">@@ -50,7 +53,6 @@
</span><span class="cx"> from twisted.python.util import FancyEqMixin
</span><span class="cx">
</span><span class="cx"> from twistedcaldav.config import config
</span><del>-from twistedcaldav.customxml import NotificationType
</del><span class="cx"> from twistedcaldav.dateops import datetimeMktime, pyCalendarTodatetime
</span><span class="cx">
</span><span class="cx"> from txdav.base.datastore.util import QueryCacher
</span><span class="lines">@@ -61,7 +63,9 @@
</span><span class="cx"> from txdav.carddav.iaddressbookstore import IAddressBookTransaction
</span><span class="cx"> from txdav.common.datastore.common import HomeChildBase
</span><span class="cx"> from txdav.common.datastore.sql_tables import _BIND_MODE_OWN, \
</span><del>- _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED
</del><ins>+ _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED, _BIND_STATUS_INVALID, \
+ _BIND_STATUS_INVITED, _BIND_MODE_DIRECT, _BIND_STATUS_DELETED, \
+ _BIND_MODE_INDIRECT
</ins><span class="cx"> from txdav.common.datastore.sql_tables import schema, splitSQLString
</span><span class="cx"> from txdav.common.icommondatastore import ConcurrentModification
</span><span class="cx"> from txdav.common.icommondatastore import HomeChildNameNotAllowedError, \
</span><span class="lines">@@ -72,13 +76,13 @@
</span><span class="cx"> from txdav.common.idirectoryservice import IStoreDirectoryService
</span><span class="cx"> from txdav.common.inotifications import INotificationCollection, \
</span><span class="cx"> INotificationObject
</span><del>-from txdav.xml.parser import WebDAVDocument
</del><span class="cx"> from txdav.idav import ChangeCategory
</span><span class="cx">
</span><span class="cx"> from uuid import uuid4, UUID
</span><span class="cx">
</span><span class="cx"> from zope.interface import implements, directlyProvides
</span><span class="cx">
</span><ins>+import json
</ins><span class="cx"> import sys
</span><span class="cx"> import time
</span><span class="cx">
</span><span class="lines">@@ -639,6 +643,14 @@
</span><span class="cx"> return NotificationCollection.notificationsWithUID(self, uid, create)
</span><span class="cx">
</span><span class="cx">
</span><ins>+ @memoizedKey("rid", "_notificationHomes")
+ def notificationsWithResourceID(self, rid):
+ """
+ Implement notificationsWithResourceID.
+ """
+ return NotificationCollection.notificationsWithResourceID(self, rid)
+
+
</ins><span class="cx"> @classproperty
</span><span class="cx"> def _insertAPNSubscriptionQuery(cls): #@NoSelf
</span><span class="cx"> apn = schema.APN_SUBSCRIPTIONS
</span><span class="lines">@@ -1426,10 +1438,43 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><del>-class CommonHome(object):
</del><ins>+class SharingHomeMixIn(object):
+ """
+ Common class for CommonHome to implement sharing operations
+ """
+
+ @inlineCallbacks
+ def acceptShare(self, shareUID, summary=None):
+ """
+ This share is being accepted.
+ """
+
+ shareeView = yield self.anyObjectWithShareUID(shareUID)
+ if shareeView is not None:
+ yield shareeView.acceptShare(summary)
+
+ returnValue(shareeView)
+
+
+ @inlineCallbacks
+ def declineShare(self, shareUID):
+ """
+ This share is being declined.
+ """
+
+ shareeView = yield self.anyObjectWithShareUID(shareUID)
+ if shareeView is not None:
+ yield shareeView.declineShare()
+
+ returnValue(shareeView)
+
+
+
+class CommonHome(SharingHomeMixIn):
</ins><span class="cx"> log = Logger()
</span><span class="cx">
</span><span class="cx"> # All these need to be initialized by derived classes for each store type
</span><ins>+ _homeType = None
</ins><span class="cx"> _homeTable = None
</span><span class="cx"> _homeMetaDataTable = None
</span><span class="cx"> _childClass = None
</span><span class="lines">@@ -1472,10 +1517,13 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @classproperty
</span><del>- def _resourceIDFromOwnerQuery(cls): #@NoSelf
</del><ins>+ def _homeColumnsFromOwnerQuery(cls): #@NoSelf
</ins><span class="cx"> home = cls._homeSchema
</span><del>- return Select([home.RESOURCE_ID],
- From=home, Where=home.OWNER_UID == Parameter("ownerUID"))
</del><ins>+ return Select(
+ cls.homeColumns(),
+ From=home,
+ Where=home.OWNER_UID == Parameter("ownerUID")
+ )
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> @classproperty
</span><span class="lines">@@ -1495,6 +1543,34 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @classmethod
</span><ins>+ def homeColumns(cls):
+ """
+ Return a list of column names to retrieve when doing an ownerUID->home lookup.
+ """
+
+ # Common behavior is to have created and modified
+
+ return (
+ cls._homeSchema.RESOURCE_ID,
+ cls._homeSchema.OWNER_UID,
+ )
+
+
+ @classmethod
+ def homeAttributes(cls):
+ """
+ Return a list of attributes names to map L{homeColumns} to.
+ """
+
+ # Common behavior is to have created and modified
+
+ return (
+ "_resourceID",
+ "_ownerUID",
+ )
+
+
+ @classmethod
</ins><span class="cx"> def metadataColumns(cls):
</span><span class="cx"> """
</span><span class="cx"> Return a list of column name for retrieval of metadata. This allows
</span><span class="lines">@@ -1535,13 +1611,14 @@
</span><span class="cx"> """
</span><span class="cx"> result = yield self._cacher.get(self._ownerUID)
</span><span class="cx"> if result is None:
</span><del>- result = yield self._resourceIDFromOwnerQuery.on(
</del><ins>+ result = yield self._homeColumnsFromOwnerQuery.on(
</ins><span class="cx"> self._txn, ownerUID=self._ownerUID)
</span><span class="cx"> if result and not no_cache:
</span><span class="cx"> yield self._cacher.set(self._ownerUID, result)
</span><span class="cx">
</span><span class="cx"> if result:
</span><del>- self._resourceID = result[0][0]
</del><ins>+ for attr, value in zip(self.homeAttributes(), result[0]):
+ setattr(self, attr, value)
</ins><span class="cx">
</span><span class="cx"> queryCacher = self._txn._queryCacher
</span><span class="cx"> if queryCacher:
</span><span class="lines">@@ -1765,30 +1842,30 @@
</span><span class="cx"> return self._childClass.objectWithName(self, name)
</span><span class="cx">
</span><span class="cx">
</span><del>- def objectWithShareUID(self, shareUID):
</del><ins>+ def anyObjectWithShareUID(self, shareUID):
</ins><span class="cx"> """
</span><del>- Retrieve the child with the given bind identifier contained in this
</del><ins>+ Retrieve the child accepted or otherwise with the given bind identifier contained in this
</ins><span class="cx"> home.
</span><span class="cx">
</span><span class="cx"> @param name: a string.
</span><span class="cx"> @return: an L{ICalendar} or C{None} if no such child exists.
</span><span class="cx"> """
</span><del>- return self.childWithName(shareUID)
</del><ins>+ return self._childClass.objectWithName(self, shareUID, accepted=None)
</ins><span class="cx">
</span><span class="cx">
</span><del>- def invitedObjectWithShareUID(self, shareUID):
</del><ins>+ @memoizedKey("resourceID", "_children")
+ def childWithID(self, resourceID):
</ins><span class="cx"> """
</span><del>- Retrieve the child invitation with the given bind identifier contained in this
</del><ins>+ Retrieve the child with the given C{resourceID} contained in this
</ins><span class="cx"> home.
</span><span class="cx">
</span><span class="cx"> @param name: a string.
</span><span class="cx"> @return: an L{ICalendar} or C{None} if no such child exists.
</span><span class="cx"> """
</span><del>- return self._childClass.objectWithName(self, shareUID, accepted=False)
</del><ins>+ return self._childClass.objectWithID(self, resourceID)
</ins><span class="cx">
</span><span class="cx">
</span><del>- @memoizedKey("resourceID", "_children")
- def childWithID(self, resourceID):
</del><ins>+ def allChildWithID(self, resourceID):
</ins><span class="cx"> """
</span><span class="cx"> Retrieve the child with the given C{resourceID} contained in this
</span><span class="cx"> home.
</span><span class="lines">@@ -1796,7 +1873,7 @@
</span><span class="cx"> @param name: a string.
</span><span class="cx"> @return: an L{ICalendar} or C{None} if no such child exists.
</span><span class="cx"> """
</span><del>- return self._childClass.objectWithID(self, resourceID)
</del><ins>+ return self._childClass.objectWithID(self, resourceID, accepted=None)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="lines">@@ -2692,125 +2769,13 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><del>-class SharingInvitation(object):
- """
- SharingInvitation covers all the information needed to expose sharing invites to upper layers. Its primarily used to
- minimize the need to load full properties/data when only this subset of information is needed.
- """
- def __init__(self, uid, owner_uid, owner_rid, sharee_uid, sharee_rid, resource_id, resource_name, mode, status, summary):
- self._uid = uid
- self._owner_uid = owner_uid
- self._owner_rid = owner_rid
- self._sharee_uid = sharee_uid
- self._sharee_rid = sharee_rid
- self._resource_id = resource_id
- self._resource_name = resource_name
- self._mode = mode
- self._status = status
- self._summary = summary
</del><ins>+SharingInvitation = namedtuple(
+ "SharingInvitation",
+ ["uid", "ownerUID", "ownerHomeID", "shareeUID", "shareeHomeID", "mode", "status", "summary"]
+)
</ins><span class="cx">
</span><span class="cx">
</span><del>- @classmethod
- def fromCommonHomeChild(cls, homeChild):
- return cls(
- homeChild.shareUID(),
- homeChild.ownerHome().uid(),
- homeChild.ownerHome()._resourceID,
- homeChild.viewerHome().uid(),
- homeChild.viewerHome()._resourceID,
- homeChild._resourceID,
- homeChild.shareeName(),
- homeChild.shareMode(),
- homeChild.shareStatus(),
- homeChild.shareMessage(),
- )
</del><span class="cx">
</span><del>-
- def uid(self):
- """
- This maps to the resource name in the bind table, the "bind name". This is used as the "uid"
- for invites, and is not necessarily the name of the resource as it appears in the collection.
- """
- return self._uid
-
-
- def ownerUID(self):
- """
- The ownerUID of the sharer.
- """
- return self._owner_uid
-
-
- def ownerHomeID(self):
- """
- The resourceID of the sharer's L{CommonHome}.
- """
- return self._owner_rid
-
-
- def shareeUID(self):
- """
- The ownerUID of the sharee.
- """
- return self._sharee_uid
-
-
- def shareeHomeID(self):
- """
- The resourceID of the sharee's L{CommonHome}.
- """
- return self._sharee_rid
-
-
- def resourceID(self):
- """
- The resourceID of the shared object.
- """
- return self._resource_id
-
-
- def resourceName(self):
- """
- This maps to the name of the shared resource in the collection it is bound into. It is not necessarily the
- same as the "bind name" which is used as the "uid" for invites.
- """
- return self._resource_name
-
-
- def mode(self):
- """
- The sharing mode: one of the _BIND_MODE_XXX values.
- """
- return self._mode
-
-
- def setMode(self, mode):
- self._mode = mode
-
-
- def status(self):
- """
- The sharing status: one of the _BIND_STATUS_XXX values.
- """
- return self._status
-
-
- def setStatus(self, status):
- self._status = status
-
-
- def summary(self):
- """
- Message associated with the invitation.
- """
- return self._summary
-
-
- def setSummary(self, summary):
- self._summary = summary
-
-
-
</del><span class="cx"> class SharingMixIn(object):
</span><span class="cx"> """
</span><span class="cx"> Common class for CommonHomeChild and AddressBookObject
</span><span class="lines">@@ -2836,29 +2801,20 @@
</span><span class="cx"> @classmethod
</span><span class="cx"> def _updateBindColumnsQuery(cls, columnMap): #@NoSelf
</span><span class="cx"> bind = cls._bindSchema
</span><del>- return Update(columnMap,
- Where=(bind.RESOURCE_ID == Parameter("resourceID"))
- .And(bind.HOME_RESOURCE_ID == Parameter("homeID")),
- Return=bind.RESOURCE_NAME)
</del><ins>+ return Update(
+ columnMap,
+ Where=(bind.RESOURCE_ID == Parameter("resourceID"))
+ .And(bind.HOME_RESOURCE_ID == Parameter("homeID")),
+ )
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> @classproperty
</span><del>- def _updateBindQuery(cls): #@NoSelf
- bind = cls._bindSchema
- return cls._updateBindColumnsQuery(
- {bind.BIND_MODE: Parameter("mode"),
- bind.BIND_STATUS: Parameter("status"),
- bind.MESSAGE: Parameter("message")})
-
-
- @classproperty
</del><span class="cx"> def _deleteBindForResourceIDAndHomeID(cls): #@NoSelf
</span><span class="cx"> bind = cls._bindSchema
</span><span class="cx"> return Delete(
</span><span class="cx"> From=bind,
</span><span class="cx"> Where=(bind.RESOURCE_ID == Parameter("resourceID"))
</span><span class="cx"> .And(bind.HOME_RESOURCE_ID == Parameter("homeID")),
</span><del>- Return=bind.RESOURCE_NAME,
</del><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -2932,9 +2888,246 @@
</span><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><ins>+ #
+ # Higher level API
+ #
</ins><span class="cx"> @inlineCallbacks
</span><del>- def shareWith(self, shareeHome, mode, status=None, message=None):
</del><ins>+ def inviteUserToShare(self, shareeUID, mode, summary):
</ins><span class="cx"> """
</span><ins>+ Invite a user to share this collection - either create the share if it does not exist, or
+ update the existing share with new values. Make sure a notification is sent as well.
+
+ @param shareeUID: UID of the sharee
+ @type shareeUID: C{str}
+ @param mode: access mode
+ @type mode: C{int}
+ @param summary: share message
+ @type summary: C{str}
+ """
+
+ # Look for existing invite and update its fields or create new one
+ shareeView = yield self.shareeView(shareeUID)
+ if shareeView is not None:
+ status = _BIND_STATUS_INVITED if shareeView.shareStatus() in (_BIND_STATUS_DECLINED, _BIND_STATUS_INVALID) else None
+ yield self.updateShare(shareeView, mode=mode, status=status, summary=summary)
+ else:
+ shareeView = yield self.createShare(shareeUID=shareeUID, mode=mode, summary=summary)
+
+ # Send invite notification
+ yield self._sendInviteNotification(shareeView)
+ returnValue(shareeView)
+
+
+ @inlineCallbacks
+ def directShareWithUser(self, shareeUID):
+ """
+ Create a direct share with the specified user. Note it is currently up to the app layer
+ to enforce access control - this is not ideal as we really should have control of that in
+ the store. Once we do, this api will need to verify that access is allowed for a direct share.
+
+ NB no invitations are used with direct sharing.
+
+ @param shareeUID: UID of the sharee
+ @type shareeUID: C{str}
+ """
+
+ # Ignore if it already exists
+ shareeView = yield self.shareeView(shareeUID)
+ if shareeView is None:
+ shareeView = yield self.createShare(shareeUID=shareeUID, mode=_BIND_MODE_DIRECT)
+ yield shareeView.newShare()
+ returnValue(shareeView)
+
+
+ @inlineCallbacks
+ def uninviteUserFromShare(self, shareeUID):
+ """
+ Remove a user from a share. Make sure a notification is sent as well.
+
+ @param shareeUID: UID of the sharee
+ @type shareeUID: C{str}
+ """
+ # Cancel invites - we'll just use whatever userid we are given
+
+ shareeView = yield self.shareeView(shareeUID)
+ if shareeView is not None:
+ # If current user state is accepted then we send an invite with the new state, otherwise
+ # we cancel any existing invites for the user
+ if not shareeView.direct():
+ if shareeView.shareStatus() != _BIND_STATUS_ACCEPTED:
+ yield self._removeInviteNotification(shareeView)
+ else:
+ yield self._sendInviteNotification(shareeView, notificationState=_BIND_STATUS_DELETED)
+
+ # Remove the bind
+ yield self.removeShare(shareeView)
+
+
+ @inlineCallbacks
+ def acceptShare(self, summary=None):
+ """
+ This share is being accepted.
+ """
+
+ if not self.direct() and self.shareStatus() != _BIND_STATUS_ACCEPTED:
+ ownerView = yield self.ownerView()
+ yield ownerView.updateShare(self, status=_BIND_STATUS_ACCEPTED)
+ yield self.newShare(displayname=summary)
+ yield self._sendReplyNotification(ownerView, summary)
+
+
+ @inlineCallbacks
+ def declineShare(self):
+ """
+ This share is being declined.
+ """
+
+ if not self.direct() and self.shareStatus() != _BIND_STATUS_DECLINED:
+ ownerView = yield self.ownerView()
+ yield ownerView.updateShare(self, status=_BIND_STATUS_DECLINED)
+ yield self._sendReplyNotification(ownerView)
+
+
+ @inlineCallbacks
+ def deleteShare(self):
+ """
+ This share is being deleted - either decline or remove (for direct shares).
+ """
+
+ ownerView = yield self.ownerView()
+ if self.direct():
+ yield ownerView.removeShare(self)
+ else:
+ yield self.declineShare()
+
+
+ def newShare(self, displayname=None):
+ """
+ Override in derived classes to do any specific operations needed when a share
+ is first accepted.
+ """
+ return succeed(None)
+
+
+ @inlineCallbacks
+ def allInvitations(self):
+ """
+ Get list of all invitations (non-direct) to this object.
+ """
+ invitations = yield self.sharingInvites()
+
+ # remove direct shares as those are not "real" invitations
+ invitations = filter(lambda x: x.mode != _BIND_MODE_DIRECT, invitations)
+ invitations.sort(key=lambda invitation: invitation.shareeUID)
+ returnValue(invitations)
+
+
+ @inlineCallbacks
+ def _sendInviteNotification(self, shareeView, notificationState=None):
+ """
+ Called on the owner's resource.
+ """
+
+ # When deleting the message is the sharee's display name
+ displayname = shareeView.shareMessage()
+ if notificationState == _BIND_STATUS_DELETED:
+ displayname = str(shareeView.properties().get(PropertyName.fromElement(element.DisplayName), displayname))
+
+ notificationtype = {
+ "notification-type": "invite-notification",
+ "shared-type": shareeView.sharedResourceType(),
+ }
+ notificationdata = {
+ "notification-type": "invite-notification",
+ "shared-type": shareeView.sharedResourceType(),
+ "dtstamp": DateTime.getNowUTC().getText(),
+ "owner": shareeView.ownerHome().uid(),
+ "sharee": shareeView.viewerHome().uid(),
+ "uid": shareeView.shareUID(),
+ "status": shareeView.shareStatus() if notificationState is None else notificationState,
+ "access": shareeView.shareMode(),
+ "ownerName": self.shareName(),
+ "summary": displayname,
+ }
+ if hasattr(self, "getSupportedComponents"):
+ notificationdata["supported-components"] = self.getSupportedComponents()
+
+ # Add to sharee's collection
+ notifications = yield self._txn.notificationsWithUID(shareeView.viewerHome().uid())
+ yield notifications.writeNotificationObject(shareeView.shareUID(), notificationtype, notificationdata)
+
+
+ @inlineCallbacks
+ def _sendReplyNotification(self, ownerView, summary=None):
+ """
+ Create a reply notification based on the current state of this shared resource.
+ """
+
+ # Generate invite XML
+ notificationUID = "%s-reply" % (self.shareUID(),)
+
+ notificationtype = {
+ "notification-type": "invite-reply",
+ "shared-type": self.sharedResourceType(),
+ }
+
+ notificationdata = {
+ "notification-type": "invite-reply",
+ "shared-type": self.sharedResourceType(),
+ "dtstamp": DateTime.getNowUTC().getText(),
+ "owner": self.ownerHome().uid(),
+ "sharee": self.viewerHome().uid(),
+ "status": self.shareStatus(),
+ "ownerName": ownerView.shareName(),
+ "in-reply-to": self.shareUID(),
+ "summary": summary,
+ }
+
+ # Add to owner notification collection
+ notifications = yield self._txn.notificationsWithUID(self.ownerHome().uid())
+ yield notifications.writeNotificationObject(notificationUID, notificationtype, notificationdata)
+
+
+ @inlineCallbacks
+ def _removeInviteNotification(self, shareeView):
+ """
+ Called on the owner's resource.
+ """
+
+ # Remove from sharee's collection
+ notifications = yield self._txn.notificationsWithUID(shareeView.viewerHome().uid())
+ yield notifications.removeNotificationObjectWithUID(shareeView.shareUID())
+
+
+ #
+ # Lower level API
+ #
+
+ @inlineCallbacks
+ def ownerView(self):
+ """
+ Return the owner resource counterpart of this shared resource.
+ """
+ # Get the child of the owner home that has the same resource id as the owned one
+ ownerView = yield self.ownerHome().childWithID(self.id())
+ returnValue(ownerView)
+
+
+ @inlineCallbacks
+ def shareeView(self, shareeUID):
+ """
+ Return the shared resource counterpart of this owned resource for the specified sharee.
+ """
+
+ # Get the child of the sharee home that has the same resource id as the owned one
+ shareeHome = yield self._txn.homeWithUID(self._home._homeType, shareeUID)
+ shareeView = (yield shareeHome.allChildWithID(self.id())) if shareeHome is not None else None
+ returnValue(shareeView)
+
+
+ @inlineCallbacks
+ def shareWith(self, shareeHome, mode, status=None, summary=None):
+ """
</ins><span class="cx"> Share this (owned) L{CommonHomeChild} with another home.
</span><span class="cx">
</span><span class="cx"> @param shareeHome: The home of the sharee.
</span><span class="lines">@@ -2948,9 +3141,9 @@
</span><span class="cx"> L{_BIND_STATUS_ACCEPTED}
</span><span class="cx"> @type mode: L{str}
</span><span class="cx">
</span><del>- @param message: The proposed message to go along with the share, which
</del><ins>+ @param summary: The proposed message to go along with the share, which
</ins><span class="cx"> will be used as the default display name.
</span><del>- @type mode: L{str}
</del><ins>+ @type summary: L{str}
</ins><span class="cx">
</span><span class="cx"> @return: the name of the shared calendar in the new calendar home.
</span><span class="cx"> @rtype: L{str}
</span><span class="lines">@@ -2961,30 +3154,36 @@
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def doInsert(subt):
</span><del>- newName = str(uuid4())
</del><ins>+ newName = self.newShareName()
</ins><span class="cx"> yield self._bindInsertQuery.on(
</span><del>- subt, homeID=shareeHome._resourceID,
- resourceID=self._resourceID, name=newName,
- mode=mode, bindStatus=status, message=message
</del><ins>+ subt,
+ homeID=shareeHome._resourceID,
+ resourceID=self._resourceID,
+ name=newName,
+ mode=mode,
+ bindStatus=status,
+ message=summary
</ins><span class="cx"> )
</span><span class="cx"> returnValue(newName)
</span><span class="cx"> try:
</span><span class="cx"> bindName = yield self._txn.subtransaction(doInsert)
</span><span class="cx"> except AllRetriesFailed:
</span><span class="cx"> # FIXME: catch more specific exception
</span><del>- child = yield shareeHome.childWithID(self._resourceID)
- if not child:
- child = yield shareeHome.objectWithID(shareeHome, self._resourceID, accepted=False)
- bindName = yield self.updateShare(
</del><ins>+ child = yield shareeHome.allChildWithID(self._resourceID)
+ yield self.updateShare(
</ins><span class="cx"> child, mode=mode, status=status,
</span><del>- message=message
</del><ins>+ summary=summary
</ins><span class="cx"> )
</span><ins>+ bindName = child._name
</ins><span class="cx"> else:
</span><span class="cx"> if status == _BIND_STATUS_ACCEPTED:
</span><del>- shareeView = yield shareeHome.objectWithShareUID(bindName)
</del><ins>+ shareeView = yield shareeHome.anyObjectWithShareUID(bindName)
</ins><span class="cx"> yield shareeView._initSyncToken()
</span><span class="cx"> yield shareeView._initBindRevision()
</span><span class="cx">
</span><ins>+ # Mark this as shared
+ yield self.setShared(True)
+
</ins><span class="cx"> # Must send notification to ensure cache invalidation occurs
</span><span class="cx"> yield self.notifyPropertyChanged()
</span><span class="cx"> yield shareeHome.notifyChanged()
</span><span class="lines">@@ -2993,25 +3192,25 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def updateShareFromSharingInvitation(self, invitation, mode=None, status=None, message=None):
</del><ins>+ def createShare(self, shareeUID, mode, summary=None):
</ins><span class="cx"> """
</span><del>- Like L{updateShare} except that the original invitation is provided. That is used
- to find the actual sharee L{CommonHomeChild} which is then passed to L{updateShare}.
</del><ins>+ Create a new shared resource. If the mode is direct, the share is created in accepted state,
+ otherwise the share is created in invited state.
</ins><span class="cx"> """
</span><ins>+ shareeHome = yield self._txn.homeWithUID(self.ownerHome()._homeType, shareeUID, create=True)
</ins><span class="cx">
</span><del>- # Look up the shared child - might be accepted or not. If accepted use the resource name
- # to look it up, else use the invitation uid (bind name)
- shareeHome = yield self._txn.homeWithUID(self._home._homeType, invitation.shareeUID())
- shareeView = yield shareeHome.childWithName(invitation.resourceName())
- if shareeView is None:
- shareeView = yield shareeHome.invitedObjectWithShareUID(invitation.uid())
</del><ins>+ yield self.shareWith(
+ shareeHome,
+ mode=mode,
+ status=_BIND_STATUS_INVITED if mode != _BIND_MODE_DIRECT else _BIND_STATUS_ACCEPTED,
+ summary=summary,
+ )
+ shareeView = yield self.shareeView(shareeUID)
+ returnValue(shareeView)
</ins><span class="cx">
</span><del>- result = yield self.updateShare(shareeView, mode, status, message)
- returnValue(result)
</del><span class="cx">
</span><del>-
</del><span class="cx"> @inlineCallbacks
</span><del>- def updateShare(self, shareeView, mode=None, status=None, message=None):
</del><ins>+ def updateShare(self, shareeView, mode=None, status=None, summary=None):
</ins><span class="cx"> """
</span><span class="cx"> Update share mode, status, and message for a home child shared with
</span><span class="cx"> this (owned) L{CommonHomeChild}.
</span><span class="lines">@@ -3028,9 +3227,9 @@
</span><span class="cx"> L{_BIND_STATUS_INVALID} or None to not update
</span><span class="cx"> @type status: L{str}
</span><span class="cx">
</span><del>- @param message: The proposed message to go along with the share, which
</del><ins>+ @param summary: The proposed message to go along with the share, which
</ins><span class="cx"> will be used as the default display name, or None to not update
</span><del>- @type message: L{str}
</del><ins>+ @type summary: L{str}
</ins><span class="cx">
</span><span class="cx"> @return: the name of the shared item in the sharee's home.
</span><span class="cx"> @rtype: a L{Deferred} which fires with a L{str}
</span><span class="lines">@@ -3040,35 +3239,32 @@
</span><span class="cx">
</span><span class="cx"> #remove None parameters, and substitute None for empty string
</span><span class="cx"> bind = self._bindSchema
</span><del>- columnMap = dict([(k, v if v != "" else None)
- for k, v in {bind.BIND_MODE:mode,
- bind.BIND_STATUS:status,
- bind.MESSAGE:message}.iteritems() if v is not None])
</del><ins>+ columnMap = dict([(k, v if v != "" else None) for k, v in {
+ bind.BIND_MODE:mode,
+ bind.BIND_STATUS:status,
+ bind.MESSAGE:summary
+ }.iteritems() if v is not None])
</ins><span class="cx">
</span><span class="cx"> if len(columnMap):
</span><span class="cx">
</span><del>- sharedname = yield self._updateBindColumnsQuery(columnMap).on(
- self._txn,
- resourceID=self._resourceID, homeID=shareeView._home._resourceID
- )
</del><ins>+ # Count accepted
+ if status is not None:
+ previouslyAcceptedCount = yield shareeView._previousAcceptCount()
</ins><span class="cx">
</span><del>- #update affected attributes
</del><ins>+ yield self._updateBindColumnsQuery(columnMap).on(
+ self._txn,
+ resourceID=self._resourceID, homeID=shareeView._home._resourceID
+ )
+
+ # Update affected attributes
</ins><span class="cx"> if mode is not None:
</span><span class="cx"> shareeView._bindMode = columnMap[bind.BIND_MODE]
</span><span class="cx">
</span><span class="cx"> if status is not None:
</span><span class="cx"> shareeView._bindStatus = columnMap[bind.BIND_STATUS]
</span><del>- if shareeView._bindStatus == _BIND_STATUS_ACCEPTED:
- yield shareeView._initSyncToken()
- yield shareeView._initBindRevision()
- shareeView._home._children[shareeView._name] = shareeView
- shareeView._home._children[shareeView._resourceID] = shareeView
- elif shareeView._bindStatus == _BIND_STATUS_DECLINED:
- yield shareeView._deletedSyncToken(sharedRemoval=True)
- shareeView._home._children.pop(shareeView._name, None)
- shareeView._home._children.pop(shareeView._resourceID, None)
</del><ins>+ yield shareeView._changedStatus(previouslyAcceptedCount)
</ins><span class="cx">
</span><del>- if message is not None:
</del><ins>+ if summary is not None:
</ins><span class="cx"> shareeView._bindMessage = columnMap[bind.MESSAGE]
</span><span class="cx">
</span><span class="cx"> queryCacher = self._txn._queryCacher
</span><span class="lines">@@ -3078,71 +3274,66 @@
</span><span class="cx"> cacheKey = queryCacher.keyForObjectWithResourceID(shareeView._home._resourceID, shareeView._resourceID)
</span><span class="cx"> yield queryCacher.invalidateAfterCommit(self._txn, cacheKey)
</span><span class="cx">
</span><del>- shareeView._name = sharedname[0][0]
-
</del><span class="cx"> # Must send notification to ensure cache invalidation occurs
</span><span class="cx"> yield self.notifyPropertyChanged()
</span><span class="cx"> yield shareeView.viewerHome().notifyChanged()
</span><span class="cx">
</span><del>- returnValue(shareeView._name)
</del><span class="cx">
</span><ins>+ def _previousAcceptCount(self):
+ return succeed(1)
</ins><span class="cx">
</span><ins>+
</ins><span class="cx"> @inlineCallbacks
</span><del>- def unshareWithUID(self, shareeUID):
- """
- Like L{unshareWith} except this is passed a sharee UID which is then used to lookup the
- L{CommonHome} for the sharee to pass to L{unshareWith}.
- """
</del><ins>+ def _changedStatus(self, previouslyAcceptedCount):
+ if self._bindStatus == _BIND_STATUS_ACCEPTED:
+ yield self._initSyncToken()
+ yield self._initBindRevision()
+ self._home._children[self._name] = self
+ self._home._children[self._resourceID] = self
+ elif self._bindStatus in (_BIND_STATUS_INVITED, _BIND_STATUS_DECLINED):
+ yield self._deletedSyncToken(sharedRemoval=True)
+ self._home._children.pop(self._name, None)
+ self._home._children.pop(self._resourceID, None)
</ins><span class="cx">
</span><del>- shareeHome = yield self._txn.homeWithUID(self._home._homeType, shareeUID)
- result = yield self.unshareWith(shareeHome)
- returnValue(result)
</del><span class="cx">
</span><del>-
</del><span class="cx"> @inlineCallbacks
</span><del>- def unshareWith(self, shareeHome):
</del><ins>+ def removeShare(self, shareeView):
</ins><span class="cx"> """
</span><span class="cx"> Remove the shared version of this (owned) L{CommonHomeChild} from the
</span><span class="cx"> referenced L{CommonHome}.
</span><span class="cx">
</span><span class="cx"> @see: L{CommonHomeChild.shareWith}
</span><span class="cx">
</span><del>- @param shareeHome: The home with which this L{CommonHomeChild} was
- previously shared.
</del><ins>+ @param shareeView: The shared resource being removed.
</ins><span class="cx">
</span><span class="cx"> @return: a L{Deferred} which will fire with the previous shareUID
</span><span class="cx"> """
</span><del>- #remove sync tokens
- shareeChildren = yield shareeHome.children()
- for shareeChild in shareeChildren:
- if not shareeChild.owned() and shareeChild._resourceID == self._resourceID:
- yield shareeChild._deletedSyncToken(sharedRemoval=True)
- shareeHome._children.pop(shareeChild._name, None)
- shareeHome._children.pop(shareeChild._resourceID, None)
</del><span class="cx">
</span><del>- # Must send notification to ensure cache invalidation occurs
- yield self.notifyPropertyChanged()
- yield shareeHome.notifyChanged()
- break
</del><ins>+ # remove sync tokens
+ shareeHome = shareeView.viewerHome()
+ yield shareeView._deletedSyncToken(sharedRemoval=True)
+ shareeHome._children.pop(shareeView._name, None)
+ shareeHome._children.pop(shareeView._resourceID, None)
</ins><span class="cx">
</span><ins>+ # Must send notification to ensure cache invalidation occurs
+ yield self.notifyPropertyChanged()
+ yield shareeHome.notifyChanged()
+
</ins><span class="cx"> # delete binds including invites
</span><del>- deletedBindNameRows = yield self._deleteBindForResourceIDAndHomeID.on(self._txn, resourceID=self._resourceID,
- homeID=shareeHome._resourceID)
</del><ins>+ yield self._deleteBindForResourceIDAndHomeID.on(
+ self._txn,
+ resourceID=self._resourceID,
+ homeID=shareeHome._resourceID,
+ )
</ins><span class="cx">
</span><del>- if deletedBindNameRows:
- deletedBindName = deletedBindNameRows[0][0]
- queryCacher = self._txn._queryCacher
- if queryCacher:
- cacheKey = queryCacher.keyForObjectWithName(shareeHome._resourceID, shareeChild._name)
- yield queryCacher.invalidateAfterCommit(self._txn, cacheKey)
- cacheKey = queryCacher.keyForObjectWithResourceID(shareeHome._resourceID, shareeChild._resourceID)
- yield queryCacher.invalidateAfterCommit(self._txn, cacheKey)
- else:
- deletedBindName = None
</del><ins>+ queryCacher = self._txn._queryCacher
+ if queryCacher:
+ cacheKey = queryCacher.keyForObjectWithName(shareeHome._resourceID, shareeView._name)
+ yield queryCacher.invalidateAfterCommit(self._txn, cacheKey)
+ cacheKey = queryCacher.keyForObjectWithResourceID(shareeHome._resourceID, shareeView._resourceID)
+ yield queryCacher.invalidateAfterCommit(self._txn, cacheKey)
</ins><span class="cx">
</span><del>- returnValue(deletedBindName)
</del><span class="cx">
</span><del>-
</del><span class="cx"> @inlineCallbacks
</span><span class="cx"> def unshare(self):
</span><span class="cx"> """
</span><span class="lines">@@ -3152,12 +3343,12 @@
</span><span class="cx"> # This collection may be shared to others
</span><span class="cx"> invites = yield self.sharingInvites()
</span><span class="cx"> for invite in invites:
</span><del>- shareeHome = (yield self._txn.homeWithResourceID(self._home._homeType, invite.shareeHomeID()))
- (yield self.unshareWith(shareeHome))
</del><ins>+ shareeView = yield self.shareeView(invite.shareeUID)
+ yield self.removeShare(shareeView)
</ins><span class="cx"> else:
</span><span class="cx"> # This collection is shared to me
</span><del>- ownerHomeChild = yield self.ownerHome().childWithID(self._resourceID)
- yield ownerHomeChild.unshareWith(self._home)
</del><ins>+ ownerView = yield self.ownerView()
+ yield ownerView.removeShare(self)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="lines">@@ -3180,12 +3371,10 @@
</span><span class="cx"> for homeUID, homeRID, resourceID, resourceName, bindMode, bindStatus, bindMessage in acceptedRows: #@UnusedVariable
</span><span class="cx"> invite = SharingInvitation(
</span><span class="cx"> resourceName,
</span><del>- self._home.name(),
- self._home._resourceID,
</del><ins>+ self.ownerHome().name(),
+ self.ownerHome().id(),
</ins><span class="cx"> homeUID,
</span><span class="cx"> homeRID,
</span><del>- resourceID,
- resourceName if self.bindNameIsResourceName() else self.shareeName(),
</del><span class="cx"> bindMode,
</span><span class="cx"> bindStatus,
</span><span class="cx"> bindMessage,
</span><span class="lines">@@ -3200,7 +3389,8 @@
</span><span class="cx">
</span><span class="cx"> bind = self._bindSchema
</span><span class="cx"> yield self._updateBindColumnsQuery(
</span><del>- {bind.BIND_REVISION : Parameter("revision"), }).on(
</del><ins>+ {bind.BIND_REVISION : Parameter("revision"), }
+ ).on(
</ins><span class="cx"> self._txn,
</span><span class="cx"> revision=self._bindRevision,
</span><span class="cx"> resourceID=self._resourceID,
</span><span class="lines">@@ -3209,13 +3399,23 @@
</span><span class="cx"> yield self.invalidateQueryCache()
</span><span class="cx">
</span><span class="cx">
</span><del>- def shareMode(self):
</del><ins>+ def sharedResourceType(self):
</ins><span class="cx"> """
</span><del>- @see: L{ICalendar.shareMode}
</del><ins>+ The sharing resource type. Needs to be overridden by each type of resource that can be shared.
+
+ @return: an identifier for the type of the share.
+ @rtype: C{str}
</ins><span class="cx"> """
</span><del>- return self._bindMode
</del><ins>+ return ""
</ins><span class="cx">
</span><span class="cx">
</span><ins>+ def newShareName(self):
+ """
+ Name used when creating a new share. By default this is a UUID.
+ """
+ return str(uuid4())
+
+
</ins><span class="cx"> def owned(self):
</span><span class="cx"> """
</span><span class="cx"> @see: L{ICalendar.owned}
</span><span class="lines">@@ -3246,8 +3446,13 @@
</span><span class="cx"> """
</span><span class="cx"> assert self.owned()
</span><span class="cx">
</span><del>- self._bindMessage = "shared" if shared else None
</del><ins>+ # Only if change is needed
+ newMessage = "shared" if shared else None
+ if self._bindMessage == newMessage:
+ returnValue(None)
</ins><span class="cx">
</span><ins>+ self._bindMessage = newMessage
+
</ins><span class="cx"> bind = self._bindSchema
</span><span class="cx"> yield Update(
</span><span class="cx"> {bind.MESSAGE: self._bindMessage},
</span><span class="lines">@@ -3259,20 +3464,51 @@
</span><span class="cx"> yield self.notifyPropertyChanged()
</span><span class="cx">
</span><span class="cx">
</span><del>- def shareeName(self):
</del><ins>+ def direct(self):
</ins><span class="cx"> """
</span><del>- The sharee's name for a shared L{CommonHomeChild} is the name of the resource by default.
</del><ins>+ Is this a "direct" share?
+
+ @return: a boolean indicating whether it's direct.
</ins><span class="cx"> """
</span><ins>+ return self._bindMode == _BIND_MODE_DIRECT
+
+
+ def indirect(self):
+ """
+ Is this an "indirect" share?
+
+ @return: a boolean indicating whether it's indirect.
+ """
+ return self._bindMode == _BIND_MODE_INDIRECT
+
+
+ def shareUID(self):
+ """
+ @see: L{ICalendar.shareUID}
+ """
</ins><span class="cx"> return self.name()
</span><span class="cx">
</span><span class="cx">
</span><del>- def bindNameIsResourceName(self):
</del><ins>+ def shareMode(self):
</ins><span class="cx"> """
</span><del>- By default, the shared resource name of an accepted share is the same as the name in the bind table.
</del><ins>+ @see: L{ICalendar.shareMode}
</ins><span class="cx"> """
</span><del>- return True
</del><ins>+ return self._bindMode
</ins><span class="cx">
</span><span class="cx">
</span><ins>+ def shareName(self):
+ """
+ This is a path like name for the resource within the home being shared. For object resource
+ shares this will be a combination of the L{CommonHomeChild} name and the L{CommonObjecrResource}
+ name. Otherwise it is just the L{CommonHomeChild} name. This is needed to expose a value to the
+ app-layer such that it can construct a URI for the actual WebDAV resource being shared.
+ """
+ name = self.name()
+ if self.sharedResourceType() == "group":
+ name = self.parentCollection().name() + "/" + name
+ return name
+
+
</ins><span class="cx"> def shareStatus(self):
</span><span class="cx"> """
</span><span class="cx"> @see: L{ICalendar.shareStatus}
</span><span class="lines">@@ -3280,18 +3516,18 @@
</span><span class="cx"> return self._bindStatus
</span><span class="cx">
</span><span class="cx">
</span><del>- def shareMessage(self):
</del><ins>+ def accepted(self):
</ins><span class="cx"> """
</span><del>- @see: L{ICalendar.shareMessage}
</del><ins>+ @see: L{ICalendar.shareStatus}
</ins><span class="cx"> """
</span><del>- return self._bindMessage
</del><ins>+ return self._bindStatus == _BIND_STATUS_ACCEPTED
</ins><span class="cx">
</span><span class="cx">
</span><del>- def shareUID(self):
</del><ins>+ def shareMessage(self):
</ins><span class="cx"> """
</span><del>- @see: L{ICalendar.shareUID}
</del><ins>+ @see: L{ICalendar.shareMessage}
</ins><span class="cx"> """
</span><del>- return self.name()
</del><ins>+ return self._bindMessage
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> @classmethod
</span><span class="lines">@@ -3481,7 +3717,7 @@
</span><span class="cx"> """
</span><span class="cx"> # FIXME: tests don't cover this as directly as they should.
</span><span class="cx"> rows = yield cls._acceptedBindForHomeID.on(
</span><del>- home._txn, homeID=home._resourceID
</del><ins>+ home._txn, homeID=home._resourceID
</ins><span class="cx"> )
</span><span class="cx"> names = [row[3] for row in rows]
</span><span class="cx"> returnValue(names)
</span><span class="lines">@@ -3529,10 +3765,13 @@
</span><span class="cx">
</span><span class="cx"> child = cls(
</span><span class="cx"> home=home,
</span><del>- name=bindName, resourceID=resourceID,
- mode=bindMode, status=bindStatus,
</del><ins>+ name=bindName,
+ resourceID=resourceID,
+ mode=bindMode,
+ status=bindStatus,
</ins><span class="cx"> revision=bindRevision,
</span><del>- message=bindMessage, ownerHome=ownerHome,
</del><ins>+ message=bindMessage,
+ ownerHome=ownerHome,
</ins><span class="cx"> ownerName=ownerName,
</span><span class="cx"> )
</span><span class="cx"> for attr, value in zip(cls.additionalBindAttributes(), additionalBind):
</span><span class="lines">@@ -3551,11 +3790,21 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @classmethod
</span><ins>+ def objectWithName(cls, home, name, accepted=True):
+ return cls._objectWithNameOrID(home, name=name, accepted=accepted)
+
+
+ @classmethod
+ def objectWithID(cls, home, resourceID, accepted=True):
+ return cls._objectWithNameOrID(home, resourceID=resourceID, accepted=accepted)
+
+
+ @classmethod
</ins><span class="cx"> @inlineCallbacks
</span><del>- def objectWithName(cls, home, name, accepted=True):
</del><ins>+ def _objectWithNameOrID(cls, home, name=None, resourceID=None, accepted=True):
</ins><span class="cx"> # replaces objectWithName()
</span><span class="cx"> """
</span><del>- Retrieve the child with the given C{name} contained in the given
</del><ins>+ Retrieve the child with the given C{name} or C{resourceID} contained in the given
</ins><span class="cx"> C{home}.
</span><span class="cx">
</span><span class="cx"> @param home: a L{CommonHome}.
</span><span class="lines">@@ -3570,97 +3819,65 @@
</span><span class="cx">
</span><span class="cx"> if queryCacher:
</span><span class="cx"> # Retrieve data from cache
</span><del>- cacheKey = queryCacher.keyForObjectWithName(home._resourceID, name)
</del><ins>+ if name:
+ cacheKey = queryCacher.keyForObjectWithName(home._resourceID, name)
+ else:
+ cacheKey = queryCacher.keyForObjectWithResourceID(home._resourceID, resourceID)
</ins><span class="cx"> rows = yield queryCacher.get(cacheKey)
</span><span class="cx">
</span><span class="cx"> if rows is None:
</span><span class="cx"> # No cached copy
</span><del>- rows = yield cls._bindForNameAndHomeID.on(home._txn, name=name, homeID=home._resourceID)
</del><ins>+ if name:
+ rows = yield cls._bindForNameAndHomeID.on(home._txn, name=name, homeID=home._resourceID)
+ else:
+ rows = yield cls._bindForResourceIDAndHomeID.on(home._txn, resourceID=resourceID, homeID=home._resourceID)
</ins><span class="cx">
</span><del>- if rows and queryCacher:
- # Cache the result
- queryCacher.setAfterCommit(home._txn, cacheKey, rows)
- queryCacher.setAfterCommit(home._txn, queryCacher.keyForObjectWithResourceID(home._resourceID, rows[0][2]), rows)
-
</del><span class="cx"> if not rows:
</span><span class="cx"> returnValue(None)
</span><span class="cx">
</span><span class="cx"> row = rows[0]
</span><del>- bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = row[:cls.bindColumnCount] #@UnusedVariable
- if (bindStatus == _BIND_STATUS_ACCEPTED) != bool(accepted):
</del><ins>+ bindMode, homeID, resourceID, name, bindStatus, bindRevision, bindMessage = row[:cls.bindColumnCount] #@UnusedVariable
+
+ if queryCacher:
+ # Cache the result
+ queryCacher.setAfterCommit(home._txn, queryCacher.keyForObjectWithName(home._resourceID, name), rows)
+ queryCacher.setAfterCommit(home._txn, queryCacher.keyForObjectWithResourceID(home._resourceID, resourceID), rows)
+
+ if accepted is not None and (bindStatus == _BIND_STATUS_ACCEPTED) != bool(accepted):
</ins><span class="cx"> returnValue(None)
</span><span class="cx"> additionalBind = row[cls.bindColumnCount:cls.bindColumnCount + len(cls.additionalBindColumns())]
</span><span class="cx">
</span><span class="cx"> if bindMode == _BIND_MODE_OWN:
</span><span class="cx"> ownerHome = home
</span><del>- ownerName = bindName
</del><ins>+ ownerName = name
</ins><span class="cx"> else:
</span><span class="cx"> ownerHome, ownerName = yield home.ownerHomeAndChildNameForChildID(resourceID)
</span><span class="cx">
</span><span class="cx"> child = cls(
</span><span class="cx"> home=home,
</span><del>- name=name, resourceID=resourceID,
- mode=bindMode, status=bindStatus,
</del><ins>+ name=name,
+ resourceID=resourceID,
+ mode=bindMode,
+ status=bindStatus,
</ins><span class="cx"> revision=bindRevision,
</span><del>- message=bindMessage, ownerHome=ownerHome,
</del><ins>+ message=bindMessage,
+ ownerHome=ownerHome,
</ins><span class="cx"> ownerName=ownerName
</span><span class="cx"> )
</span><span class="cx"> yield child.initFromStore(additionalBind)
</span><span class="cx"> returnValue(child)
</span><span class="cx">
</span><span class="cx">
</span><del>- @classmethod
- @inlineCallbacks
- def objectWithID(cls, home, resourceID, accepted=True):
- """
- Retrieve the child with the given C{resourceID} contained in the given
- C{home}.
-
- @param home: a L{CommonHome}.
- @param resourceID: a string.
- @return: an L{CommonHomeChild} or C{None} if no such child
- exists.
- """
-
- rows = None
- queryCacher = home._txn._queryCacher
-
- if queryCacher:
- # Retrieve data from cache
- cacheKey = queryCacher.keyForObjectWithResourceID(home._resourceID, resourceID)
- rows = yield queryCacher.get(cacheKey)
-
- if rows is None:
- # No cached copy
- rows = yield cls._bindForResourceIDAndHomeID.on(home._txn, resourceID=resourceID, homeID=home._resourceID)
-
- if rows and queryCacher:
- # Cache the result (under both the ID and name values)
- queryCacher.setAfterCommit(home._txn, cacheKey, rows)
- queryCacher.setAfterCommit(home._txn, queryCacher.keyForObjectWithName(home._resourceID, rows[0][3]), rows)
-
- if not rows:
- returnValue(None)
-
- row = rows[0]
- bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = row[:cls.bindColumnCount] #@UnusedVariable]
- if (bindStatus == _BIND_STATUS_ACCEPTED) != bool(accepted):
- returnValue(None)
-
- if accepted:
- returnValue((yield home.objectWithShareUID(bindName)))
- else:
- returnValue((yield home.invitedObjectWithShareUID(bindName)))
-
-
</del><span class="cx"> @classproperty
</span><span class="cx"> def _insertHomeChild(cls): #@NoSelf
</span><span class="cx"> """
</span><span class="cx"> DAL statement to create a home child with all default values.
</span><span class="cx"> """
</span><span class="cx"> child = cls._homeChildSchema
</span><del>- return Insert({child.RESOURCE_ID: schema.RESOURCE_ID_SEQ},
- Return=(child.RESOURCE_ID))
</del><ins>+ return Insert(
+ {child.RESOURCE_ID: schema.RESOURCE_ID_SEQ},
+ Return=(child.RESOURCE_ID)
+ )
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> @classproperty
</span><span class="lines">@@ -3740,9 +3957,7 @@
</span><span class="cx"> dataRows = None
</span><span class="cx"> if dataRows is None:
</span><span class="cx"> # No cached copy
</span><del>- dataRows = (
- yield self._metadataByIDQuery.on(self._txn,
- resourceID=self._resourceID))[0]
</del><ins>+ dataRows = (yield self._metadataByIDQuery.on(self._txn, resourceID=self._resourceID))[0]
</ins><span class="cx"> if queryCacher:
</span><span class="cx"> # Cache the results
</span><span class="cx"> yield queryCacher.setAfterCommit(self._txn, cacheKey, dataRows)
</span><span class="lines">@@ -4313,8 +4528,7 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def _notifyChanged(self, property_change=False,
- category=ChangeCategory.default):
</del><ins>+ def _notifyChanged(self, property_change=False, category=ChangeCategory.default):
</ins><span class="cx"> """
</span><span class="cx"> Send notifications, change sync token and bump last modified because
</span><span class="cx"> the resource has changed. We ensure we only do this once per object
</span><span class="lines">@@ -4424,7 +4638,7 @@
</span><span class="cx"> self._size = None
</span><span class="cx"> self._created = None
</span><span class="cx"> self._modified = None
</span><del>- self._objectText = None
</del><ins>+ self._notificationData = None
</ins><span class="cx">
</span><span class="cx"> self._locked = False
</span><span class="cx">
</span><span class="lines">@@ -4748,6 +4962,18 @@
</span><span class="cx"> return self._parentCollection
</span><span class="cx">
</span><span class="cx">
</span><ins>+ def owned(self):
+ return self._parentCollection.owned()
+
+
+ def ownerHome(self):
+ return self._parentCollection.ownerHome()
+
+
+ def viewerHome(self):
+ return self._parentCollection.viewerHome()
+
+
</ins><span class="cx"> @classmethod
</span><span class="cx"> def _selectForUpdateQuery(cls, nowait): #@NoSelf
</span><span class="cx"> """
</span><span class="lines">@@ -4835,7 +5061,7 @@
</span><span class="cx"> self._size = None
</span><span class="cx"> self._created = None
</span><span class="cx"> self._modified = None
</span><del>- self._objectText = None
</del><ins>+ self._notificationData = None
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def uid(self):
</span><span class="lines">@@ -4879,19 +5105,19 @@
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def _text(self):
</span><del>- if self._objectText is None:
</del><ins>+ if self._notificationData is None:
</ins><span class="cx"> texts = (
</span><span class="cx"> yield self._textByIDQuery.on(self._txn,
</span><span class="cx"> resourceID=self._resourceID)
</span><span class="cx"> )
</span><span class="cx"> if texts:
</span><span class="cx"> text = texts[0][0]
</span><del>- self._objectText = text
</del><ins>+ self._notificationData = text
</ins><span class="cx"> returnValue(text)
</span><span class="cx"> else:
</span><span class="cx"> raise ConcurrentModification()
</span><span class="cx"> else:
</span><del>- returnValue(self._objectText)
</del><ins>+ returnValue(self._notificationData)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -4914,6 +5140,7 @@
</span><span class="cx"> self._txn = txn
</span><span class="cx"> self._uid = uid
</span><span class="cx"> self._resourceID = resourceID
</span><ins>+ self._dataVersion = None
</ins><span class="cx"> self._notifications = {}
</span><span class="cx"> self._notificationNames = None
</span><span class="cx"> self._syncTokenRevision = None
</span><span class="lines">@@ -4926,6 +5153,10 @@
</span><span class="cx"> [_homeSchema.RESOURCE_ID], From=_homeSchema,
</span><span class="cx"> Where=_homeSchema.OWNER_UID == Parameter("uid"))
</span><span class="cx">
</span><ins>+ _UIDFromResourceIDQuery = Select(
+ [_homeSchema.OWNER_UID], From=_homeSchema,
+ Where=_homeSchema.RESOURCE_ID == Parameter("rid"))
+
</ins><span class="cx"> _provisionNewNotificationsQuery = Insert(
</span><span class="cx"> {_homeSchema.OWNER_UID: Parameter("uid")},
</span><span class="cx"> Return=_homeSchema.RESOURCE_ID
</span><span class="lines">@@ -4984,7 +5215,20 @@
</span><span class="cx"> returnValue(collection)
</span><span class="cx">
</span><span class="cx">
</span><ins>+ @classmethod
</ins><span class="cx"> @inlineCallbacks
</span><ins>+ def notificationsWithResourceID(cls, txn, rid):
+ rows = yield cls._UIDFromResourceIDQuery.on(txn, rid=rid)
+
+ if rows:
+ uid = rows[0][0]
+ result = (yield cls.notificationsWithUID(txn, uid, create=False))
+ returnValue(result)
+ else:
+ returnValue(None)
+
+
+ @inlineCallbacks
</ins><span class="cx"> def _loadPropertyStore(self):
</span><span class="cx"> self._propertyStore = yield PropertyStore.load(
</span><span class="cx"> self._uid,
</span><span class="lines">@@ -5009,6 +5253,23 @@
</span><span class="cx"> return self._resourceID
</span><span class="cx">
</span><span class="cx">
</span><ins>+ @classproperty
+ def _dataVersionQuery(cls): #@NoSelf
+ nh = cls._homeSchema
+ return Select(
+ [nh.DATAVERSION], From=nh,
+ Where=nh.RESOURCE_ID == Parameter("resourceID")
+ )
+
+
+ @inlineCallbacks
+ def dataVersion(self):
+ if self._dataVersion is None:
+ self._dataVersion = (yield self._dataVersionQuery.on(
+ self._txn, resourceID=self._resourceID))[0][0]
+ returnValue(self._dataVersion)
+
+
</ins><span class="cx"> def name(self):
</span><span class="cx"> return "notification"
</span><span class="cx">
</span><span class="lines">@@ -5077,22 +5338,26 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def writeNotificationObject(self, uid, xmltype, xmldata):
</del><ins>+ def writeNotificationObject(self, uid, notificationtype, notificationdata):
</ins><span class="cx">
</span><span class="cx"> inserting = False
</span><span class="cx"> notificationObject = yield self.notificationObjectWithUID(uid)
</span><span class="cx"> if notificationObject is None:
</span><span class="cx"> notificationObject = NotificationObject(self, uid)
</span><span class="cx"> inserting = True
</span><del>- yield notificationObject.setData(uid, xmltype, xmldata, inserting=inserting)
</del><ins>+ yield notificationObject.setData(uid, notificationtype, notificationdata, inserting=inserting)
</ins><span class="cx"> if inserting:
</span><span class="cx"> yield self._insertRevision("%s.xml" % (uid,))
</span><ins>+ if self._notificationNames is not None:
+ self._notificationNames.append(notificationObject.uid())
</ins><span class="cx"> else:
</span><span class="cx"> yield self._updateRevision("%s.xml" % (uid,))
</span><span class="cx"> yield self.notifyChanged()
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def removeNotificationObjectWithName(self, name):
</span><ins>+ if self._notificationNames is not None:
+ self._notificationNames.remove(self._nameToUID(name))
</ins><span class="cx"> return self.removeNotificationObjectWithUID(self._nameToUID(name))
</span><span class="cx">
</span><span class="cx"> _removeByUIDQuery = Delete(
</span><span class="lines">@@ -5233,6 +5498,11 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> class NotificationObject(FancyEqMixin, object):
</span><ins>+ """
+ This used to store XML data and an XML element for the type. But we are now switching it
+ to use JSON internally. The app layer will convert that to XML and fill in the "blanks" as
+ needed for the app.
+ """
</ins><span class="cx"> log = Logger()
</span><span class="cx">
</span><span class="cx"> implements(INotificationObject)
</span><span class="lines">@@ -5252,8 +5522,8 @@
</span><span class="cx"> self._size = None
</span><span class="cx"> self._created = None
</span><span class="cx"> self._modified = None
</span><del>- self._xmlType = None
- self._objectText = None
</del><ins>+ self._notificationType = None
+ self._notificationData = None
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def __repr__(self):
</span><span class="lines">@@ -5266,12 +5536,12 @@
</span><span class="cx"> DAL query to load all columns by home ID.
</span><span class="cx"> """
</span><span class="cx"> obj = cls._objectSchema
</span><del>- return Select([obj.RESOURCE_ID, obj.NOTIFICATION_UID, obj.MD5,
- Len(obj.XML_DATA), obj.XML_TYPE, obj.CREATED,
- obj.MODIFIED],
- From=obj,
- Where=(obj.NOTIFICATION_HOME_RESOURCE_ID == Parameter(
- "homeID")))
</del><ins>+ return Select(
+ [obj.RESOURCE_ID, obj.NOTIFICATION_UID, obj.MD5,
+ Len(obj.NOTIFICATION_DATA), obj.NOTIFICATION_TYPE, obj.CREATED, obj.MODIFIED],
+ From=obj,
+ Where=(obj.NOTIFICATION_HOME_RESOURCE_ID == Parameter("homeID"))
+ )
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> @classmethod
</span><span class="lines">@@ -5308,9 +5578,13 @@
</span><span class="cx"> child._uid,
</span><span class="cx"> child._md5,
</span><span class="cx"> child._size,
</span><del>- child._xmlType,
</del><ins>+ child._notificationType,
</ins><span class="cx"> child._created,
</span><span class="cx"> child._modified,) = tuple(row)
</span><ins>+ try:
+ child._notificationType = json.loads(child._notificationType)
+ except ValueError:
+ pass
</ins><span class="cx"> child._loadPropertyStore(
</span><span class="cx"> props=propertyStores.get(child._resourceID, None)
</span><span class="cx"> )
</span><span class="lines">@@ -5326,8 +5600,8 @@
</span><span class="cx"> [
</span><span class="cx"> no.RESOURCE_ID,
</span><span class="cx"> no.MD5,
</span><del>- Len(no.XML_DATA),
- no.XML_TYPE,
</del><ins>+ Len(no.NOTIFICATION_DATA),
+ no.NOTIFICATION_TYPE,
</ins><span class="cx"> no.CREATED,
</span><span class="cx"> no.MODIFIED
</span><span class="cx"> ],
</span><span class="lines">@@ -5352,9 +5626,13 @@
</span><span class="cx"> (self._resourceID,
</span><span class="cx"> self._md5,
</span><span class="cx"> self._size,
</span><del>- self._xmlType,
</del><ins>+ self._notificationType,
</ins><span class="cx"> self._created,
</span><span class="cx"> self._modified,) = tuple(rows[0])
</span><ins>+ try:
+ self._notificationType = json.loads(self._notificationType)
+ except ValueError:
+ pass
</ins><span class="cx"> self._loadPropertyStore()
</span><span class="cx"> returnValue(self)
</span><span class="cx"> else:
</span><span class="lines">@@ -5405,8 +5683,8 @@
</span><span class="cx"> {
</span><span class="cx"> no.NOTIFICATION_HOME_RESOURCE_ID: Parameter("homeID"),
</span><span class="cx"> no.NOTIFICATION_UID: Parameter("uid"),
</span><del>- no.XML_TYPE: Parameter("xmlType"),
- no.XML_DATA: Parameter("xmlData"),
</del><ins>+ no.NOTIFICATION_TYPE: Parameter("notificationType"),
+ no.NOTIFICATION_DATA: Parameter("notificationData"),
</ins><span class="cx"> no.MD5: Parameter("md5"),
</span><span class="cx"> },
</span><span class="cx"> Return=[no.RESOURCE_ID, no.CREATED, no.MODIFIED]
</span><span class="lines">@@ -5418,8 +5696,8 @@
</span><span class="cx"> no = cls._objectSchema
</span><span class="cx"> return Update(
</span><span class="cx"> {
</span><del>- no.XML_TYPE: Parameter("xmlType"),
- no.XML_DATA: Parameter("xmlData"),
</del><ins>+ no.NOTIFICATION_TYPE: Parameter("notificationType"),
+ no.NOTIFICATION_DATA: Parameter("notificationData"),
</ins><span class="cx"> no.MD5: Parameter("md5"),
</span><span class="cx"> },
</span><span class="cx"> Where=(no.NOTIFICATION_HOME_RESOURCE_ID == Parameter("homeID")).And(
</span><span class="lines">@@ -5429,41 +5707,46 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def setData(self, uid, xmltype, xmldata, inserting=False):
</del><ins>+ def setData(self, uid, notificationtype, notificationdata, inserting=False):
</ins><span class="cx"> """
</span><span class="cx"> Set the object resource data and update and cached metadata.
</span><span class="cx"> """
</span><span class="cx">
</span><del>- self._xmlType = NotificationType(xmltype)
- self._md5 = hashlib.md5(xmldata).hexdigest()
- self._size = len(xmldata)
</del><ins>+ notificationtext = json.dumps(notificationdata)
+ self._notificationType = notificationtype
+ self._md5 = hashlib.md5(notificationtext).hexdigest()
+ self._size = len(notificationtext)
</ins><span class="cx"> if inserting:
</span><span class="cx"> rows = yield self._newNotificationQuery.on(
</span><span class="cx"> self._txn, homeID=self._home._resourceID, uid=uid,
</span><del>- xmlType=self._xmlType.toxml(), xmlData=xmldata, md5=self._md5
</del><ins>+ notificationType=json.dumps(self._notificationType),
+ notificationData=notificationtext, md5=self._md5
</ins><span class="cx"> )
</span><span class="cx"> self._resourceID, self._created, self._modified = rows[0]
</span><span class="cx"> self._loadPropertyStore()
</span><span class="cx"> else:
</span><span class="cx"> rows = yield self._updateNotificationQuery.on(
</span><span class="cx"> self._txn, homeID=self._home._resourceID, uid=uid,
</span><del>- xmlType=self._xmlType.toxml(), xmlData=xmldata, md5=self._md5
</del><ins>+ notificationType=json.dumps(self._notificationType),
+ notificationData=notificationtext, md5=self._md5
</ins><span class="cx"> )
</span><span class="cx"> self._modified = rows[0][0]
</span><del>- self._objectText = xmldata
</del><ins>+ self._notificationData = notificationdata
</ins><span class="cx">
</span><del>- _xmlDataFromID = Select(
- [_objectSchema.XML_DATA], From=_objectSchema,
</del><ins>+ _notificationDataFromID = Select(
+ [_objectSchema.NOTIFICATION_DATA], From=_objectSchema,
</ins><span class="cx"> Where=_objectSchema.RESOURCE_ID == Parameter("resourceID"))
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def xmldata(self):
- if self._objectText is None:
- self._objectText = (
- yield self._xmlDataFromID.on(
- self._txn, resourceID=self._resourceID))[0][0]
- returnValue(self._objectText)
</del><ins>+ def notificationData(self):
+ if self._notificationData is None:
+ self._notificationData = (yield self._notificationDataFromID.on(self._txn, resourceID=self._resourceID))[0][0]
+ try:
+ self._notificationData = json.loads(self._notificationData)
+ except ValueError:
+ pass
+ returnValue(self._notificationData)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def contentType(self):
</span><span class="lines">@@ -5481,15 +5764,10 @@
</span><span class="cx"> return self._size
</span><span class="cx">
</span><span class="cx">
</span><del>- def xmlType(self):
- # NB This is the NotificationType property element
- if isinstance(self._xmlType, str):
- # Convert into NotificationType property element
- self._xmlType = WebDAVDocument.fromString(self._xmlType).root_element
</del><ins>+ def notificationType(self):
+ return self._notificationType
</ins><span class="cx">
</span><del>- return self._xmlType
</del><span class="cx">
</span><del>-
</del><span class="cx"> def created(self):
</span><span class="cx"> return datetimeMktime(parseSQLTimestamp(self._created))
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresql_schemacurrentoracledialectsql"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/sql_schema/current-oracle-dialect.sql (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_schema/current-oracle-dialect.sql        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/current-oracle-dialect.sql        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -49,15 +49,16 @@
</span><span class="cx">
</span><span class="cx"> create table NOTIFICATION_HOME (
</span><span class="cx"> "RESOURCE_ID" integer primary key,
</span><del>- "OWNER_UID" nvarchar2(255) unique
</del><ins>+ "OWNER_UID" nvarchar2(255) unique,
+ "DATAVERSION" integer default 0 not null
</ins><span class="cx"> );
</span><span class="cx">
</span><span class="cx"> create table NOTIFICATION (
</span><span class="cx"> "RESOURCE_ID" integer primary key,
</span><span class="cx"> "NOTIFICATION_HOME_RESOURCE_ID" integer not null references NOTIFICATION_HOME,
</span><span class="cx"> "NOTIFICATION_UID" nvarchar2(255),
</span><del>- "XML_TYPE" nvarchar2(255),
- "XML_DATA" nclob,
</del><ins>+ "NOTIFICATION_TYPE" nvarchar2(255),
+ "NOTIFICATION_DATA" nclob,
</ins><span class="cx"> "MD5" nchar(32),
</span><span class="cx"> "CREATED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
</span><span class="cx"> "MODIFIED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
</span><span class="lines">@@ -91,6 +92,7 @@
</span><span class="cx"> insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('read', 1);
</span><span class="cx"> insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('write', 2);
</span><span class="cx"> insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('direct', 3);
</span><ins>+insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('indirect', 4);
</ins><span class="cx"> create table CALENDAR_BIND_STATUS (
</span><span class="cx"> "ID" integer primary key,
</span><span class="cx"> "DESCRIPTION" nvarchar2(16) unique
</span><span class="lines">@@ -100,6 +102,7 @@
</span><span class="cx"> insert into CALENDAR_BIND_STATUS (DESCRIPTION, ID) values ('accepted', 1);
</span><span class="cx"> insert into CALENDAR_BIND_STATUS (DESCRIPTION, ID) values ('declined', 2);
</span><span class="cx"> insert into CALENDAR_BIND_STATUS (DESCRIPTION, ID) values ('invalid', 3);
</span><ins>+insert into CALENDAR_BIND_STATUS (DESCRIPTION, ID) values ('deleted', 4);
</ins><span class="cx"> create table CALENDAR_TRANSP (
</span><span class="cx"> "ID" integer primary key,
</span><span class="cx"> "DESCRIPTION" nvarchar2(16) unique
</span><span class="lines">@@ -367,9 +370,10 @@
</span><span class="cx"> "VALUE" nvarchar2(255)
</span><span class="cx"> );
</span><span class="cx">
</span><del>-insert into CALENDARSERVER (NAME, VALUE) values ('VERSION', '28');
</del><ins>+insert into CALENDARSERVER (NAME, VALUE) values ('VERSION', '29');
</ins><span class="cx"> insert into CALENDARSERVER (NAME, VALUE) values ('CALENDAR-DATAVERSION', '5');
</span><span class="cx"> insert into CALENDARSERVER (NAME, VALUE) values ('ADDRESSBOOK-DATAVERSION', '2');
</span><ins>+insert into CALENDARSERVER (NAME, VALUE) values ('NOTIFICATION-DATAVERSION', '1');
</ins><span class="cx"> create index CALENDAR_HOME_METADAT_3cb9049e on CALENDAR_HOME_METADATA (
</span><span class="cx"> DEFAULT_EVENTS
</span><span class="cx"> );
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresql_schemacurrentsql"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/sql_schema/current.sql (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_schema/current.sql        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/current.sql        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -109,15 +109,16 @@
</span><span class="cx">
</span><span class="cx"> create table NOTIFICATION_HOME (
</span><span class="cx"> RESOURCE_ID integer primary key default nextval('RESOURCE_ID_SEQ'), -- implicit index
</span><del>- OWNER_UID varchar(255) not null unique -- implicit index
</del><ins>+ OWNER_UID varchar(255) not null unique, -- implicit index
+ DATAVERSION integer default 0 not null
</ins><span class="cx"> );
</span><span class="cx">
</span><span class="cx"> create table NOTIFICATION (
</span><span class="cx"> RESOURCE_ID integer primary key default nextval('RESOURCE_ID_SEQ'), -- implicit index
</span><span class="cx"> NOTIFICATION_HOME_RESOURCE_ID integer not null references NOTIFICATION_HOME,
</span><span class="cx"> NOTIFICATION_UID varchar(255) not null,
</span><del>- XML_TYPE varchar(255) not null,
- XML_DATA text not null,
</del><ins>+ NOTIFICATION_TYPE varchar(255) not null,
+ NOTIFICATION_DATA text not null,
</ins><span class="cx"> MD5 char(32) not null,
</span><span class="cx"> CREATED timestamp default timezone('UTC', CURRENT_TIMESTAMP),
</span><span class="cx"> MODIFIED timestamp default timezone('UTC', CURRENT_TIMESTAMP),
</span><span class="lines">@@ -168,6 +169,7 @@
</span><span class="cx"> insert into CALENDAR_BIND_MODE values (1, 'read' );
</span><span class="cx"> insert into CALENDAR_BIND_MODE values (2, 'write');
</span><span class="cx"> insert into CALENDAR_BIND_MODE values (3, 'direct');
</span><ins>+insert into CALENDAR_BIND_MODE values (4, 'indirect');
</ins><span class="cx">
</span><span class="cx"> -- Enumeration of statuses
</span><span class="cx">
</span><span class="lines">@@ -180,6 +182,7 @@
</span><span class="cx"> insert into CALENDAR_BIND_STATUS values (1, 'accepted');
</span><span class="cx"> insert into CALENDAR_BIND_STATUS values (2, 'declined');
</span><span class="cx"> insert into CALENDAR_BIND_STATUS values (3, 'invalid');
</span><ins>+insert into CALENDAR_BIND_STATUS values (4, 'deleted');
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> -- Enumeration of transparency
</span><span class="lines">@@ -699,6 +702,7 @@
</span><span class="cx"> VALUE varchar(255)
</span><span class="cx"> );
</span><span class="cx">
</span><del>-insert into CALENDARSERVER values ('VERSION', '28');
</del><ins>+insert into CALENDARSERVER values ('VERSION', '29');
</ins><span class="cx"> insert into CALENDARSERVER values ('CALENDAR-DATAVERSION', '5');
</span><span class="cx"> insert into CALENDARSERVER values ('ADDRESSBOOK-DATAVERSION', '2');
</span><ins>+insert into CALENDARSERVER values ('NOTIFICATION-DATAVERSION', '1');
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresql_schemaoldoracledialectv28sqlfromrev12016CalendarServerbranchesuserscdaboosharinginthestoretxdavcommondatastoresql_schemaoldoracledialectv28sql"></a>
<div class="copfile"><h4>Copied: CalendarServer/trunk/txdav/common/datastore/sql_schema/old/oracle-dialect/v28.sql (from rev 12016, CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/old/oracle-dialect/v28.sql) (0 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_schema/old/oracle-dialect/v28.sql         (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/old/oracle-dialect/v28.sql        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -0,0 +1,501 @@
</span><ins>+create sequence RESOURCE_ID_SEQ;
+create sequence INSTANCE_ID_SEQ;
+create sequence ATTACHMENT_ID_SEQ;
+create sequence REVISION_SEQ;
+create sequence WORKITEM_SEQ;
+create table NODE_INFO (
+ "HOSTNAME" nvarchar2(255),
+ "PID" integer not null,
+ "PORT" integer not null,
+ "TIME" timestamp default CURRENT_TIMESTAMP at time zone 'UTC' not null,
+ primary key("HOSTNAME", "PORT")
+);
+
+create table NAMED_LOCK (
+ "LOCK_NAME" nvarchar2(255) primary key
+);
+
+create table CALENDAR_HOME (
+ "RESOURCE_ID" integer primary key,
+ "OWNER_UID" nvarchar2(255) unique,
+ "DATAVERSION" integer default 0 not null
+);
+
+create table CALENDAR (
+ "RESOURCE_ID" integer primary key
+);
+
+create table CALENDAR_HOME_METADATA (
+ "RESOURCE_ID" integer primary key references CALENDAR_HOME on delete cascade,
+ "QUOTA_USED_BYTES" integer default 0 not null,
+ "DEFAULT_EVENTS" integer default null references CALENDAR on delete set null,
+ "DEFAULT_TASKS" integer default null references CALENDAR on delete set null,
+ "DEFAULT_POLLS" integer default null references CALENDAR on delete set null,
+ "ALARM_VEVENT_TIMED" nclob default null,
+ "ALARM_VEVENT_ALLDAY" nclob default null,
+ "ALARM_VTODO_TIMED" nclob default null,
+ "ALARM_VTODO_ALLDAY" nclob default null,
+ "AVAILABILITY" nclob default null,
+ "CREATED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+ "MODIFIED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC'
+);
+
+create table CALENDAR_METADATA (
+ "RESOURCE_ID" integer primary key references CALENDAR on delete cascade,
+ "SUPPORTED_COMPONENTS" nvarchar2(255) default null,
+ "CREATED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+ "MODIFIED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC'
+);
+
+create table NOTIFICATION_HOME (
+ "RESOURCE_ID" integer primary key,
+ "OWNER_UID" nvarchar2(255) unique
+);
+
+create table NOTIFICATION (
+ "RESOURCE_ID" integer primary key,
+ "NOTIFICATION_HOME_RESOURCE_ID" integer not null references NOTIFICATION_HOME,
+ "NOTIFICATION_UID" nvarchar2(255),
+ "XML_TYPE" nvarchar2(255),
+ "XML_DATA" nclob,
+ "MD5" nchar(32),
+ "CREATED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+ "MODIFIED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+ unique("NOTIFICATION_UID", "NOTIFICATION_HOME_RESOURCE_ID")
+);
+
+create table CALENDAR_BIND (
+ "CALENDAR_HOME_RESOURCE_ID" integer not null references CALENDAR_HOME,
+ "CALENDAR_RESOURCE_ID" integer not null references CALENDAR on delete cascade,
+ "CALENDAR_RESOURCE_NAME" nvarchar2(255),
+ "BIND_MODE" integer not null,
+ "BIND_STATUS" integer not null,
+ "BIND_REVISION" integer default 0 not null,
+ "MESSAGE" nclob,
+ "TRANSP" integer default 0 not null,
+ "ALARM_VEVENT_TIMED" nclob default null,
+ "ALARM_VEVENT_ALLDAY" nclob default null,
+ "ALARM_VTODO_TIMED" nclob default null,
+ "ALARM_VTODO_ALLDAY" nclob default null,
+ "TIMEZONE" nclob default null,
+ primary key("CALENDAR_HOME_RESOURCE_ID", "CALENDAR_RESOURCE_ID"),
+ unique("CALENDAR_HOME_RESOURCE_ID", "CALENDAR_RESOURCE_NAME")
+);
+
+create table CALENDAR_BIND_MODE (
+ "ID" integer primary key,
+ "DESCRIPTION" nvarchar2(16) unique
+);
+
+insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('own', 0);
+insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('read', 1);
+insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('write', 2);
+insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('direct', 3);
+create table CALENDAR_BIND_STATUS (
+ "ID" integer primary key,
+ "DESCRIPTION" nvarchar2(16) unique
+);
+
+insert into CALENDAR_BIND_STATUS (DESCRIPTION, ID) values ('invited', 0);
+insert into CALENDAR_BIND_STATUS (DESCRIPTION, ID) values ('accepted', 1);
+insert into CALENDAR_BIND_STATUS (DESCRIPTION, ID) values ('declined', 2);
+insert into CALENDAR_BIND_STATUS (DESCRIPTION, ID) values ('invalid', 3);
+create table CALENDAR_TRANSP (
+ "ID" integer primary key,
+ "DESCRIPTION" nvarchar2(16) unique
+);
+
+insert into CALENDAR_TRANSP (DESCRIPTION, ID) values ('opaque', 0);
+insert into CALENDAR_TRANSP (DESCRIPTION, ID) values ('transparent', 1);
+create table CALENDAR_OBJECT (
+ "RESOURCE_ID" integer primary key,
+ "CALENDAR_RESOURCE_ID" integer not null references CALENDAR on delete cascade,
+ "RESOURCE_NAME" nvarchar2(255),
+ "ICALENDAR_TEXT" nclob,
+ "ICALENDAR_UID" nvarchar2(255),
+ "ICALENDAR_TYPE" nvarchar2(255),
+ "ATTACHMENTS_MODE" integer default 0 not null,
+ "DROPBOX_ID" nvarchar2(255),
+ "ORGANIZER" nvarchar2(255),
+ "RECURRANCE_MIN" date,
+ "RECURRANCE_MAX" date,
+ "ACCESS" integer default 0 not null,
+ "SCHEDULE_OBJECT" integer default 0,
+ "SCHEDULE_TAG" nvarchar2(36) default null,
+ "SCHEDULE_ETAGS" nclob default null,
+ "PRIVATE_COMMENTS" integer default 0 not null,
+ "MD5" nchar(32),
+ "CREATED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+ "MODIFIED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+ unique("CALENDAR_RESOURCE_ID", "RESOURCE_NAME")
+);
+
+create table CALENDAR_OBJECT_ATTACHMENTS_MO (
+ "ID" integer primary key,
+ "DESCRIPTION" nvarchar2(16) unique
+);
+
+insert into CALENDAR_OBJECT_ATTACHMENTS_MO (DESCRIPTION, ID) values ('none', 0);
+insert into CALENDAR_OBJECT_ATTACHMENTS_MO (DESCRIPTION, ID) values ('read', 1);
+insert into CALENDAR_OBJECT_ATTACHMENTS_MO (DESCRIPTION, ID) values ('write', 2);
+create table CALENDAR_ACCESS_TYPE (
+ "ID" integer primary key,
+ "DESCRIPTION" nvarchar2(32) unique
+);
+
+insert into CALENDAR_ACCESS_TYPE (DESCRIPTION, ID) values ('', 0);
+insert into CALENDAR_ACCESS_TYPE (DESCRIPTION, ID) values ('public', 1);
+insert into CALENDAR_ACCESS_TYPE (DESCRIPTION, ID) values ('private', 2);
+insert into CALENDAR_ACCESS_TYPE (DESCRIPTION, ID) values ('confidential', 3);
+insert into CALENDAR_ACCESS_TYPE (DESCRIPTION, ID) values ('restricted', 4);
+create table TIME_RANGE (
+ "INSTANCE_ID" integer primary key,
+ "CALENDAR_RESOURCE_ID" integer not null references CALENDAR on delete cascade,
+ "CALENDAR_OBJECT_RESOURCE_ID" integer not null references CALENDAR_OBJECT on delete cascade,
+ "FLOATING" integer not null,
+ "START_DATE" timestamp not null,
+ "END_DATE" timestamp not null,
+ "FBTYPE" integer not null,
+ "TRANSPARENT" integer not null
+);
+
+create table FREE_BUSY_TYPE (
+ "ID" integer primary key,
+ "DESCRIPTION" nvarchar2(16) unique
+);
+
+insert into FREE_BUSY_TYPE (DESCRIPTION, ID) values ('unknown', 0);
+insert into FREE_BUSY_TYPE (DESCRIPTION, ID) values ('free', 1);
+insert into FREE_BUSY_TYPE (DESCRIPTION, ID) values ('busy', 2);
+insert into FREE_BUSY_TYPE (DESCRIPTION, ID) values ('busy-unavailable', 3);
+insert into FREE_BUSY_TYPE (DESCRIPTION, ID) values ('busy-tentative', 4);
+create table TRANSPARENCY (
+ "TIME_RANGE_INSTANCE_ID" integer not null references TIME_RANGE on delete cascade,
+ "USER_ID" nvarchar2(255),
+ "TRANSPARENT" integer not null
+);
+
+create table ATTACHMENT (
+ "ATTACHMENT_ID" integer primary key,
+ "CALENDAR_HOME_RESOURCE_ID" integer not null references CALENDAR_HOME,
+ "DROPBOX_ID" nvarchar2(255),
+ "CONTENT_TYPE" nvarchar2(255),
+ "SIZE" integer not null,
+ "MD5" nchar(32),
+ "CREATED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+ "MODIFIED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+ "PATH" nvarchar2(1024)
+);
+
+create table ATTACHMENT_CALENDAR_OBJECT (
+ "ATTACHMENT_ID" integer not null references ATTACHMENT on delete cascade,
+ "MANAGED_ID" nvarchar2(255),
+ "CALENDAR_OBJECT_RESOURCE_ID" integer not null references CALENDAR_OBJECT on delete cascade,
+ primary key("ATTACHMENT_ID", "CALENDAR_OBJECT_RESOURCE_ID"),
+ unique("MANAGED_ID", "CALENDAR_OBJECT_RESOURCE_ID")
+);
+
+create table RESOURCE_PROPERTY (
+ "RESOURCE_ID" integer not null,
+ "NAME" nvarchar2(255),
+ "VALUE" nclob,
+ "VIEWER_UID" nvarchar2(255),
+ primary key("RESOURCE_ID", "NAME", "VIEWER_UID")
+);
+
+create table ADDRESSBOOK_HOME (
+ "RESOURCE_ID" integer primary key,
+ "ADDRESSBOOK_PROPERTY_STORE_ID" integer not null,
+ "OWNER_UID" nvarchar2(255) unique,
+ "DATAVERSION" integer default 0 not null
+);
+
+create table ADDRESSBOOK_HOME_METADATA (
+ "RESOURCE_ID" integer primary key references ADDRESSBOOK_HOME on delete cascade,
+ "QUOTA_USED_BYTES" integer default 0 not null,
+ "CREATED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+ "MODIFIED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC'
+);
+
+create table SHARED_ADDRESSBOOK_BIND (
+ "ADDRESSBOOK_HOME_RESOURCE_ID" integer not null references ADDRESSBOOK_HOME,
+ "OWNER_HOME_RESOURCE_ID" integer not null references ADDRESSBOOK_HOME on delete cascade,
+ "ADDRESSBOOK_RESOURCE_NAME" nvarchar2(255),
+ "BIND_MODE" integer not null,
+ "BIND_STATUS" integer not null,
+ "BIND_REVISION" integer default 0 not null,
+ "MESSAGE" nclob,
+ primary key("ADDRESSBOOK_HOME_RESOURCE_ID", "OWNER_HOME_RESOURCE_ID"),
+ unique("ADDRESSBOOK_HOME_RESOURCE_ID", "ADDRESSBOOK_RESOURCE_NAME")
+);
+
+create table ADDRESSBOOK_OBJECT (
+ "RESOURCE_ID" integer primary key,
+ "ADDRESSBOOK_HOME_RESOURCE_ID" integer not null references ADDRESSBOOK_HOME on delete cascade,
+ "RESOURCE_NAME" nvarchar2(255),
+ "VCARD_TEXT" nclob,
+ "VCARD_UID" nvarchar2(255),
+ "KIND" integer not null,
+ "MD5" nchar(32),
+ "CREATED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+ "MODIFIED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+ unique("ADDRESSBOOK_HOME_RESOURCE_ID", "RESOURCE_NAME"),
+ unique("ADDRESSBOOK_HOME_RESOURCE_ID", "VCARD_UID")
+);
+
+create table ADDRESSBOOK_OBJECT_KIND (
+ "ID" integer primary key,
+ "DESCRIPTION" nvarchar2(16) unique
+);
+
+insert into ADDRESSBOOK_OBJECT_KIND (DESCRIPTION, ID) values ('person', 0);
+insert into ADDRESSBOOK_OBJECT_KIND (DESCRIPTION, ID) values ('group', 1);
+insert into ADDRESSBOOK_OBJECT_KIND (DESCRIPTION, ID) values ('resource', 2);
+insert into ADDRESSBOOK_OBJECT_KIND (DESCRIPTION, ID) values ('location', 3);
+create table ABO_MEMBERS (
+ "GROUP_ID" integer not null references ADDRESSBOOK_OBJECT on delete cascade,
+ "ADDRESSBOOK_ID" integer not null references ADDRESSBOOK_HOME on delete cascade,
+ "MEMBER_ID" integer not null references ADDRESSBOOK_OBJECT,
+ primary key("GROUP_ID", "MEMBER_ID")
+);
+
+create table ABO_FOREIGN_MEMBERS (
+ "GROUP_ID" integer not null references ADDRESSBOOK_OBJECT on delete cascade,
+ "ADDRESSBOOK_ID" integer not null references ADDRESSBOOK_HOME on delete cascade,
+ "MEMBER_ADDRESS" nvarchar2(255),
+ primary key("GROUP_ID", "MEMBER_ADDRESS")
+);
+
+create table SHARED_GROUP_BIND (
+ "ADDRESSBOOK_HOME_RESOURCE_ID" integer not null references ADDRESSBOOK_HOME,
+ "GROUP_RESOURCE_ID" integer not null references ADDRESSBOOK_OBJECT on delete cascade,
+ "GROUP_ADDRESSBOOK_NAME" nvarchar2(255),
+ "BIND_MODE" integer not null,
+ "BIND_STATUS" integer not null,
+ "BIND_REVISION" integer default 0 not null,
+ "MESSAGE" nclob,
+ primary key("ADDRESSBOOK_HOME_RESOURCE_ID", "GROUP_RESOURCE_ID"),
+ unique("ADDRESSBOOK_HOME_RESOURCE_ID", "GROUP_ADDRESSBOOK_NAME")
+);
+
+create table CALENDAR_OBJECT_REVISIONS (
+ "CALENDAR_HOME_RESOURCE_ID" integer not null references CALENDAR_HOME,
+ "CALENDAR_RESOURCE_ID" integer references CALENDAR,
+ "CALENDAR_NAME" nvarchar2(255) default null,
+ "RESOURCE_NAME" nvarchar2(255),
+ "REVISION" integer not null,
+ "DELETED" integer not null
+);
+
+create table ADDRESSBOOK_OBJECT_REVISIONS (
+ "ADDRESSBOOK_HOME_RESOURCE_ID" integer not null references ADDRESSBOOK_HOME,
+ "OWNER_HOME_RESOURCE_ID" integer references ADDRESSBOOK_HOME,
+ "ADDRESSBOOK_NAME" nvarchar2(255) default null,
+ "RESOURCE_NAME" nvarchar2(255),
+ "REVISION" integer not null,
+ "DELETED" integer not null
+);
+
+create table NOTIFICATION_OBJECT_REVISIONS (
+ "NOTIFICATION_HOME_RESOURCE_ID" integer not null references NOTIFICATION_HOME on delete cascade,
+ "RESOURCE_NAME" nvarchar2(255),
+ "REVISION" integer not null,
+ "DELETED" integer not null,
+ unique("NOTIFICATION_HOME_RESOURCE_ID", "RESOURCE_NAME")
+);
+
+create table APN_SUBSCRIPTIONS (
+ "TOKEN" nvarchar2(255),
+ "RESOURCE_KEY" nvarchar2(255),
+ "MODIFIED" integer not null,
+ "SUBSCRIBER_GUID" nvarchar2(255),
+ "USER_AGENT" nvarchar2(255) default null,
+ "IP_ADDR" nvarchar2(255) default null,
+ primary key("TOKEN", "RESOURCE_KEY")
+);
+
+create table IMIP_TOKENS (
+ "TOKEN" nvarchar2(255),
+ "ORGANIZER" nvarchar2(255),
+ "ATTENDEE" nvarchar2(255),
+ "ICALUID" nvarchar2(255),
+ "ACCESSED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+ primary key("ORGANIZER", "ATTENDEE", "ICALUID")
+);
+
+create table IMIP_INVITATION_WORK (
+ "WORK_ID" integer primary key not null,
+ "NOT_BEFORE" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+ "FROM_ADDR" nvarchar2(255),
+ "TO_ADDR" nvarchar2(255),
+ "ICALENDAR_TEXT" nclob
+);
+
+create table IMIP_POLLING_WORK (
+ "WORK_ID" integer primary key not null,
+ "NOT_BEFORE" timestamp default CURRENT_TIMESTAMP at time zone 'UTC'
+);
+
+create table IMIP_REPLY_WORK (
+ "WORK_ID" integer primary key not null,
+ "NOT_BEFORE" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+ "ORGANIZER" nvarchar2(255),
+ "ATTENDEE" nvarchar2(255),
+ "ICALENDAR_TEXT" nclob
+);
+
+create table PUSH_NOTIFICATION_WORK (
+ "WORK_ID" integer primary key not null,
+ "NOT_BEFORE" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+ "PUSH_ID" nvarchar2(255),
+ "PRIORITY" integer not null
+);
+
+create table GROUP_CACHER_POLLING_WORK (
+ "WORK_ID" integer primary key not null,
+ "NOT_BEFORE" timestamp default CURRENT_TIMESTAMP at time zone 'UTC'
+);
+
+create table CALENDAR_OBJECT_SPLITTER_WORK (
+ "WORK_ID" integer primary key not null,
+ "NOT_BEFORE" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
+ "RESOURCE_ID" integer not null references CALENDAR_OBJECT on delete cascade
+);
+
+create table CALENDARSERVER (
+ "NAME" nvarchar2(255) primary key,
+ "VALUE" nvarchar2(255)
+);
+
+insert into CALENDARSERVER (NAME, VALUE) values ('VERSION', '28');
+insert into CALENDARSERVER (NAME, VALUE) values ('CALENDAR-DATAVERSION', '5');
+insert into CALENDARSERVER (NAME, VALUE) values ('ADDRESSBOOK-DATAVERSION', '2');
+create index CALENDAR_HOME_METADAT_3cb9049e on CALENDAR_HOME_METADATA (
+ DEFAULT_EVENTS
+);
+
+create index CALENDAR_HOME_METADAT_d55e5548 on CALENDAR_HOME_METADATA (
+ DEFAULT_TASKS
+);
+
+create index CALENDAR_HOME_METADAT_910264ce on CALENDAR_HOME_METADATA (
+ DEFAULT_POLLS
+);
+
+create index NOTIFICATION_NOTIFICA_f891f5f9 on NOTIFICATION (
+ NOTIFICATION_HOME_RESOURCE_ID
+);
+
+create index CALENDAR_BIND_RESOURC_e57964d4 on CALENDAR_BIND (
+ CALENDAR_RESOURCE_ID
+);
+
+create index CALENDAR_OBJECT_CALEN_a9a453a9 on CALENDAR_OBJECT (
+ CALENDAR_RESOURCE_ID,
+ ICALENDAR_UID
+);
+
+create index CALENDAR_OBJECT_CALEN_96e83b73 on CALENDAR_OBJECT (
+ CALENDAR_RESOURCE_ID,
+ RECURRANCE_MAX
+);
+
+create index CALENDAR_OBJECT_ICALE_82e731d5 on CALENDAR_OBJECT (
+ ICALENDAR_UID
+);
+
+create index CALENDAR_OBJECT_DROPB_de041d80 on CALENDAR_OBJECT (
+ DROPBOX_ID
+);
+
+create index TIME_RANGE_CALENDAR_R_beb6e7eb on TIME_RANGE (
+ CALENDAR_RESOURCE_ID
+);
+
+create index TIME_RANGE_CALENDAR_O_acf37bd1 on TIME_RANGE (
+ CALENDAR_OBJECT_RESOURCE_ID
+);
+
+create index TRANSPARENCY_TIME_RAN_5f34467f on TRANSPARENCY (
+ TIME_RANGE_INSTANCE_ID
+);
+
+create index ATTACHMENT_CALENDAR_H_0078845c on ATTACHMENT (
+ CALENDAR_HOME_RESOURCE_ID
+);
+
+create index ATTACHMENT_CALENDAR_O_81508484 on ATTACHMENT_CALENDAR_OBJECT (
+ CALENDAR_OBJECT_RESOURCE_ID
+);
+
+create index SHARED_ADDRESSBOOK_BI_e9a2e6d4 on SHARED_ADDRESSBOOK_BIND (
+ OWNER_HOME_RESOURCE_ID
+);
+
+create index ABO_MEMBERS_ADDRESSBO_4effa879 on ABO_MEMBERS (
+ ADDRESSBOOK_ID
+);
+
+create index ABO_MEMBERS_MEMBER_ID_8d66adcf on ABO_MEMBERS (
+ MEMBER_ID
+);
+
+create index ABO_FOREIGN_MEMBERS_A_1fd2c5e9 on ABO_FOREIGN_MEMBERS (
+ ADDRESSBOOK_ID
+);
+
+create index SHARED_GROUP_BIND_RES_cf52f95d on SHARED_GROUP_BIND (
+ GROUP_RESOURCE_ID
+);
+
+create index CALENDAR_OBJECT_REVIS_3a3956c4 on CALENDAR_OBJECT_REVISIONS (
+ CALENDAR_HOME_RESOURCE_ID,
+ CALENDAR_RESOURCE_ID
+);
+
+create index CALENDAR_OBJECT_REVIS_6d9d929c on CALENDAR_OBJECT_REVISIONS (
+ CALENDAR_RESOURCE_ID,
+ RESOURCE_NAME,
+ DELETED,
+ REVISION
+);
+
+create index CALENDAR_OBJECT_REVIS_265c8acf on CALENDAR_OBJECT_REVISIONS (
+ CALENDAR_RESOURCE_ID,
+ REVISION
+);
+
+create index ADDRESSBOOK_OBJECT_RE_2bfcf757 on ADDRESSBOOK_OBJECT_REVISIONS (
+ ADDRESSBOOK_HOME_RESOURCE_ID,
+ OWNER_HOME_RESOURCE_ID
+);
+
+create index ADDRESSBOOK_OBJECT_RE_00fe8288 on ADDRESSBOOK_OBJECT_REVISIONS (
+ OWNER_HOME_RESOURCE_ID,
+ RESOURCE_NAME,
+ DELETED,
+ REVISION
+);
+
+create index ADDRESSBOOK_OBJECT_RE_45004780 on ADDRESSBOOK_OBJECT_REVISIONS (
+ OWNER_HOME_RESOURCE_ID,
+ REVISION
+);
+
+create index NOTIFICATION_OBJECT_R_036a9cee on NOTIFICATION_OBJECT_REVISIONS (
+ NOTIFICATION_HOME_RESOURCE_ID,
+ REVISION
+);
+
+create index APN_SUBSCRIPTIONS_RES_9610d78e on APN_SUBSCRIPTIONS (
+ RESOURCE_KEY
+);
+
+create index IMIP_TOKENS_TOKEN_e94b918f on IMIP_TOKENS (
+ TOKEN
+);
+
+create index CALENDAR_OBJECT_SPLIT_af71dcda on CALENDAR_OBJECT_SPLITTER_WORK (
+ RESOURCE_ID
+);
+
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresql_schemaoldpostgresdialectv28sqlfromrev12016CalendarServerbranchesuserscdaboosharinginthestoretxdavcommondatastoresql_schemaoldpostgresdialectv28sql"></a>
<div class="copfile"><h4>Copied: CalendarServer/trunk/txdav/common/datastore/sql_schema/old/postgres-dialect/v28.sql (from rev 12016, CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/old/postgres-dialect/v28.sql) (0 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_schema/old/postgres-dialect/v28.sql         (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/old/postgres-dialect/v28.sql        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -0,0 +1,704 @@
</span><ins>+-- -*- test-case-name: txdav.caldav.datastore.test.test_sql,txdav.carddav.datastore.test.test_sql -*-
+
+----
+-- Copyright (c) 2010-2013 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.
+----
+
+
+-----------------
+-- Resource ID --
+-----------------
+
+create sequence RESOURCE_ID_SEQ;
+
+
+-------------------------
+-- Cluster Bookkeeping --
+-------------------------
+
+-- Information about a process connected to this database.
+
+-- Note that this must match the node info schema in twext.enterprise.queue.
+create table NODE_INFO (
+ HOSTNAME varchar(255) not null,
+ PID integer not null,
+ PORT integer not null,
+ TIME timestamp not null default timezone('UTC', CURRENT_TIMESTAMP),
+
+ primary key (HOSTNAME, PORT)
+);
+
+-- Unique named locks. This table should always be empty, but rows are
+-- temporarily created in order to prevent undesirable concurrency.
+create table NAMED_LOCK (
+ LOCK_NAME varchar(255) primary key
+);
+
+
+-------------------
+-- Calendar Home --
+-------------------
+
+create table CALENDAR_HOME (
+ RESOURCE_ID integer primary key default nextval('RESOURCE_ID_SEQ'), -- implicit index
+ OWNER_UID varchar(255) not null unique, -- implicit index
+ DATAVERSION integer default 0 not null
+);
+
+--------------
+-- Calendar --
+--------------
+
+create table CALENDAR (
+ RESOURCE_ID integer primary key default nextval('RESOURCE_ID_SEQ') -- implicit index
+);
+
+----------------------------
+-- Calendar Home Metadata --
+----------------------------
+
+create table CALENDAR_HOME_METADATA (
+ RESOURCE_ID integer primary key references CALENDAR_HOME on delete cascade, -- implicit index
+ QUOTA_USED_BYTES integer default 0 not null,
+ DEFAULT_EVENTS integer default null references CALENDAR on delete set null,
+ DEFAULT_TASKS integer default null references CALENDAR on delete set null,
+ DEFAULT_POLLS integer default null references CALENDAR on delete set null,
+ ALARM_VEVENT_TIMED text default null,
+ ALARM_VEVENT_ALLDAY text default null,
+ ALARM_VTODO_TIMED text default null,
+ ALARM_VTODO_ALLDAY text default null,
+ AVAILABILITY text default null,
+ CREATED timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+ MODIFIED timestamp default timezone('UTC', CURRENT_TIMESTAMP)
+);
+
+create index CALENDAR_HOME_METADATA_DEFAULT_EVENTS on
+        CALENDAR_HOME_METADATA(DEFAULT_EVENTS);
+create index CALENDAR_HOME_METADATA_DEFAULT_TASKS on
+        CALENDAR_HOME_METADATA(DEFAULT_TASKS);
+create index CALENDAR_HOME_METADATA_DEFAULT_POLLS on
+        CALENDAR_HOME_METADATA(DEFAULT_POLLS);
+
+-----------------------
+-- Calendar Metadata --
+-----------------------
+
+create table CALENDAR_METADATA (
+ RESOURCE_ID integer primary key references CALENDAR on delete cascade, -- implicit index
+ SUPPORTED_COMPONENTS varchar(255) default null,
+ CREATED timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+ MODIFIED timestamp default timezone('UTC', CURRENT_TIMESTAMP)
+);
+
+
+---------------------------
+-- Sharing Notifications --
+---------------------------
+
+create table NOTIFICATION_HOME (
+ RESOURCE_ID integer primary key default nextval('RESOURCE_ID_SEQ'), -- implicit index
+ OWNER_UID varchar(255) not null unique -- implicit index
+);
+
+create table NOTIFICATION (
+ RESOURCE_ID integer primary key default nextval('RESOURCE_ID_SEQ'), -- implicit index
+ NOTIFICATION_HOME_RESOURCE_ID integer not null references NOTIFICATION_HOME,
+ NOTIFICATION_UID varchar(255) not null,
+ XML_TYPE varchar(255) not null,
+ XML_DATA text not null,
+ MD5 char(32) not null,
+ CREATED timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+ MODIFIED timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+
+ unique(NOTIFICATION_UID, NOTIFICATION_HOME_RESOURCE_ID) -- implicit index
+);
+
+create index NOTIFICATION_NOTIFICATION_HOME_RESOURCE_ID on
+        NOTIFICATION(NOTIFICATION_HOME_RESOURCE_ID);
+
+
+-------------------
+-- Calendar Bind --
+-------------------
+
+-- Joins CALENDAR_HOME and CALENDAR
+
+create table CALENDAR_BIND (
+ CALENDAR_HOME_RESOURCE_ID integer not null references CALENDAR_HOME,
+ CALENDAR_RESOURCE_ID integer not null references CALENDAR on delete cascade,
+ CALENDAR_RESOURCE_NAME varchar(255) not null,
+ BIND_MODE integer not null, -- enum CALENDAR_BIND_MODE
+ BIND_STATUS integer not null, -- enum CALENDAR_BIND_STATUS
+ BIND_REVISION                                integer default 0 not null,
+ MESSAGE text,
+ TRANSP integer default 0 not null, -- enum CALENDAR_TRANSP
+ ALARM_VEVENT_TIMED text default null,
+ ALARM_VEVENT_ALLDAY text default null,
+ ALARM_VTODO_TIMED text default null,
+ ALARM_VTODO_ALLDAY text default null,
+ TIMEZONE text default null,
+
+ primary key(CALENDAR_HOME_RESOURCE_ID, CALENDAR_RESOURCE_ID), -- implicit index
+ unique(CALENDAR_HOME_RESOURCE_ID, CALENDAR_RESOURCE_NAME) -- implicit index
+);
+
+create index CALENDAR_BIND_RESOURCE_ID on
+        CALENDAR_BIND(CALENDAR_RESOURCE_ID);
+
+-- Enumeration of calendar bind modes
+
+create table CALENDAR_BIND_MODE (
+ ID integer primary key,
+ DESCRIPTION varchar(16) not null unique
+);
+
+insert into CALENDAR_BIND_MODE values (0, 'own' );
+insert into CALENDAR_BIND_MODE values (1, 'read' );
+insert into CALENDAR_BIND_MODE values (2, 'write');
+insert into CALENDAR_BIND_MODE values (3, 'direct');
+
+-- Enumeration of statuses
+
+create table CALENDAR_BIND_STATUS (
+ ID integer primary key,
+ DESCRIPTION varchar(16) not null unique
+);
+
+insert into CALENDAR_BIND_STATUS values (0, 'invited' );
+insert into CALENDAR_BIND_STATUS values (1, 'accepted');
+insert into CALENDAR_BIND_STATUS values (2, 'declined');
+insert into CALENDAR_BIND_STATUS values (3, 'invalid');
+
+
+-- Enumeration of transparency
+
+create table CALENDAR_TRANSP (
+ ID integer primary key,
+ DESCRIPTION varchar(16) not null unique
+);
+
+insert into CALENDAR_TRANSP values (0, 'opaque' );
+insert into CALENDAR_TRANSP values (1, 'transparent');
+
+
+---------------------
+-- Calendar Object --
+---------------------
+
+create table CALENDAR_OBJECT (
+ RESOURCE_ID integer primary key default nextval('RESOURCE_ID_SEQ'), -- implicit index
+ CALENDAR_RESOURCE_ID integer not null references CALENDAR on delete cascade,
+ RESOURCE_NAME varchar(255) not null,
+ ICALENDAR_TEXT text not null,
+ ICALENDAR_UID varchar(255) not null,
+ ICALENDAR_TYPE varchar(255) not null,
+ ATTACHMENTS_MODE integer default 0 not null, -- enum CALENDAR_OBJECT_ATTACHMENTS_MODE
+ DROPBOX_ID varchar(255),
+ ORGANIZER varchar(255),
+ RECURRANCE_MIN date, -- minimum date that recurrences have been expanded to.
+ RECURRANCE_MAX date, -- maximum date that recurrences have been expanded to.
+ ACCESS integer default 0 not null,
+ SCHEDULE_OBJECT boolean default false,
+ SCHEDULE_TAG varchar(36) default null,
+ SCHEDULE_ETAGS text default null,
+ PRIVATE_COMMENTS boolean default false not null,
+ MD5 char(32) not null,
+ CREATED timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+ MODIFIED timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+
+ unique (CALENDAR_RESOURCE_ID, RESOURCE_NAME) -- implicit index
+
+ -- since the 'inbox' is a 'calendar resource' for the purpose of storing
+ -- calendar objects, this constraint has to be selectively enforced by the
+ -- application layer.
+
+ -- unique(CALENDAR_RESOURCE_ID, ICALENDAR_UID)
+);
+
+create index CALENDAR_OBJECT_CALENDAR_RESOURCE_ID_AND_ICALENDAR_UID on
+ CALENDAR_OBJECT(CALENDAR_RESOURCE_ID, ICALENDAR_UID);
+
+create index CALENDAR_OBJECT_CALENDAR_RESOURCE_ID_RECURRANCE_MAX on
+ CALENDAR_OBJECT(CALENDAR_RESOURCE_ID, RECURRANCE_MAX);
+
+create index CALENDAR_OBJECT_ICALENDAR_UID on
+ CALENDAR_OBJECT(ICALENDAR_UID);
+
+create index CALENDAR_OBJECT_DROPBOX_ID on
+ CALENDAR_OBJECT(DROPBOX_ID);
+
+-- Enumeration of attachment modes
+
+create table CALENDAR_OBJECT_ATTACHMENTS_MODE (
+ ID integer primary key,
+ DESCRIPTION varchar(16) not null unique
+);
+
+insert into CALENDAR_OBJECT_ATTACHMENTS_MODE values (0, 'none' );
+insert into CALENDAR_OBJECT_ATTACHMENTS_MODE values (1, 'read' );
+insert into CALENDAR_OBJECT_ATTACHMENTS_MODE values (2, 'write');
+
+
+-- Enumeration of calendar access types
+
+create table CALENDAR_ACCESS_TYPE (
+ ID integer primary key,
+ DESCRIPTION varchar(32) not null unique
+);
+
+insert into CALENDAR_ACCESS_TYPE values (0, '' );
+insert into CALENDAR_ACCESS_TYPE values (1, 'public' );
+insert into CALENDAR_ACCESS_TYPE values (2, 'private' );
+insert into CALENDAR_ACCESS_TYPE values (3, 'confidential' );
+insert into CALENDAR_ACCESS_TYPE values (4, 'restricted' );
+
+
+-----------------
+-- Instance ID --
+-----------------
+
+create sequence INSTANCE_ID_SEQ;
+
+
+----------------
+-- Time Range --
+----------------
+
+create table TIME_RANGE (
+ INSTANCE_ID integer primary key default nextval('INSTANCE_ID_SEQ'), -- implicit index
+ CALENDAR_RESOURCE_ID integer not null references CALENDAR on delete cascade,
+ CALENDAR_OBJECT_RESOURCE_ID integer not null references CALENDAR_OBJECT on delete cascade,
+ FLOATING boolean not null,
+ START_DATE timestamp not null,
+ END_DATE timestamp not null,
+ FBTYPE integer not null,
+ TRANSPARENT boolean not null
+);
+
+create index TIME_RANGE_CALENDAR_RESOURCE_ID on
+ TIME_RANGE(CALENDAR_RESOURCE_ID);
+create index TIME_RANGE_CALENDAR_OBJECT_RESOURCE_ID on
+ TIME_RANGE(CALENDAR_OBJECT_RESOURCE_ID);
+
+
+-- Enumeration of free/busy types
+
+create table FREE_BUSY_TYPE (
+ ID integer primary key,
+ DESCRIPTION varchar(16) not null unique
+);
+
+insert into FREE_BUSY_TYPE values (0, 'unknown' );
+insert into FREE_BUSY_TYPE values (1, 'free' );
+insert into FREE_BUSY_TYPE values (2, 'busy' );
+insert into FREE_BUSY_TYPE values (3, 'busy-unavailable');
+insert into FREE_BUSY_TYPE values (4, 'busy-tentative' );
+
+
+------------------
+-- Transparency --
+------------------
+
+create table TRANSPARENCY (
+ TIME_RANGE_INSTANCE_ID integer not null references TIME_RANGE on delete cascade,
+ USER_ID varchar(255) not null,
+ TRANSPARENT boolean not null
+);
+
+create index TRANSPARENCY_TIME_RANGE_INSTANCE_ID on
+ TRANSPARENCY(TIME_RANGE_INSTANCE_ID);
+
+
+----------------
+-- Attachment --
+----------------
+
+create sequence ATTACHMENT_ID_SEQ;
+
+create table ATTACHMENT (
+ ATTACHMENT_ID integer primary key default nextval('ATTACHMENT_ID_SEQ'), -- implicit index
+ CALENDAR_HOME_RESOURCE_ID integer not null references CALENDAR_HOME,
+ DROPBOX_ID varchar(255),
+ CONTENT_TYPE varchar(255) not null,
+ SIZE integer not null,
+ MD5 char(32) not null,
+ CREATED timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+ MODIFIED timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+ PATH varchar(1024) not null
+);
+
+create index ATTACHMENT_CALENDAR_HOME_RESOURCE_ID on
+ ATTACHMENT(CALENDAR_HOME_RESOURCE_ID);
+
+-- Many-to-many relationship between attachments and calendar objects
+create table ATTACHMENT_CALENDAR_OBJECT (
+ ATTACHMENT_ID integer not null references ATTACHMENT on delete cascade,
+ MANAGED_ID varchar(255) not null,
+ CALENDAR_OBJECT_RESOURCE_ID integer not null references CALENDAR_OBJECT on delete cascade,
+
+ primary key (ATTACHMENT_ID, CALENDAR_OBJECT_RESOURCE_ID), -- implicit index
+ unique (MANAGED_ID, CALENDAR_OBJECT_RESOURCE_ID) --implicit index
+);
+
+create index ATTACHMENT_CALENDAR_OBJECT_CALENDAR_OBJECT_RESOURCE_ID on
+        ATTACHMENT_CALENDAR_OBJECT(CALENDAR_OBJECT_RESOURCE_ID);
+
+-----------------------
+-- Resource Property --
+-----------------------
+
+create table RESOURCE_PROPERTY (
+ RESOURCE_ID integer not null, -- foreign key: *.RESOURCE_ID
+ NAME varchar(255) not null,
+ VALUE text not null, -- FIXME: xml?
+ VIEWER_UID varchar(255),
+
+ primary key (RESOURCE_ID, NAME, VIEWER_UID) -- implicit index
+);
+
+
+----------------------
+-- AddressBook Home --
+----------------------
+
+create table ADDRESSBOOK_HOME (
+ RESOURCE_ID                                 integer                        primary key default nextval('RESOURCE_ID_SEQ'), -- implicit index
+ ADDRESSBOOK_PROPERTY_STORE_ID        integer         default nextval('RESOURCE_ID_SEQ') not null,         -- implicit index
+ OWNER_UID                                 varchar(255)         not null unique, -- implicit index
+ DATAVERSION                                 integer         default 0 not null
+);
+
+
+-------------------------------
+-- AddressBook Home Metadata --
+-------------------------------
+
+create table ADDRESSBOOK_HOME_METADATA (
+ RESOURCE_ID integer primary key references ADDRESSBOOK_HOME on delete cascade, -- implicit index
+ QUOTA_USED_BYTES integer default 0 not null,
+ CREATED timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+ MODIFIED timestamp default timezone('UTC', CURRENT_TIMESTAMP)
+);
+
+
+-----------------------------
+-- Shared AddressBook Bind --
+-----------------------------
+
+-- Joins sharee ADDRESSBOOK_HOME and owner ADDRESSBOOK_HOME
+
+create table SHARED_ADDRESSBOOK_BIND (
+ ADDRESSBOOK_HOME_RESOURCE_ID                        integer                        not null references ADDRESSBOOK_HOME,
+ OWNER_HOME_RESOURCE_ID                         integer         not null references ADDRESSBOOK_HOME on delete cascade,
+ ADDRESSBOOK_RESOURCE_NAME                         varchar(255)         not null,
+ BIND_MODE                         integer         not null,        -- enum CALENDAR_BIND_MODE
+ BIND_STATUS                         integer         not null,        -- enum CALENDAR_BIND_STATUS
+ BIND_REVISION                                                         integer         default 0 not null,
+ MESSAGE                         text,                 -- FIXME: xml?
+
+ primary key (ADDRESSBOOK_HOME_RESOURCE_ID, OWNER_HOME_RESOURCE_ID), -- implicit index
+ unique (ADDRESSBOOK_HOME_RESOURCE_ID, ADDRESSBOOK_RESOURCE_NAME) -- implicit index
+);
+
+create index SHARED_ADDRESSBOOK_BIND_RESOURCE_ID on
+ SHARED_ADDRESSBOOK_BIND(OWNER_HOME_RESOURCE_ID);
+
+
+------------------------
+-- AddressBook Object --
+------------------------
+
+create table ADDRESSBOOK_OBJECT (
+ RESOURCE_ID                 integer                 primary key default nextval('RESOURCE_ID_SEQ'), -- implicit index
+ ADDRESSBOOK_HOME_RESOURCE_ID         integer         not null references ADDRESSBOOK_HOME on delete cascade,
+ RESOURCE_NAME                 varchar(255)         not null,
+ VCARD_TEXT                 text         not null,
+ VCARD_UID                 varchar(255)         not null,
+ KIND                                                           integer         not null, -- enum ADDRESSBOOK_OBJECT_KIND
+ MD5                 char(32)         not null,
+ CREATED                 timestamp         default timezone('UTC', CURRENT_TIMESTAMP),
+ MODIFIED                 timestamp         default timezone('UTC', CURRENT_TIMESTAMP),
+
+ unique (ADDRESSBOOK_HOME_RESOURCE_ID, RESOURCE_NAME), -- implicit index
+ unique (ADDRESSBOOK_HOME_RESOURCE_ID, VCARD_UID) -- implicit index
+);
+
+
+-----------------------------
+-- AddressBook Object kind --
+-----------------------------
+
+create table ADDRESSBOOK_OBJECT_KIND (
+ ID integer primary key,
+ DESCRIPTION varchar(16) not null unique
+);
+
+insert into ADDRESSBOOK_OBJECT_KIND values (0, 'person');
+insert into ADDRESSBOOK_OBJECT_KIND values (1, 'group' );
+insert into ADDRESSBOOK_OBJECT_KIND values (2, 'resource');
+insert into ADDRESSBOOK_OBJECT_KIND values (3, 'location');
+
+
+---------------------------------
+-- Address Book Object Members --
+---------------------------------
+
+create table ABO_MEMBERS (
+ GROUP_ID integer not null references ADDRESSBOOK_OBJECT on delete cascade,        -- AddressBook Object's (kind=='group') RESOURCE_ID
+         ADDRESSBOOK_ID                 integer not null references ADDRESSBOOK_HOME on delete cascade,
+ MEMBER_ID integer not null references ADDRESSBOOK_OBJECT,                                                -- member AddressBook Object's RESOURCE_ID
+
+ primary key (GROUP_ID, MEMBER_ID) -- implicit index
+);
+
+create index ABO_MEMBERS_ADDRESSBOOK_ID on
+        ABO_MEMBERS(ADDRESSBOOK_ID);
+create index ABO_MEMBERS_MEMBER_ID on
+        ABO_MEMBERS(MEMBER_ID);
+
+------------------------------------------
+-- Address Book Object Foreign Members --
+------------------------------------------
+
+create table ABO_FOREIGN_MEMBERS (
+ GROUP_ID integer not null references ADDRESSBOOK_OBJECT on delete cascade,        -- AddressBook Object's (kind=='group') RESOURCE_ID
+         ADDRESSBOOK_ID                 integer not null references ADDRESSBOOK_HOME on delete cascade,
+ MEMBER_ADDRESS          varchar(255) not null,                                                                                                         -- member AddressBook Object's 'calendar' address
+
+ primary key (GROUP_ID, MEMBER_ADDRESS) -- implicit index
+);
+
+create index ABO_FOREIGN_MEMBERS_ADDRESSBOOK_ID on
+        ABO_FOREIGN_MEMBERS(ADDRESSBOOK_ID);
+
+-----------------------
+-- Shared Group Bind --
+-----------------------
+
+-- Joins ADDRESSBOOK_HOME and ADDRESSBOOK_OBJECT (kind == group)
+
+create table SHARED_GROUP_BIND (        
+ ADDRESSBOOK_HOME_RESOURCE_ID                 integer not null references ADDRESSBOOK_HOME,
+ GROUP_RESOURCE_ID                         integer not null references ADDRESSBOOK_OBJECT on delete cascade,
+ GROUP_ADDRESSBOOK_NAME                        varchar(255) not null,
+ BIND_MODE                 integer not null, -- enum CALENDAR_BIND_MODE
+ BIND_STATUS                 integer not null, -- enum CALENDAR_BIND_STATUS
+ BIND_REVISION                                                 integer default 0 not null,
+ MESSAGE                 text, -- FIXME: xml?
+
+ primary key (ADDRESSBOOK_HOME_RESOURCE_ID, GROUP_RESOURCE_ID), -- implicit index
+ unique (ADDRESSBOOK_HOME_RESOURCE_ID, GROUP_ADDRESSBOOK_NAME) -- implicit index
+);
+
+create index SHARED_GROUP_BIND_RESOURCE_ID on
+ SHARED_GROUP_BIND(GROUP_RESOURCE_ID);
+
+
+---------------
+-- Revisions --
+---------------
+
+create sequence REVISION_SEQ;
+
+
+-------------------------------
+-- Calendar Object Revisions --
+-------------------------------
+
+create table CALENDAR_OBJECT_REVISIONS (
+ CALENDAR_HOME_RESOURCE_ID integer not null references CALENDAR_HOME,
+ CALENDAR_RESOURCE_ID integer references CALENDAR,
+ CALENDAR_NAME varchar(255) default null,
+ RESOURCE_NAME varchar(255),
+ REVISION integer default nextval('REVISION_SEQ') not null,
+ DELETED boolean not null
+);
+
+create index CALENDAR_OBJECT_REVISIONS_HOME_RESOURCE_ID_CALENDAR_RESOURCE_ID
+ on CALENDAR_OBJECT_REVISIONS(CALENDAR_HOME_RESOURCE_ID, CALENDAR_RESOURCE_ID);
+
+create index CALENDAR_OBJECT_REVISIONS_RESOURCE_ID_RESOURCE_NAME_DELETED_REVISION
+ on CALENDAR_OBJECT_REVISIONS(CALENDAR_RESOURCE_ID, RESOURCE_NAME, DELETED, REVISION);
+
+create index CALENDAR_OBJECT_REVISIONS_RESOURCE_ID_REVISION
+ on CALENDAR_OBJECT_REVISIONS(CALENDAR_RESOURCE_ID, REVISION);
+
+
+----------------------------------
+-- AddressBook Object Revisions --
+----------------------------------
+
+create table ADDRESSBOOK_OBJECT_REVISIONS (
+ ADDRESSBOOK_HOME_RESOURCE_ID                         integer                        not null references ADDRESSBOOK_HOME,
+ OWNER_HOME_RESOURCE_ID                         integer         references ADDRESSBOOK_HOME,
+ ADDRESSBOOK_NAME                         varchar(255)         default null,
+ RESOURCE_NAME                         varchar(255),
+ REVISION                         integer         default nextval('REVISION_SEQ') not null,
+ DELETED                         boolean         not null
+);
+
+create index ADDRESSBOOK_OBJECT_REVISIONS_HOME_RESOURCE_ID_OWNER_HOME_RESOURCE_ID
+ on ADDRESSBOOK_OBJECT_REVISIONS(ADDRESSBOOK_HOME_RESOURCE_ID, OWNER_HOME_RESOURCE_ID);
+
+create index ADDRESSBOOK_OBJECT_REVISIONS_OWNER_HOME_RESOURCE_ID_RESOURCE_NAME_DELETED_REVISION
+ on ADDRESSBOOK_OBJECT_REVISIONS(OWNER_HOME_RESOURCE_ID, RESOURCE_NAME, DELETED, REVISION);
+
+create index ADDRESSBOOK_OBJECT_REVISIONS_OWNER_HOME_RESOURCE_ID_REVISION
+ on ADDRESSBOOK_OBJECT_REVISIONS(OWNER_HOME_RESOURCE_ID, REVISION);
+
+
+-----------------------------------
+-- Notification Object Revisions --
+-----------------------------------
+
+create table NOTIFICATION_OBJECT_REVISIONS (
+ NOTIFICATION_HOME_RESOURCE_ID integer not null references NOTIFICATION_HOME on delete cascade,
+ RESOURCE_NAME varchar(255),
+ REVISION integer default nextval('REVISION_SEQ') not null,
+ DELETED boolean not null,
+
+ unique(NOTIFICATION_HOME_RESOURCE_ID, RESOURCE_NAME) -- implicit index
+);
+
+create index NOTIFICATION_OBJECT_REVISIONS_RESOURCE_ID_REVISION
+ on NOTIFICATION_OBJECT_REVISIONS(NOTIFICATION_HOME_RESOURCE_ID, REVISION);
+
+
+-------------------------------------------
+-- Apple Push Notification Subscriptions --
+-------------------------------------------
+
+create table APN_SUBSCRIPTIONS (
+ TOKEN varchar(255) not null,
+ RESOURCE_KEY varchar(255) not null,
+ MODIFIED integer not null,
+ SUBSCRIBER_GUID varchar(255) not null,
+ USER_AGENT varchar(255) default null,
+ IP_ADDR varchar(255) default null,
+
+ primary key (TOKEN, RESOURCE_KEY) -- implicit index
+);
+
+create index APN_SUBSCRIPTIONS_RESOURCE_KEY
+ on APN_SUBSCRIPTIONS(RESOURCE_KEY);
+
+
+-----------------
+-- IMIP Tokens --
+-----------------
+
+create table IMIP_TOKENS (
+ TOKEN varchar(255) not null,
+ ORGANIZER varchar(255) not null,
+ ATTENDEE varchar(255) not null,
+ ICALUID varchar(255) not null,
+ ACCESSED timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+
+ primary key (ORGANIZER, ATTENDEE, ICALUID) -- implicit index
+);
+
+create index IMIP_TOKENS_TOKEN
+ on IMIP_TOKENS(TOKEN);
+
+
+----------------
+-- Work Items --
+----------------
+
+create sequence WORKITEM_SEQ;
+
+
+---------------------------
+-- IMIP Inivitation Work --
+---------------------------
+
+create table IMIP_INVITATION_WORK (
+ WORK_ID integer primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+ NOT_BEFORE timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+ FROM_ADDR varchar(255) not null,
+ TO_ADDR varchar(255) not null,
+ ICALENDAR_TEXT text not null
+);
+
+
+-----------------------
+-- IMIP Polling Work --
+-----------------------
+
+create table IMIP_POLLING_WORK (
+ WORK_ID integer primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+ NOT_BEFORE timestamp default timezone('UTC', CURRENT_TIMESTAMP)
+);
+
+
+---------------------
+-- IMIP Reply Work --
+---------------------
+
+create table IMIP_REPLY_WORK (
+ WORK_ID integer primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+ NOT_BEFORE timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+ ORGANIZER varchar(255) not null,
+ ATTENDEE varchar(255) not null,
+ ICALENDAR_TEXT text not null
+);
+
+
+------------------------
+-- Push Notifications --
+------------------------
+
+create table PUSH_NOTIFICATION_WORK (
+ WORK_ID integer primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+ NOT_BEFORE timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+ PUSH_ID varchar(255) not null,
+ PRIORITY integer not null -- 1:low 5:medium 10:high
+);
+
+-----------------
+-- GroupCacher --
+-----------------
+
+create table GROUP_CACHER_POLLING_WORK (
+ WORK_ID integer primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+ NOT_BEFORE timestamp default timezone('UTC', CURRENT_TIMESTAMP)
+);
+
+
+--------------------------
+-- Object Splitter Work --
+--------------------------
+
+create table CALENDAR_OBJECT_SPLITTER_WORK (
+ WORK_ID integer primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
+ NOT_BEFORE timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+ RESOURCE_ID integer not null references CALENDAR_OBJECT on delete cascade
+);
+
+create index CALENDAR_OBJECT_SPLITTER_WORK_RESOURCE_ID on
+        CALENDAR_OBJECT_SPLITTER_WORK(RESOURCE_ID);
+
+--------------------
+-- Schema Version --
+--------------------
+
+create table CALENDARSERVER (
+ NAME varchar(255) primary key, -- implicit index
+ VALUE varchar(255)
+);
+
+insert into CALENDARSERVER values ('VERSION', '28');
+insert into CALENDARSERVER values ('CALENDAR-DATAVERSION', '5');
+insert into CALENDARSERVER values ('ADDRESSBOOK-DATAVERSION', '2');
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresql_schemaupgradesoracledialectupgrade_from_28_to_29sqlfromrev12016CalendarServerbranchesuserscdaboosharinginthestoretxdavcommondatastoresql_schemaupgradesoracledialectupgrade_from_28_to_29sql"></a>
<div class="copfile"><h4>Copied: CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_28_to_29.sql (from rev 12016, CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_28_to_29.sql) (0 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_28_to_29.sql         (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_28_to_29.sql        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -0,0 +1,38 @@
</span><ins>+----
+-- Copyright (c) 2012-2013 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.
+----
+
+---------------------------------------------------
+-- Upgrade database schema from VERSION 28 to 29 --
+---------------------------------------------------
+
+-- Sharing notification related updates
+
+alter table NOTIFICATION_HOME
+ add ("DATAVERSION" integer default 0 not null);
+
+alter table NOTIFICATION
+ rename column XML_TYPE to NOTIFICATION_TYPE;
+alter table NOTIFICATION
+ rename column XML_DATA to NOTIFICATION_DATA;
+
+ -- Sharing enumeration updates
+insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('indirect', 4);
+
+insert into CALENDAR_BIND_STATUS (DESCRIPTION, ID) values ('deleted', 4);
+
+-- Now update the version
+update CALENDARSERVER set VALUE = '29' where NAME = 'VERSION';
+insert into CALENDARSERVER (NAME, VALUE) values ('NOTIFICATION-DATAVERSION', '1');
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresql_schemaupgradespostgresdialectupgrade_from_28_to_29sqlfromrev12016CalendarServerbranchesuserscdaboosharinginthestoretxdavcommondatastoresql_schemaupgradespostgresdialectupgrade_from_28_to_29sql"></a>
<div class="copfile"><h4>Copied: CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_28_to_29.sql (from rev 12016, CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_28_to_29.sql) (0 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_28_to_29.sql         (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_28_to_29.sql        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -0,0 +1,38 @@
</span><ins>+----
+-- Copyright (c) 2012-2013 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.
+----
+
+---------------------------------------------------
+-- Upgrade database schema from VERSION 28 to 29 --
+---------------------------------------------------
+
+-- Sharing notification related updates
+
+alter table NOTIFICATION_HOME
+ add column DATAVERSION integer default 0 not null;
+
+alter table NOTIFICATION
+ rename column XML_TYPE to NOTIFICATION_TYPE;
+alter table NOTIFICATION
+ rename column XML_DATA to NOTIFICATION_DATA;
+
+-- Sharing enumeration updates
+insert into CALENDAR_BIND_MODE values (4, 'indirect');
+
+insert into CALENDAR_BIND_STATUS values (4, 'deleted');
+
+-- Now update the version
+update CALENDARSERVER set VALUE = '29' where NAME = 'VERSION';
+insert into CALENDARSERVER values ('NOTIFICATION-DATAVERSION', '1');
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresql_tablespy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/sql_tables.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_tables.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/txdav/common/datastore/sql_tables.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -142,6 +142,7 @@
</span><span class="cx"> _BIND_STATUS_ACCEPTED = _bindStatus('accepted')
</span><span class="cx"> _BIND_STATUS_DECLINED = _bindStatus('declined')
</span><span class="cx"> _BIND_STATUS_INVALID = _bindStatus('invalid')
</span><ins>+_BIND_STATUS_DELETED = _bindStatus('deleted')
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> _transpValues = _schemaConstants(
</span><span class="lines">@@ -173,6 +174,7 @@
</span><span class="cx"> _BIND_MODE_READ = _bindMode('read')
</span><span class="cx"> _BIND_MODE_WRITE = _bindMode('write')
</span><span class="cx"> _BIND_MODE_DIRECT = _bindMode('direct')
</span><ins>+_BIND_MODE_INDIRECT = _bindMode('indirect')
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> _addressBookObjectKind = _schemaConstants(
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoretestutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/test/util.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/test/util.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/txdav/common/datastore/test/util.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -707,7 +707,36 @@
</span><span class="cx"> .calendarObjectWithName(name)))
</span><span class="cx">
</span><span class="cx">
</span><ins>+ def addressbookHomeUnderTest(self, txn=None, name="home1"):
+ """
+ Get the addressbook home detailed by C{requirements['home1']}.
+ """
+ if txn is None:
+ txn = self.transactionUnderTest()
+ return txn.addressbookHomeWithUID(name)
</ins><span class="cx">
</span><ins>+
+ @inlineCallbacks
+ def addressbookUnderTest(self, txn=None, name="addressbook", home="home1"):
+ """
+ Get the addressbook detailed by C{requirements['home1']['addressbook']}.
+ """
+ returnValue((yield
+ (yield self.addressbookHomeUnderTest(txn=txn, name=home)).addressbookWithName(name))
+ )
+
+
+ @inlineCallbacks
+ def addressbookObjectUnderTest(self, txn=None, name="1.vcf", addressbook_name="addressbook", home="home1"):
+ """
+ Get the addressbook detailed by
+ C{requirements['home1']['addressbook']['1.vcf']}.
+ """
+ returnValue((yield (yield self.addressbookUnderTest(txn=txn, name=addressbook_name, home=home))
+ .addressbookObjectWithName(name)))
+
+
+
</ins><span class="cx"> class StubNotifierFactory(object):
</span><span class="cx"> """
</span><span class="cx"> For testing push notifications without an XMPP server.
</span><span class="lines">@@ -726,7 +755,7 @@
</span><span class="cx"> return "/%s/%s/%s/" % (prefix, self.hostname, id)
</span><span class="cx">
</span><span class="cx">
</span><del>- def send(self, prefix, id, txn, priority):
</del><ins>+ def send(self, prefix, id, txn, priority):
</ins><span class="cx"> self.history.append((self.pushKeyForId(prefix, id), priority))
</span><span class="cx">
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoreupgradesqlupgradepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrade.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrade.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrade.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -414,6 +414,34 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><ins>+class UpgradeDatabaseNotificationDataStep(_UpgradeDatabaseDataStep):
+ """
+ Checks and upgrades the database data. This assumes there are a bunch of
+ upgrade python modules that we can execute against the database to
+ accomplish the upgrade.
+
+ @ivar sqlStore: The store to operate on.
+
+ @type sqlStore: L{txdav.idav.IDataStore}
+ """
+
+ def __init__(self, sqlStore, **kwargs):
+ """
+ Initialize the service.
+
+ @param sqlStore: The store to operate on. Can be C{None} when doing unit tests.
+ @param service: Wrapped service. Can be C{None} when doing unit tests.
+ """
+ super(UpgradeDatabaseNotificationDataStep, self).__init__(sqlStore, **kwargs)
+
+ self.versionKey = "NOTIFICATION-DATAVERSION"
+ self.versionDescriptor = "notification data"
+ self.upgradeFilePrefix = "notification_"
+ self.upgradeFileSuffix = ".py"
+ self.defaultKeyValue = 0
+
+
+
</ins><span class="cx"> class UpgradeDatabaseOtherStep(UpgradeDatabaseCoreStep):
</span><span class="cx"> """
</span><span class="cx"> Do any other upgrade behaviors once all the schema, data, file migration upgraders
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoreupgradesqlupgradesnotification_upgrade_from_0_to_1pyfromrev12016CalendarServerbranchesuserscdaboosharinginthestoretxdavcommondatastoreupgradesqlupgradesnotification_upgrade_from_0_to_1py"></a>
<div class="copfile"><h4>Copied: CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/notification_upgrade_from_0_to_1.py (from rev 12016, CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/upgrade/sql/upgrades/notification_upgrade_from_0_to_1.py) (0 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/notification_upgrade_from_0_to_1.py         (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/notification_upgrade_from_0_to_1.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -0,0 +1,165 @@
</span><ins>+# -*- test-case-name: txdav.common.datastore.upgrade.sql.test -*-
+##
+# Copyright (c) 2013 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.
+##
+
+from twisted.internet.defer import inlineCallbacks
+
+from twistedcaldav import caldavxml, customxml
+from twistedcaldav.config import config
+
+from txdav.common.datastore.sql_tables import schema, _BIND_STATUS_INVITED
+from txdav.common.datastore.upgrade.sql.upgrades.util import updateNotificationDataVersion, \
+ doToEachHomeNotAtVersion
+from txdav.xml import element
+from txdav.xml.parser import WebDAVDocument
+from twistedcaldav.sharing import invitationBindStatusFromXMLMap, \
+ invitationBindModeFromXMLMap
+
+"""
+Data upgrade from database version 0 to 1
+"""
+
+UPGRADE_TO_VERSION = 1
+
+@inlineCallbacks
+def doUpgrade(sqlStore):
+ """
+ Do the required upgrade steps.
+ """
+ yield updateNotificationHomes(sqlStore, config.UpgradeHomePrefix)
+
+ # Don't do remaining upgrade if we are only process a subset of the homes
+ if not config.UpgradeHomePrefix:
+ # Always bump the DB value
+ yield updateNotificationDataVersion(sqlStore, UPGRADE_TO_VERSION)
+
+
+
+@inlineCallbacks
+def updateNotificationHomes(sqlStore, prefix=None):
+ """
+ For each calendar home, update the associated properties on the home or its owned calendars.
+ """
+
+ yield doToEachHomeNotAtVersion(sqlStore, schema.NOTIFICATION_HOME, UPGRADE_TO_VERSION, updateNotificationHome, "Update Notification Home", filterOwnerUID=prefix)
+
+
+
+@inlineCallbacks
+def updateNotificationHome(txn, homeResourceID):
+ """
+ For this notification home, update the associated child resources.
+ """
+
+ home = yield txn.notificationsWithResourceID(homeResourceID)
+ notifications = (yield home.notificationObjects())
+ for notification in notifications:
+ yield updateNotification(txn, notification)
+
+
+
+@inlineCallbacks
+def updateNotification(txn, notification):
+ """
+ For this notification home, update the associated child resources.
+ """
+
+ # Convert the type value to JSON
+ xmltype = WebDAVDocument.fromString(notification.notificationType()).root_element
+ shared_type = "calendar"
+ if xmltype.children[0].qname() == customxml.InviteNotification.qname():
+ jsontype = {"notification-type": "invite-notification"}
+ if "shared-type" in xmltype.children[0].attributes:
+ shared_type = xmltype.children[0].attributes["shared-type"]
+ jsontype["shared-type"] = shared_type
+ elif xmltype.children[0].qname() == customxml.InviteReply.qname():
+ jsontype = {"notification-type": "invite-reply"}
+
+ # Convert the data value to JSON
+ xmldata = (yield notification.notificationData())
+ xmldata = WebDAVDocument.fromString(xmldata).root_element
+
+ def _extract_UID(uri):
+ if uri.startswith("urn:uuid:"):
+ return uri[len("urn:uuid:"):]
+ elif uri[0] == "/":
+ return uri.rstrip("/").split("/")[-1]
+ elif uri.startswith("mailto:"):
+ return uri[7:].split("@")[0]
+ else:
+ return ""
+
+ if xmldata.childOfType(customxml.InviteNotification) is not None:
+ ntype = xmldata.childOfType(customxml.InviteNotification)
+ dtstamp = str(xmldata.childOfType(customxml.DTStamp))
+ owner = _extract_UID(str(ntype.childOfType(customxml.Organizer).childOfType(element.HRef)))
+ sharee = _extract_UID(str(ntype.childOfType(element.HRef)))
+ uid = str(ntype.childOfType(customxml.UID))
+ for xml in invitationBindStatusFromXMLMap.keys():
+ if ntype.childOfType(xml) is not None:
+ state = invitationBindStatusFromXMLMap[xml]
+ break
+ else:
+ state = _BIND_STATUS_INVITED
+ mode = invitationBindModeFromXMLMap[type(ntype.childOfType(customxml.InviteAccess).children[0])]
+ name = str(ntype.childOfType(customxml.HostURL).childOfType(element.HRef)).rstrip("/").split("/")[-1]
+ summary = str(ntype.childOfType(customxml.InviteSummary))
+
+ jsondata = {
+ "notification-type": "invite-notification",
+ "shared-type": shared_type,
+ "dtstamp": dtstamp,
+ "owner": owner,
+ "sharee": sharee,
+ "uid": uid,
+ "status": state,
+ "access": mode,
+ "name": name,
+ "summary": summary,
+ }
+ if ntype.childOfType(caldavxml.SupportedCalendarComponentSet):
+ comps = [child.attributes["name"] for child in ntype.childOfType(caldavxml.SupportedCalendarComponentSet).children]
+ jsondata["supported-components"] = ",".join(comps)
+
+ elif xmldata.childOfType(customxml.InviteReply) is not None:
+ ntype = xmldata.childOfType(customxml.InviteReply)
+ dtstamp = str(xmldata.childOfType(customxml.DTStamp))
+ sharee = _extract_UID(str(ntype.childOfType(element.HRef)))
+ for xml in invitationBindStatusFromXMLMap.keys():
+ if ntype.childOfType(xml) is not None:
+ state = invitationBindStatusFromXMLMap[xml]
+ break
+ else:
+ state = _BIND_STATUS_INVITED
+ name = str(ntype.childOfType(customxml.HostURL).childOfType(element.HRef)).rstrip("/").split("/")[-1]
+ inreplyto = str(ntype.childOfType(customxml.InReplyTo))
+ summary = str(ntype.childOfType(customxml.InviteSummary)) if ntype.childOfType(customxml.InviteSummary) is not None else ""
+
+ owner = str(ntype.childOfType(customxml.HostURL).childOfType(element.HRef)).rstrip("/").split("/")[-2]
+
+ jsondata = {
+ "notification-type": "invite-reply",
+ "shared-type": shared_type,
+ "dtstamp": dtstamp,
+ "owner": owner,
+ "sharee": sharee,
+ "status": state,
+ "name": name,
+ "in-reply-to": inreplyto,
+ "summary": summary,
+ }
+
+ yield notification.setData(notification.uid(), jsontype, jsondata)
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoreupgradesqlupgradestesttest_notification_upgrade_from_0_to_1pyfromrev12016CalendarServerbranchesuserscdaboosharinginthestoretxdavcommondatastoreupgradesqlupgradestesttest_notification_upgrade_from_0_to_1py"></a>
<div class="copfile"><h4>Copied: CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/test/test_notification_upgrade_from_0_to_1.py (from rev 12016, CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/upgrade/sql/upgrades/test/test_notification_upgrade_from_0_to_1.py) (0 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/test/test_notification_upgrade_from_0_to_1.py         (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/test/test_notification_upgrade_from_0_to_1.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -0,0 +1,194 @@
</span><ins>+##
+# Copyright (c) 2013 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.
+##
+
+from twext.enterprise.dal.syntax import Update
+
+from twisted.internet.defer import inlineCallbacks
+
+from txdav.caldav.datastore.test.util import CommonStoreTests
+from txdav.common.datastore.sql_tables import _BIND_STATUS_INVITED, \
+ _BIND_MODE_WRITE, _BIND_STATUS_ACCEPTED, _BIND_MODE_READ
+from txdav.common.datastore.upgrade.sql.upgrades.notification_upgrade_from_0_to_1 import doUpgrade
+
+"""
+Tests for L{txdav.common.datastore.upgrade.sql.upgrade}.
+"""
+
+class Upgrade_from_0_to_1(CommonStoreTests):
+ """
+ Tests for notification upgrade.
+ """
+
+ @inlineCallbacks
+ def test_upgrade_invite(self):
+
+ data = (
+ (
+ "uid1",
+ """<?xml version='1.0' encoding='UTF-8'?>
+<CS:notification xmlns:CS='http://calendarserver.org/ns/'>
+ <CS:invite-notification shared-type='calendar'/>
+</CS:notification>
+""",
+ {
+ "notification-type": "invite-notification",
+ "shared-type": "calendar",
+ },
+ """<?xml version='1.0' encoding='UTF-8'?>
+<notification xmlns='http://calendarserver.org/ns/'>
+ <dtstamp>20131113T153109Z</dtstamp>
+ <invite-notification shared-type='calendar'>
+ <uid>uid1</uid>
+ <href xmlns='DAV:'>urn:uuid:user02</href>
+ <invite-noresponse/>
+ <access>
+ <read-write/>
+ </access>
+ <hosturl>
+ <href xmlns='DAV:'>/calendars/__uids__/user01/calendar</href>
+ </hosturl>
+ <organizer>
+ <href xmlns='DAV:'>urn:uuid:user01</href>
+ <common-name>User 01</common-name>
+ </organizer>
+ <summary>Shared</summary>
+ <supported-calendar-component-set xmlns='urn:ietf:params:xml:ns:caldav'>
+ <comp name='VEVENT'/>
+ <comp name='VTODO'/>
+ </supported-calendar-component-set>
+ </invite-notification>
+</notification>
+""",
+ {
+ "notification-type": "invite-notification",
+ "shared-type": "calendar",
+ "dtstamp": "20131113T153109Z",
+ "owner": "user01",
+ "sharee": "user02",
+ "uid": "uid1",
+ "status": _BIND_STATUS_INVITED,
+ "access": _BIND_MODE_WRITE,
+ "name": "calendar",
+ "summary": "Shared",
+ "supported-components": "VEVENT,VTODO",
+ },
+ ),
+ (
+ "uid2",
+ """<?xml version='1.0' encoding='UTF-8'?>
+<CS:notification xmlns:CS='http://calendarserver.org/ns/'>
+ <CS:invite-notification shared-type='addressbook'/>
+</CS:notification>
+""",
+ {
+ "notification-type": "invite-notification",
+ "shared-type": "addressbook",
+ },
+ """<?xml version='1.0' encoding='UTF-8'?>
+<notification xmlns='http://calendarserver.org/ns/'>
+ <dtstamp>20131113T153110Z</dtstamp>
+ <invite-notification shared-type='addressbook'>
+ <uid>uid2</uid>
+ <href xmlns='DAV:'>/principals/users/user02/</href>
+ <invite-accepted/>
+ <access>
+ <read/>
+ </access>
+ <hosturl>
+ <href xmlns='DAV:'>/addressbooks/__uids__/user01/addressbook/</href>
+ </hosturl>
+ <organizer>
+ <href xmlns='DAV:'>/principals/users/user01/</href>
+ <common-name>User 01</common-name>
+ </organizer>
+ <summary>Shared 2</summary>
+ </invite-notification>
+</notification>
+""",
+ {
+ "notification-type": "invite-notification",
+ "shared-type": "addressbook",
+ "dtstamp": "20131113T153110Z",
+ "owner": "user01",
+ "sharee": "user02",
+ "uid": "uid2",
+ "status": _BIND_STATUS_ACCEPTED,
+ "access": _BIND_MODE_READ,
+ "name": "addressbook",
+ "summary": "Shared 2",
+ },
+ ),
+ (
+ "uid3",
+ """<?xml version='1.0' encoding='UTF-8'?>
+<CS:notification xmlns:CS='http://calendarserver.org/ns/'>
+ <CS:invite-reply/>
+</CS:notification>
+""",
+ {
+ "notification-type": "invite-reply",
+ },
+ """<?xml version='1.0' encoding='UTF-8'?>
+<notification xmlns='http://calendarserver.org/ns/'>
+ <dtstamp>20131113T153111Z</dtstamp>
+ <invite-reply shared-type='calendar'>
+ <href xmlns='DAV:'>mailto:user02@example.com</href>
+ <invite-accepted/>
+ <hosturl>
+ <href xmlns='DAV:'>/calendars/__uids__/user01/calendar</href>
+ </hosturl>
+ <in-reply-to>uid1</in-reply-to>
+ </invite-reply>
+</notification>
+""",
+ {
+ "notification-type": "invite-reply",
+ "shared-type": "calendar",
+ "dtstamp": "20131113T153111Z",
+ "owner": "user01",
+ "sharee": "user02",
+ "status": _BIND_STATUS_ACCEPTED,
+ "name": "calendar",
+ "in-reply-to": "uid1",
+ "summary": "",
+ },
+ ),
+ )
+
+ for uid, notificationtype, _ignore_jtype, notificationdata, _ignore_jdata in data:
+ notifications = yield self.transactionUnderTest().notificationsWithUID("user01")
+ yield notifications.writeNotificationObject(uid, notificationtype, notificationdata)
+
+ # Force data version to previous
+ nh = notifications._homeSchema
+ yield Update(
+ {nh.DATAVERSION: 0},
+ Where=None,
+ ).on(self.transactionUnderTest())
+
+ yield self.commit()
+ yield doUpgrade(self._sqlCalendarStore)
+
+ notifications = yield self.transactionUnderTest().notificationsWithUID("user01")
+ version = (yield notifications.dataVersion())
+ self.assertEqual(version, 1)
+
+ for uid, _ignore_notificationtype, jtype, _ignore_notificationdata, jdata in data:
+ notification = (yield notifications.notificationObjectWithUID(uid))
+ self.assertTrue(notification is not None, msg="Failed {uid}".format(uid=uid))
+ self.assertEqual(notification.notificationType(), jtype, msg="Failed {uid}".format(uid=uid))
+ data = (yield notification.notificationData())
+ self.assertEqual(data, jdata, msg="Failed {uid}".format(uid=uid))
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoreupgradesqlupgradesutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/util.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/util.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/util.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -128,6 +128,11 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><ins>+def updateNotificationDataVersion(store, version):
+ return _updateDataVersion(store, "NOTIFICATION-DATAVERSION", version)
+
+
+
</ins><span class="cx"> @inlineCallbacks
</span><span class="cx"> def doToEachHomeNotAtVersion(store, homeSchema, version, doIt, logStr, filterOwnerUID=None):
</span><span class="cx"> """
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommoninotificationspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/inotifications.py (12016 => 12017)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/inotifications.py        2013-12-02 19:04:21 UTC (rev 12016)
+++ CalendarServer/trunk/txdav/common/inotifications.py        2013-12-02 20:56:25 UTC (rev 12017)
</span><span class="lines">@@ -72,10 +72,10 @@
</span><span class="cx"> object exists.
</span><span class="cx"> """
</span><span class="cx">
</span><del>- def writeNotificationObject(uid, xmltype, xmldata): #@NoSelf
</del><ins>+ def writeNotificationObject(uid, notificationtype, notificationdata): #@NoSelf
</ins><span class="cx"> """
</span><span class="cx"> Write a notification with the given C{uid} in this notification
</span><del>- collection from the given C{xmldata} with given C{xmltype}. If a
</del><ins>+ collection from the given C{notificationdata} with given C{notificationtype}. If a
</ins><span class="cx"> L{INotificationObject} with the same uid already exists in this
</span><span class="cx"> L{INotificationCollection}, it will be overwritten.
</span><span class="cx">
</span><span class="lines">@@ -83,18 +83,12 @@
</span><span class="cx"> written.
</span><span class="cx"> @type uid: C{str}
</span><span class="cx">
</span><del>- @param xmltype: the node within the notification payload, emptied of
- its children, to indicate the type of notification and fill out the
- C{CS:notificationtype} property.
</del><ins>+ @param notificationtype: the type of notification as a C{dict}.
</ins><span class="cx">
</span><del>- @type xmltype: an instance of
- L{txdav.xml.base.WebDAVElement},
- most likely a subclass like L{twistedcaldav.customxml.InviteReply},
- L{twistedcaldav.customxml.InviteRemove}, etc.
</del><ins>+ @type notificationtype: C{dict}
</ins><span class="cx">
</span><del>- @param xmldata: the serialized representation of the C{CS:notification}
- node.
- @type xmldata: C{str}
</del><ins>+ @param notificationdata: the representation of the notification data as a C{dict}.
+ @type notificationdata: C{dict}
</ins><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> def removeNotificationObjectWithName(name): #@NoSelf
</span><span class="lines">@@ -142,23 +136,23 @@
</span><span class="cx"> An notification object describes an XML notification.
</span><span class="cx"> """
</span><span class="cx">
</span><del>- def setData(uid, xmltype, xmldata, inserting=False): #@NoSelf
</del><ins>+ def setData(uid, notificationtype, notificationdata, inserting=False): #@NoSelf
</ins><span class="cx"> """
</span><del>- Rewrite this notification object to match the given C{xmltype} and
- C{xmldata}. C{xmldata} must have the same UID as this notification object.
</del><ins>+ Rewrite this notification object to match the given C{notificationtype} and
+ C{notificationdata}. C{notificationdata} must have the same UID as this notification object.
</ins><span class="cx">
</span><del>- @param xmltype: a string.
- @param xmldata: a string.
</del><ins>+ @param notificationtype: a string.
+ @param notificationdata: a string.
</ins><span class="cx"> @raise InvalidObjectResourceError: if the given
</span><del>- C{xmltype} or C{xmldata} is not a valid for
</del><ins>+ C{notificationtype} or C{notificationdata} is not a valid for
</ins><span class="cx"> an notification object.
</span><span class="cx"> """
</span><span class="cx">
</span><del>- def xmldata(): #@NoSelf
</del><ins>+ def notificationData(): #@NoSelf
</ins><span class="cx"> """
</span><span class="cx"> Retrieve the notification data for this notification object.
</span><span class="cx">
</span><del>- @return: a string.
</del><ins>+ @return: a C{dict}.
</ins><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> def uid(): #@NoSelf
</span></span></pre>
</div>
</div>
</body>
</html>