enumeration of resources for discovery in home sets
authorchrysn <chrysn@fsfe.org>
Fri, 4 Apr 2014 10:22:35 +0000 (12:22 +0200)
committerJelmer Vernooń≥ <jelmer@jelmer.uk>
Sun, 10 Apr 2016 11:43:29 +0000 (11:43 +0000)
this is subject to the same constraints as in the "distinguish between
calendars and address books" commit; probably, dedicated support for
creating collections must be added. (how else should clients with
autodiscovery do anything on a freshly installed server?)

calypso/paths.py
calypso/principal.py

index 8483fff..ec284c7 100644 (file)
@@ -85,6 +85,22 @@ def is_collection(url):
             return False
         urlpath, stripped = os.path.split(urlpath)
 
+def enumerate_collection_paths():
+    """List the url paths that can be accessed as collections."""
+
+    for root, dirs, files in os.walk(data_root()):
+        relative = root[len(data_root())+1:]
+        if any(p.startswith('.') for p in relative.split('/')):
+            continue
+        urlpath = base_prefix() + "/" + relative
+        if is_collection(urlpath):
+            yield urlpath
+
+def enumerate_collections():
+    from calypso import collection_singleton
+    for p in enumerate_collection_paths():
+        yield collection_singleton(p)
+
 #
 # Given a URL, return the parent URL by stripping off
 # the last path element
index d395c07..4f6b653 100644 (file)
@@ -53,17 +53,17 @@ class HomeSet(Resource):
     def propfind_children(self, depth, context):
         # FIXME ignoring depth
 
-        collection_name = paths.collection_from_path(self.username + "/" + self.single_collection)
-        from calypso import collection_singleton
-        collection = collection_singleton(collection_name)
-        items = [collection] # + collection.items # FIXME sequence matters, see parentcollectionhack
-        return super(HomeSet, self).propfind_children(depth) + items
+        items = [c for c in paths.enumerate_collections() if self.is_in_set(c) and context['has_right'](c.owner)]
+        return super(HomeSet, self).propfind_children(depth, context) + items
 
 class AddressbookHomeSet(HomeSet):
     type_dependent_suffix = "addressbooks"
-    single_collection = "addresses"
+
+    def is_in_set(self, collection):
+        return collection.is_vcard
 
 class CalendarHomeSet(HomeSet):
     type_dependent_suffix = "calendars"
-    single_collection = "calendar"
 
+    def is_in_set(self, collection):
+        return collection.is_vcal