[CalendarServer-changes] [14122] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Wed Oct 29 13:28:29 PDT 2014
Revision: 14122
http://trac.calendarserver.org//changeset/14122
Author: sagen at apple.com
Date: 2014-10-29 13:28:29 -0700 (Wed, 29 Oct 2014)
Log Message:
-----------
csmp --search now can use multiple tokens; adds --context for limiting record types
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/principals.py
CalendarServer/trunk/calendarserver/tools/test/principals/users-groups.xml
CalendarServer/trunk/calendarserver/tools/test/test_principals.py
CalendarServer/trunk/txdav/who/groups.py
Modified: CalendarServer/trunk/calendarserver/tools/principals.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/principals.py 2014-10-29 16:57:26 UTC (rev 14121)
+++ CalendarServer/trunk/calendarserver/tools/principals.py 2014-10-29 20:28:29 UTC (rev 14122)
@@ -71,7 +71,8 @@
print(" -v --verbose: print debugging information")
print("")
print("actions:")
- print(" --search <search-string>: search for matching principals")
+ print(" --context <search-context>: {user|group|location|resource|attendee}; must be used in conjunction with --search")
+ print(" --search <search-tokens>: search using one or more tokens")
print(" --list-principal-types: list all of the known principal types")
print(" --list-principals type: list all principals of the given type")
print(" --list-read-proxies: list proxies with read-only access")
@@ -129,7 +130,8 @@
"config=",
"add=",
"remove",
- "search=",
+ "context=",
+ "search",
"list-principal-types",
"list-principals=",
@@ -175,7 +177,8 @@
addType = None
listPrincipalTypes = False
listPrincipals = None
- searchPrincipals = None
+ searchContext = None
+ searchTokens = None
printGroupInfo = False
scheduleGroupRefresh = False
principalActions = []
@@ -207,8 +210,11 @@
elif opt in ("", "--list-principals"):
listPrincipals = arg
+ elif opt in ("", "--context"):
+ searchContext = arg
+
elif opt in ("", "--search"):
- searchPrincipals = arg
+ searchTokens = args
elif opt in ("", "--list-read-proxies"):
principalActions.append((action_listProxies, "read"))
@@ -356,9 +362,10 @@
function = runListPrincipals
params = (listPrincipals,)
- elif searchPrincipals:
+ elif searchTokens:
function = runSearch
- params = (searchPrincipals,)
+ searchTokens = [t.decode("utf-8") for t in searchTokens]
+ params = (searchTokens, searchContext)
else:
if not args:
@@ -420,13 +427,16 @@
@inlineCallbacks
-def runSearch(service, store, searchTerm):
+def runSearch(service, store, tokens, context=None):
directory = store.directoryService()
- fields = []
- for fieldName in ("fullNames", "emailAddresses"):
- fields.append((fieldName, searchTerm, True, "contains"))
- records = list((yield directory.recordsMatchingTokens(searchTerm.strip().split())))
+ records = list(
+ (
+ yield directory.recordsMatchingTokens(
+ tokens, context=context
+ )
+ )
+ )
if records:
records.sort(key=operator.attrgetter('fullNames'))
print("{n} matches found:".format(n=len(records)))
Modified: CalendarServer/trunk/calendarserver/tools/test/principals/users-groups.xml
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/principals/users-groups.xml 2014-10-29 16:57:26 UTC (rev 14121)
+++ CalendarServer/trunk/calendarserver/tools/test/principals/users-groups.xml 2014-10-29 20:28:29 UTC (rev 14122)
@@ -99,6 +99,14 @@
<email>user10 at example.com</email>
</record>
+ <record type="user">
+ <short-name>testuser1</short-name>
+ <uid>testuser1</uid>
+ <password>testuser1</password>
+ <full-name>Test User One</full-name>
+ <email>testuser10 at example.com</email>
+ </record>
+
<record type="group">
<uid>e5a6142c-4189-4e9e-90b0-9cd0268b314b</uid>
<short-name>testgroup1</short-name>
@@ -106,6 +114,20 @@
<member-uid type="users">user01</member-uid>
<member-uid type="users">user02</member-uid>
</record>
+
+ <record type="group">
+ <uid>group2</uid>
+ <short-name>group2</short-name>
+ <full-name>Test Group Two</full-name>
+ </record>
+
+ <record type="group">
+ <uid>group3</uid>
+ <short-name>group3</short-name>
+ <full-name>Test Group Three</full-name>
+ </record>
+
+
<!--
<user repeat="10">
<uid>user%02d</uid>
Modified: CalendarServer/trunk/calendarserver/tools/test/test_principals.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_principals.py 2014-10-29 16:57:26 UTC (rev 14121)
+++ CalendarServer/trunk/calendarserver/tools/test/test_principals.py 2014-10-29 20:28:29 UTC (rev 14122)
@@ -35,9 +35,6 @@
def setUp(self):
super(ManagePrincipalsTestCase, self).setUp()
- # # Since this test operates on proxy db, we need to assign the service:
- # calendaruserproxy.ProxyDBService = calendaruserproxy.ProxySqliteDB(os.path.abspath(self.mktemp()))
-
testRoot = os.path.join(os.path.dirname(__file__), "principals")
templateName = os.path.join(testRoot, "caldavd.plist")
templateFile = open(templateName)
@@ -138,12 +135,26 @@
@inlineCallbacks
def test_search(self):
- results = yield self.runCommand("--search=user")
- self.assertTrue("10 matches found" in results)
+ results = yield self.runCommand("--search", "user")
+ self.assertTrue("11 matches found" in results)
for i in xrange(1, 10):
self.assertTrue("user%02d" % (i,) in results)
+ results = yield self.runCommand("--search", "user", "04")
+ self.assertTrue("1 matches found" in results)
+ self.assertTrue("user04" in results)
+ results = yield self.runCommand("--context=group", "--search", "test")
+ self.assertTrue("2 matches found" in results)
+ self.assertTrue("group2" in results)
+ self.assertTrue("group3" in results)
+
+ results = yield self.runCommand("--context=attendee", "--search", "test")
+ self.assertTrue("3 matches found" in results)
+ self.assertTrue("testuser1" in results)
+ self.assertTrue("group2" in results)
+ self.assertTrue("group3" in results)
+
@inlineCallbacks
def test_addRemove(self):
results = yield self.runCommand(
Modified: CalendarServer/trunk/txdav/who/groups.py
===================================================================
--- CalendarServer/trunk/txdav/who/groups.py 2014-10-29 16:57:26 UTC (rev 14121)
+++ CalendarServer/trunk/txdav/who/groups.py 2014-10-29 20:28:29 UTC (rev 14122)
@@ -446,7 +446,7 @@
)
if membershipChanged:
- self.log.debug(
+ self.log.info(
"Membership changed for group {uid} {name}",
uid=groupUID,
name=cachedName
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20141029/9568e62a/attachment.html>
More information about the calendarserver-changes
mailing list