Skip to content

Commit d13539e

Browse files
committed
docs: docstring updates for bulk add operations
1 parent 789d661 commit d13539e

File tree

1 file changed

+128
-2
lines changed

1 file changed

+128
-2
lines changed

tableauserverclient/server/endpoint/users_endpoint.py

+128-2
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,34 @@ def add(self, user_item: UserItem) -> UserItem:
349349

350350
# Add new users to site. This does not actually perform a bulk action, it's syntactic sugar
351351
@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)
354380
created = []
355381
failed = []
356382
for user in users:
@@ -387,6 +413,17 @@ def bulk_add(self, users: Iterable[UserItem]) -> JobItem:
387413
388414
Details about administrator level and publishing capability are
389415
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.
390427
"""
391428
url = f"{self.baseurl}/import"
392429
# Allow for iterators to be passed into the function
@@ -399,6 +436,22 @@ def bulk_add(self, users: Iterable[UserItem]) -> JobItem:
399436

400437
@api(version="3.15")
401438
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+
"""
402455
url = f"{self.baseurl}/delete"
403456
csv_content = remove_users_csv(users)
404457
request, content_type = RequestFactory.User.delete_csv_req(csv_content)
@@ -407,6 +460,35 @@ def bulk_remove(self, users: Iterable[UserItem]) -> None:
407460

408461
@api(version="2.0")
409462
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+
"""
410492
warnings.warn("This method is deprecated, use bulk_add instead", DeprecationWarning)
411493
created = []
412494
failed = []
@@ -615,6 +697,21 @@ def create_users_csv(users: Iterable[UserItem], identity_pool=None) -> bytes:
615697
- Admin Level
616698
- Publish capability
617699
- 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.
618715
"""
619716
if identity_pool is not None:
620717
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:
654751

655752

656753
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+
"""
657783
with io.StringIO() as output:
658784
writer = csv.writer(output, quoting=csv.QUOTE_MINIMAL)
659785
for user in users:

0 commit comments

Comments
 (0)