[CalendarServer-changes] [12968] CalendarServer/branches/users/sagen/move2who-4
source_changes at macosforge.org
source_changes at macosforge.org
Tue Mar 18 19:32:52 PDT 2014
Revision: 12968
http://trac.calendarserver.org//changeset/12968
Author: sagen at apple.com
Date: 2014-03-18 19:32:52 -0700 (Tue, 18 Mar 2014)
Log Message:
-----------
Allow recordsMatchingFields to restrict to a single recordType; fix other tests.
Modified Paths:
--------------
CalendarServer/branches/users/sagen/move2who-4/conf/auth/accounts-test.xml
CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/method/report.py
CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/sharing.py
CalendarServer/branches/users/sagen/move2who-4/txdav/dps/client.py
CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test.xml
CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test_client.py
CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py
Modified: CalendarServer/branches/users/sagen/move2who-4/conf/auth/accounts-test.xml
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/conf/auth/accounts-test.xml 2014-03-19 01:26:08 UTC (rev 12967)
+++ CalendarServer/branches/users/sagen/move2who-4/conf/auth/accounts-test.xml 2014-03-19 02:32:52 UTC (rev 12968)
@@ -290,6 +290,76 @@
<email>user25 at example.com</email>
</record>
+ <record type="user">
+ <short-name>public01</short-name>
+ <uid>public01</uid>
+ <password>public01</password>
+ <full-name>Public 01</full-name>
+ </record>
+
+ <record type="user">
+ <short-name>public02</short-name>
+ <uid>public02</uid>
+ <password>public02</password>
+ <full-name>Public 02</full-name>
+ </record>
+
+ <record type="user">
+ <short-name>public03</short-name>
+ <uid>public03</uid>
+ <password>public03</password>
+ <full-name>Public 03</full-name>
+ </record>
+
+ <record type="user">
+ <short-name>public04</short-name>
+ <uid>public04</uid>
+ <password>public04</password>
+ <full-name>Public 04</full-name>
+ </record>
+
+ <record type="user">
+ <short-name>public05</short-name>
+ <uid>public05</uid>
+ <password>public05</password>
+ <full-name>Public 05</full-name>
+ </record>
+
+ <record type="user">
+ <short-name>public06</short-name>
+ <uid>public06</uid>
+ <password>public06</password>
+ <full-name>Public 06</full-name>
+ </record>
+
+ <record type="user">
+ <short-name>public07</short-name>
+ <uid>public07</uid>
+ <password>public07</password>
+ <full-name>Public 07</full-name>
+ </record>
+
+ <record type="user">
+ <short-name>public08</short-name>
+ <uid>public08</uid>
+ <password>public08</password>
+ <full-name>Public 08</full-name>
+ </record>
+
+ <record type="user">
+ <short-name>public09</short-name>
+ <uid>public09</uid>
+ <password>public09</password>
+ <full-name>Public 09</full-name>
+ </record>
+
+ <record type="user">
+ <short-name>public10</short-name>
+ <uid>public10</uid>
+ <password>public10</password>
+ <full-name>Public 10</full-name>
+ </record>
+
<record type="group">
<uid>group01</uid>
<short-name>group01</short-name>
Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/method/report.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/method/report.py 2014-03-19 01:26:08 UTC (rev 12967)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/method/report.py 2014-03-19 02:32:52 UTC (rev 12968)
@@ -43,6 +43,7 @@
log = Logger()
+
@inlineCallbacks
def http_REPORT(self, request):
"""
@@ -58,7 +59,7 @@
try:
doc = (yield davXMLFromStream(request.stream))
except ValueError, e:
- log.error("Error while handling REPORT body: %s" % (e,))
+ log.error("Error while handling REPORT body: {err}", err=str(e))
raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
if doc is None:
Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/sharing.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/sharing.py 2014-03-19 01:26:08 UTC (rev 12967)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/sharing.py 2014-03-19 02:32:52 UTC (rev 12968)
@@ -62,24 +62,25 @@
"""
if config.Sharing.Enabled:
+ @inlineCallbacks
def invitePropertyElement(invitation, includeUID=True):
userid = "urn:uuid:" + invitation.shareeUID
- principal = self.principalForUID(invitation.shareeUID)
+ principal = yield self.principalForUID(invitation.shareeUID)
cn = principal.displayName() if principal else invitation.shareeUID
- return customxml.InviteUser(
+ returnValue(customxml.InviteUser(
customxml.UID.fromString(invitation.uid) if includeUID else None,
element.HRef.fromString(userid),
customxml.CommonName.fromString(cn),
customxml.InviteAccess(invitationBindModeToXMLMap[invitation.mode]()),
invitationBindStatusToXMLMap[invitation.status](),
- )
+ ))
# See if this property is on the shared calendar
if self.isShared():
invitations = yield self.validateInvites(request)
returnValue(customxml.Invite(
- *[invitePropertyElement(invitation) for invitation in invitations]
+ *[(yield invitePropertyElement(invitation)) for invitation in invitations]
))
# See if it is on the sharee calendar
@@ -89,7 +90,7 @@
invitations = yield original.allInvitations()
invitations = yield self.validateInvites(request, invitations)
- ownerPrincipal = self.principalForUID(self._newStoreObject.ownerHome().uid())
+ ownerPrincipal = yield self.principalForUID(self._newStoreObject.ownerHome().uid())
# FIXME: use urn:uuid in all cases
if self.isCalendarCollection():
owner = ownerPrincipal.principalURL()
@@ -102,7 +103,7 @@
element.HRef.fromString(owner),
customxml.CommonName.fromString(ownerCN),
),
- *[invitePropertyElement(invitation, includeUID=False) for invitation in invitations]
+ *[(yield invitePropertyElement(invitation, includeUID=False)) for invitation in invitations]
))
returnValue(None)
@@ -266,8 +267,8 @@
any access at all.
"""
if self._newStoreObject.direct():
- owner = self.principalForUID(self._newStoreObject.ownerHome().uid())
- sharee = self.principalForUID(self._newStoreObject.viewerHome().uid())
+ owner = yield self.principalForUID(self._newStoreObject.ownerHome().uid())
+ sharee = yield self.principalForUID(self._newStoreObject.viewerHome().uid())
if owner.record.recordType == WikiDirectoryService.recordType_wikis:
# Access level comes from what the wiki has granted to the
# sharee
@@ -320,7 +321,7 @@
assert self._isShareeResource, "Only call this for a sharee resource"
assert self.isCalendarCollection() or self.isAddressBookCollection(), "Only call this for a address book or calendar resource"
- sharee = self.principalForUID(self._newStoreObject.viewerHome().uid())
+ sharee = yield self.principalForUID(self._newStoreObject.viewerHome().uid())
access = yield self._checkAccessControl()
if access == "original" and not self._newStoreObject.ownerHome().external():
@@ -411,7 +412,7 @@
"""
# First try to resolve as a principal
- principal = self.principalForCalendarUserAddress(userid)
+ principal = yield self.principalForCalendarUserAddress(userid)
if principal:
if request:
ownerPrincipal = (yield self.ownerPrincipal(request))
@@ -504,7 +505,7 @@
def inviteSingleUserToShare(self, userid, cn, ace, summary, request): #@UnusedVariable
# We currently only handle local users
- sharee = self.principalForCalendarUserAddress(userid)
+ sharee = yield self.principalForCalendarUserAddress(userid)
if not sharee:
returnValue(False)
@@ -521,7 +522,7 @@
def uninviteSingleUserFromShare(self, userid, aces, request): #@UnusedVariable
# Cancel invites - we'll just use whatever userid we are given
- sharee = self.principalForCalendarUserAddress(userid)
+ sharee = yield self.principalForCalendarUserAddress(userid)
if not sharee:
returnValue(False)
Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/dps/client.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/dps/client.py 2014-03-19 01:26:08 UTC (rev 12967)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/dps/client.py 2014-03-19 02:32:52 UTC (rev 12968)
@@ -191,7 +191,7 @@
# MOVE2WHO, REMOVE THIS HACK TOO:
if not isinstance(shortName, unicode):
- log.warn("Need to change shortName to unicode")
+ # log.warn("Need to change shortName to unicode")
shortName = shortName.decode("utf-8")
@@ -206,7 +206,7 @@
def recordWithUID(self, uid):
# MOVE2WHO, REMOVE THIS:
if not isinstance(uid, unicode):
- log.warn("Need to change uid to unicode")
+ # log.warn("Need to change uid to unicode")
uid = uid.decode("utf-8")
return self._call(
Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test.xml
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test.xml 2014-03-19 01:26:08 UTC (rev 12967)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test.xml 2014-03-19 02:32:52 UTC (rev 12968)
@@ -114,4 +114,10 @@
<member-uid>__alyssa__</member-uid>
</record>
+ <record type="location">
+ <uid>__sanchezoffice__</uid>
+ <short-name>sanchezoffice</short-name>
+ <full-name>Sanchez Office</full-name>
+ </record>
+
</directory>
Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test_client.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test_client.py 2014-03-19 01:26:08 UTC (rev 12967)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test_client.py 2014-03-19 02:32:52 UTC (rev 12968)
@@ -16,6 +16,7 @@
import os
+from twext.who.expression import Operand, MatchType, MatchFlags
from twext.who.idirectory import RecordType
from twisted.cred.credentials import calcResponse, calcHA1, calcHA2
from twisted.internet.defer import inlineCallbacks, succeed
@@ -147,6 +148,41 @@
@inlineCallbacks
+ def test_recordsMatchingFields_anyType(self):
+ fields = (
+ (u"fullNames", "anche", MatchFlags.caseInsensitive, MatchType.contains),
+ )
+ records = (yield self.directory.recordsMatchingFields(
+ fields, operand=Operand.OR, recordType=None
+ ))
+ matchingShortNames = set()
+ for r in records:
+ for shortName in r.shortNames:
+ matchingShortNames.add(shortName)
+ self.assertTrue("dre" in matchingShortNames)
+ self.assertTrue("wsanchez" in matchingShortNames)
+ self.assertTrue("sanchezoffice" in matchingShortNames)
+
+
+ @inlineCallbacks
+ def test_recordsMatchingFields_oneType(self):
+ fields = (
+ (u"fullNames", "anche", MatchFlags.caseInsensitive, MatchType.contains),
+ )
+ records = (yield self.directory.recordsMatchingFields(
+ fields, operand=Operand.OR, recordType=RecordType.user
+ ))
+ matchingShortNames = set()
+ for r in records:
+ for shortName in r.shortNames:
+ matchingShortNames.add(shortName)
+ self.assertTrue("dre" in matchingShortNames)
+ self.assertTrue("wsanchez" in matchingShortNames)
+ # This location should *not* appear in the results
+ self.assertFalse("sanchezoffice" in matchingShortNames)
+
+
+ @inlineCallbacks
def test_verifyPlaintextPassword(self):
expectations = (
(testPassword, True), # Correct
Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py 2014-03-19 01:26:08 UTC (rev 12967)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py 2014-03-19 02:32:52 UTC (rev 12968)
@@ -142,6 +142,22 @@
subExpressions.append(subExpression)
expression = CompoundExpression(subExpressions, operand)
+
+ # AND in the recordType if passed in
+ if recordType is not None:
+ typeExpression = MatchExpression(
+ self.fieldName.recordType,
+ recordType,
+ MatchType.equals,
+ MatchFlags.none
+ )
+ expression = CompoundExpression(
+ [
+ expression,
+ typeExpression
+ ],
+ Operand.AND
+ )
return self.recordsFromExpression(expression)
@@ -289,7 +305,7 @@
self.__class__.__name__,
self.service.realmName,
self.recordType.name,
- self.shortNames,
+ # self.shortNames, # MOVE2WHO FIXME: is this needed? it's not hashable
self.uid,
self.hasCalendars,
))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140318/8df88711/attachment-0001.html>
More information about the calendarserver-changes
mailing list