enumeration of resources for discovery in home sets
authorchrysn <chrysn@fsfe.org>
Fri, 4 Apr 2014 10:22:35 +0000 (12:22 +0200)
committerJelmer Vernooij <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 8483fff4588e9dbe87b29647400c0b1d9bfc7aa3..ec284c7c34a208a058ee3feefb36afb4d0961544 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 d395c07dcd4494ebe4a66e259d13abf2598a596e..4f6b653bc6487c14378b6e085aab44031cead0b8 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