@@ -381,10 +381,15 @@ def create_from_file(self, filepath: str) -> tuple[list[UserItem], list[tuple[Us
381381
382382 # Get workbooks for user
383383 @api (version = "2.0" )
384- def populate_workbooks (self , user_item : UserItem , req_options : Optional [RequestOptions ] = None ) -> None :
384+ def populate_workbooks (
385+ self , user_item : UserItem , req_options : Optional [RequestOptions ] = None , owned_only : bool = False
386+ ) -> None :
385387 """
386388 Returns information about the workbooks that the specified user owns
387- and has Read (view) permissions for.
389+ or has Read (view) permissions for. If owned_only is set to True,
390+ only the workbooks that the user owns are returned. If owned_only is
391+ set to False, all workbooks that the user has Read (view) permissions
392+ for are returned.
388393
389394 This method retrieves the workbook information for the specified user.
390395 The REST API is designed to return only the information you ask for
@@ -402,6 +407,10 @@ def populate_workbooks(self, user_item: UserItem, req_options: Optional[RequestO
402407 req_options : Optional[RequestOptions]
403408 Optional request options to filter and sort the results.
404409
410+ owned_only : bool, default=False
411+ If True, only the workbooks that the user owns are returned.
412+ If False, all workbooks that the user has Read (view) permissions
413+
405414 Returns
406415 -------
407416 None
@@ -423,14 +432,22 @@ def populate_workbooks(self, user_item: UserItem, req_options: Optional[RequestO
423432 raise MissingRequiredFieldError (error )
424433
425434 def wb_pager ():
426- return Pager (lambda options : self ._get_wbs_for_user (user_item , options ), req_options )
435+ def func (req_options ):
436+ return self ._get_wbs_for_user (user_item , req_options , owned_only = owned_only )
437+
438+ return Pager (func , req_options )
427439
428440 user_item ._set_workbooks (wb_pager )
429441
430442 def _get_wbs_for_user (
431- self , user_item : UserItem , req_options : Optional [RequestOptions ] = None
443+ self ,
444+ user_item : UserItem ,
445+ req_options : Optional [RequestOptions ] = None ,
446+ owned_only : bool = False ,
432447 ) -> tuple [list [WorkbookItem ], PaginationItem ]:
433448 url = f"{ self .baseurl } /{ user_item .id } /workbooks"
449+ if owned_only :
450+ url += "?ownedBy=true"
434451 server_response = self .get_request (url , req_options )
435452 logger .info (f"Populated workbooks for user (ID: { user_item .id } )" )
436453 workbook_item = WorkbookItem .from_response (server_response .content , self .parent_srv .namespace )
0 commit comments