Skip to content

Commit 8c79efc

Browse files
committed
fixes for listing project users
1 parent 99b1812 commit 8c79efc

File tree

1 file changed

+73
-5
lines changed

1 file changed

+73
-5
lines changed

nocodb/infra/requests_client.py

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional
1+
from typing import Optional, List, Dict, Any
22
from ..nocodb import (
33
NocoDBClient,
44
NocoDBProject,
@@ -231,10 +231,78 @@ def view_filter_create(
231231
).json()
232232

233233
def project_users_list(
234-
self, project: NocoDBProject,
235-
) -> dict:
236-
print(self.__api_info.get_project_users_uri(project))
234+
self,
235+
project: NocoDBProject,
236+
page: int = 1,
237+
page_size: int = 25,
238+
include_roles: bool = True,
239+
) -> Dict[str, Any]:
240+
"""
241+
Fetch project users with pagination support.
242+
243+
Args:
244+
project (NocoDBProject): The project to fetch users from
245+
page (int): Page number (1-based indexing)
246+
page_size (int): Number of items per page
247+
include_roles (bool): Whether to include user roles in the response
248+
249+
Returns:
250+
Dict containing:
251+
- list: List of users for the current page
252+
- pageInfo: Pagination information including total count
253+
"""
254+
params = {
255+
"limit": page_size,
256+
"offset": (page - 1) * page_size,
257+
}
258+
259+
if include_roles:
260+
params["include_roles"] = "true"
261+
237262
return self._request(
238263
"GET",
239264
url=self.__api_info.get_project_users_uri(project),
240-
).json()
265+
params=params,
266+
).json()
267+
268+
def project_users_list_all(
269+
self,
270+
project: NocoDBProject,
271+
include_roles: bool = True,
272+
page_size: int = 25,
273+
) -> List[Dict[str, Any]]:
274+
"""
275+
Fetch all project users by automatically handling pagination.
276+
277+
Args:
278+
project (NocoDBProject): The project to fetch users from
279+
include_roles (bool): Whether to include user roles in the response
280+
page_size (int): Number of items to fetch per request
281+
282+
Returns:
283+
List of all users in the project
284+
"""
285+
all_users = []
286+
page = 1
287+
288+
while True:
289+
response = self.project_users_list(
290+
project=project,
291+
page=page,
292+
page_size=page_size,
293+
include_roles=include_roles
294+
)
295+
296+
users = response.get("list", [])
297+
all_users.extend(users)
298+
299+
# Check if we've reached the end of the pagination
300+
page_info = response.get("pageInfo", {})
301+
total_pages = (page_info.get("totalRows", 0) + page_size - 1) // page_size
302+
303+
if page >= total_pages or not users:
304+
break
305+
306+
page += 1
307+
308+
return all_users

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy