@@ -349,8 +349,34 @@ def add(self, user_item: UserItem) -> UserItem:
349
349
350
350
# Add new users to site. This does not actually perform a bulk action, it's syntactic sugar
351
351
@api (version = "2.0" )
352
- def add_all (self , users : list [UserItem ]):
353
- warnings .warn ("This method is deprecated, use bulk_add instead" , DeprecationWarning )
352
+ def add_all (self , users : list [UserItem ]) -> tuple [list [UserItem ], list [UserItem ]]:
353
+ """
354
+ Syntactic sugar for calling users.add multiple times. This method has
355
+ been deprecated in favor of using the bulk_add which accomplishes the
356
+ same task in one API call.
357
+
358
+ .. deprecated:: v0.34.0
359
+ `add_all` will be removed as its functionality is replicated via
360
+ the `bulk_add` method.
361
+
362
+ Parameters
363
+ ----------
364
+ users: list[UserItem]
365
+ A list of UserItem objects to add to the site. Each UserItem object
366
+ will be passed to the `add` method individually.
367
+
368
+ Returns
369
+ -------
370
+ tuple[list[UserItem], list[UserItem]]
371
+ The first element of the tuple is a list of UserItem objects that
372
+ were successfully added to the site. The second element is a list
373
+ of UserItem objects that failed to be added to the site.
374
+
375
+ Warnings
376
+ --------
377
+ This method is deprecated. Use the `bulk_add` method instead.
378
+ """
379
+ warnings .warn ("This method is deprecated, use bulk_add method instead." , DeprecationWarning )
354
380
created = []
355
381
failed = []
356
382
for user in users :
@@ -387,6 +413,17 @@ def bulk_add(self, users: Iterable[UserItem]) -> JobItem:
387
413
388
414
Details about administrator level and publishing capability are
389
415
inferred from the site_role.
416
+
417
+ Parameters
418
+ ----------
419
+ users: Iterable[UserItem]
420
+ An iterable of UserItem objects to add to the site. See above for
421
+ what fields are required and optional.
422
+
423
+ Returns
424
+ -------
425
+ JobItem
426
+ The job that is started for adding the users in bulk.
390
427
"""
391
428
url = f"{ self .baseurl } /import"
392
429
# Allow for iterators to be passed into the function
@@ -399,6 +436,22 @@ def bulk_add(self, users: Iterable[UserItem]) -> JobItem:
399
436
400
437
@api (version = "3.15" )
401
438
def bulk_remove (self , users : Iterable [UserItem ]) -> None :
439
+ """
440
+ Remove multiple users from the site. The users are identified by their
441
+ domain and name. The users are removed in bulk, so the server will not
442
+ return a job item to track the progress of the operation nor a response
443
+ for each user that was removed.
444
+
445
+ Parameters
446
+ ----------
447
+ users: Iterable[UserItem]
448
+ An iterable of UserItem objects to remove from the site. Each
449
+ UserItem object should have the domain and name attributes set.
450
+
451
+ Returns
452
+ -------
453
+ None
454
+ """
402
455
url = f"{ self .baseurl } /delete"
403
456
csv_content = remove_users_csv (users )
404
457
request , content_type = RequestFactory .User .delete_csv_req (csv_content )
@@ -407,6 +460,35 @@ def bulk_remove(self, users: Iterable[UserItem]) -> None:
407
460
408
461
@api (version = "2.0" )
409
462
def create_from_file (self , filepath : str ) -> tuple [list [UserItem ], list [tuple [UserItem , ServerResponseError ]]]:
463
+ """
464
+ Syntactic sugar for calling users.add multiple times. This method has
465
+ been deprecated in favor of using the bulk_add which accomplishes the
466
+ same task in one API call.
467
+
468
+ .. deprecated:: v0.34.0
469
+ `add_all` will be removed as its functionality is replicated via
470
+ the `bulk_add` method.
471
+
472
+ Parameters
473
+ ----------
474
+ filepath: str
475
+ The path to the CSV file containing the users to add to the site.
476
+ The file is read in line by line and each line is passed to the
477
+ `add` method.
478
+
479
+ Returns
480
+ -------
481
+ tuple[list[UserItem], list[tuple[UserItem, ServerResponseError]]]
482
+ The first element of the tuple is a list of UserItem objects that
483
+ were successfully added to the site. The second element is a list
484
+ of tuples where the first element is the UserItem object that failed
485
+ to be added to the site and the second element is the ServerResponseError
486
+ that was raised when attempting to add the user.
487
+
488
+ Warnings
489
+ --------
490
+ This method is deprecated. Use the `bulk_add` method instead.
491
+ """
410
492
warnings .warn ("This method is deprecated, use bulk_add instead" , DeprecationWarning )
411
493
created = []
412
494
failed = []
@@ -615,6 +697,21 @@ def create_users_csv(users: Iterable[UserItem], identity_pool=None) -> bytes:
615
697
- Admin Level
616
698
- Publish capability
617
699
- Email
700
+
701
+ Parameters
702
+ ----------
703
+ users: Iterable[UserItem]
704
+ An iterable of UserItem objects to create the CSV from.
705
+
706
+ identity_pool: Optional[str]
707
+ The identity pool to use when adding the users. This parameter is not
708
+ yet supported in this version of the Tableau Server Client, and should
709
+ be left as None.
710
+
711
+ Returns
712
+ -------
713
+ bytes
714
+ A byte string containing the CSV data.
618
715
"""
619
716
if identity_pool is not None :
620
717
raise NotImplementedError ("Identity pool is not supported in this version" )
@@ -654,6 +751,35 @@ def create_users_csv(users: Iterable[UserItem], identity_pool=None) -> bytes:
654
751
655
752
656
753
def remove_users_csv (users : Iterable [UserItem ]) -> bytes :
754
+ """
755
+ Create a CSV byte string from an Iterable of UserItem objects. This function
756
+ only consumes the domain and name attributes of the UserItem objects. The
757
+ CSV will have space for the following columns, though only the first column
758
+ will be populated, and no header row:
759
+
760
+ - Username
761
+ - Password
762
+ - Display Name
763
+ - License
764
+ - Admin Level
765
+ - Publish capability
766
+ - Email
767
+
768
+ Parameters
769
+ ----------
770
+ users: Iterable[UserItem]
771
+ An iterable of UserItem objects to create the CSV from.
772
+
773
+ identity_pool: Optional[str]
774
+ The identity pool to use when adding the users. This parameter is not
775
+ yet supported in this version of the Tableau Server Client, and should
776
+ be left as None.
777
+
778
+ Returns
779
+ -------
780
+ bytes
781
+ A byte string containing the CSV data.
782
+ """
657
783
with io .StringIO () as output :
658
784
writer = csv .writer (output , quoting = csv .QUOTE_MINIMAL )
659
785
for user in users :
0 commit comments