@@ -145,6 +145,22 @@ def add_v1_space_members_to_v2_group(space, group_id, headers):
145145 )
146146
147147
148+ def get_collection_v1_descendants (headers , collection_id ):
149+ descendant_ids = []
150+
151+ collection_endpoint = f"{ CLOWDER_V1 } /api/collections/{ collection_id } "
152+ response = requests .get (collection_endpoint , headers = headers , verify = False )
153+ collection_json = response .json ()
154+ print (collection_json ["child_collection_ids" ])
155+ if int (collection_json ["childCollectionsCount" ]) > 0 :
156+ child_collections_ids = collection_json ["child_collection_ids" ]
157+ descendant_ids = child_collections_ids [5 :- 1 ].split (', ' )
158+ for id in descendant_ids :
159+ sub_descendants = get_collection_v1_descendants (headers , id )
160+ descendant_ids .extend (sub_descendants )
161+ return descendant_ids
162+ print ('we got collection' )
163+
148164def get_clowder_v1_user_collections (headers , user_v1 ):
149165 endpoint = f"{ CLOWDER_V1 } /api/collections"
150166 response = requests .get (endpoint , headers = headers )
@@ -154,6 +170,7 @@ def get_clowder_v1_user_collections(headers, user_v1):
154170def get_clowder_v1_dataset_collections (headers , user_v1 , dataset_id ):
155171 matching_collections = []
156172 endpoint1 = f"{ CLOWDER_V1 } /api/collections/rootCollections?superAdmin=true"
173+ # use this one below
157174 endpint2 = f"{ CLOWDER_V1 } /api/collections/topLevelCollections?superAdmin=true"
158175 response = requests .get (endpoint1 , headers = headers )
159176 response2 = requests .get (endpint2 , headers = headers )
@@ -163,7 +180,10 @@ def get_clowder_v1_dataset_collections(headers, user_v1, dataset_id):
163180 user_collections_2 = response2 .json ()
164181 for collection in user_collections_2 :
165182 id = collection ['id' ]
166- user_collections_ids_2 .append (id )
183+ descendants = get_collection_v1_descendants (headers , id )
184+ # test_descendants = get_collection_v1_descendants(headers, "68a34b28e4b0cc7386c091a4")
185+ # TODO check here if the dataset is in a descendant
186+ print ('got descendants' )
167187 for collection in user_collections :
168188 user_collections_ids .append (collection ['id' ])
169189 for collection in user_collections :
0 commit comments