@@ -206,6 +206,7 @@ async def list(self, session: SessionAdapter, search_params: generic.SearchParam
206
206
List credentials that are members of currently authorized tenants.
207
207
Global_search lists all credentials, regardless of tenants, but this requires superuser authorization.
208
208
"""
209
+ # TODO: Searching with filters is very inefficient and needs serious optimization
209
210
if len (search_params .AdvancedFilter ) > 1 :
210
211
raise asab .exceptions .ValidationError ("No more than one advanced filter at a time is supported." )
211
212
@@ -260,8 +261,7 @@ async def list(self, session: SessionAdapter, search_params: generic.SearchParam
260
261
estimated_count = None
261
262
if searched_roles :
262
263
role_svc = self .App .get_service ("seacatauth.RoleService" )
263
- assignments = await role_svc .list_role_assignments (
264
- role_id = searched_roles , page = search_params .Page , limit = search_params .ItemsPerPage )
264
+ assignments = await role_svc .list_role_assignments (role_id = searched_roles )
265
265
if filtered_cids is None :
266
266
filtered_cids = set (a ["c" ] for a in assignments ["data" ])
267
267
estimated_count = assignments ["count" ]
@@ -271,8 +271,7 @@ async def list(self, session: SessionAdapter, search_params: generic.SearchParam
271
271
if searched_tenants :
272
272
tenant_svc = self .App .get_service ("seacatauth.TenantService" )
273
273
provider = tenant_svc .get_provider ()
274
- assignments = await provider .list_tenant_assignments (
275
- searched_tenants , page = search_params .Page , limit = search_params .ItemsPerPage )
274
+ assignments = await provider .list_tenant_assignments (searched_tenants )
276
275
if filtered_cids is None :
277
276
filtered_cids = set (a ["c" ] for a in assignments ["data" ])
278
277
estimated_count = assignments ["count" ]
@@ -285,20 +284,34 @@ async def list(self, session: SessionAdapter, search_params: generic.SearchParam
285
284
return {"count" : 0 , "data" : []}
286
285
287
286
credentials = []
288
- total_count = estimated_count
287
+ filtered_cids = sorted ( filtered_cids )
289
288
289
+ offset = search_params .Page * search_params .ItemsPerPage
290
290
for cid in filtered_cids :
291
291
_ , provider_id , _ = cid .split (":" , 2 )
292
292
try :
293
293
provider = self .CredentialProviders [provider_id ]
294
- credentials . append ( await provider .get (cid ) )
294
+ cred_data = await provider .get (cid )
295
295
except KeyError :
296
296
L .info ("Found an assignment of nonexisting credentials" , struct_data = {
297
297
"cid" : cid , "role_ids" : searched_roles , "tenant_ids" : searched_tenants })
298
+ continue
299
+ if not search_params .SimpleFilter or (
300
+ cred_data .get ("username" , "" ).startswith (search_params .SimpleFilter )
301
+ or cred_data .get ("email" , "" ).startswith (search_params .SimpleFilter )
302
+ ):
303
+ if offset > 0 :
304
+ # Skip until offset is reached
305
+ offset -= 1
306
+ continue
307
+ credentials .append (cred_data )
308
+ if len (credentials ) >= search_params .ItemsPerPage :
309
+ # Page is full
310
+ break
298
311
299
312
return {
300
313
"data" : credentials ,
301
- "count" : total_count ,
314
+ "count" : estimated_count ,
302
315
}
303
316
304
317
# Search without external filters
0 commit comments