1414
1515
1616class Users (QuerysetEndpoint [UserItem ]):
17+ """
18+ The user resources for Tableau Server are defined in the UserItem class.
19+ The class corresponds to the user resources you can access using the
20+ Tableau Server REST API. The user methods are based upon the endpoints for
21+ users in the REST API and operate on the UserItem class. Only server and
22+ site administrators can access the user resources.
23+ """
24+
1725 @property
1826 def baseurl (self ) -> str :
1927 return f"{ self .parent_srv .baseurl } /sites/{ self .parent_srv .site_id } /users"
2028
2129 # Gets all users
2230 @api (version = "2.0" )
2331 def get (self , req_options : Optional [RequestOptions ] = None ) -> tuple [list [UserItem ], PaginationItem ]:
32+ """
33+ Query all users on the site. Request is paginated and returns a subset of users.
34+ By default, the request returns the first 100 users on the site.
35+
36+ Parameters
37+ ----------
38+ req_options : Optional[RequestOptions]
39+ Optional request options to filter and sort the results.
40+
41+ Returns
42+ -------
43+ tuple[list[UserItem], PaginationItem]
44+ Returns a tuple with a list of UserItem objects and a PaginationItem object.
45+
46+ Examples
47+ --------
48+ >>> import tableauserverclient as TSC
49+ >>> tableau_auth = TSC.TableauAuth('USERNAME', 'PASSWORD')
50+ >>> server = TSC.Server('https://SERVERURL')
51+
52+ >>> with server.auth.sign_in(tableau_auth):
53+ >>> users_page, pagination_item = server.users.get()
54+ >>> print("\n There are {} user on site: ".format(pagination_item.total_available))
55+ >>> print([user.name for user in users_page])
56+ """
2457 logger .info ("Querying all users on site" )
2558
2659 if req_options is None :
@@ -36,6 +69,23 @@ def get(self, req_options: Optional[RequestOptions] = None) -> tuple[list[UserIt
3669 # Gets 1 user by id
3770 @api (version = "2.0" )
3871 def get_by_id (self , user_id : str ) -> UserItem :
72+ """
73+ Query a single user by ID.
74+
75+ Parameters
76+ ----------
77+ user_id : str
78+ The ID of the user to query.
79+
80+ Returns
81+ -------
82+ UserItem
83+ The user item that was queried.
84+
85+ Examples
86+ --------
87+ >>> user1 = server.users.get_by_id('9f9e9d9c-8b8a-8f8e-7d7c-7b7a6f6d6e6d')
88+ """
3989 if not user_id :
4090 error = "User ID undefined."
4191 raise ValueError (error )
@@ -47,6 +97,47 @@ def get_by_id(self, user_id: str) -> UserItem:
4797 # Update user
4898 @api (version = "2.0" )
4999 def update (self , user_item : UserItem , password : Optional [str ] = None ) -> UserItem :
100+ """
101+ Modifies information about the specified user.
102+
103+ If Tableau Server is configured to use local authentication, you can
104+ update the user's name, email address, password, or site role.
105+
106+ If Tableau Server is configured to use Active Directory
107+ authentication, you can change the user's display name (full name),
108+ email address, and site role. However, if you synchronize the user with
109+ Active Directory, the display name and email address will be
110+ overwritten with the information that's in Active Directory.
111+
112+ For Tableau Cloud, you can update the site role for a user, but you
113+ cannot update or change a user's password, user name (email address),
114+ or full name.
115+
116+ Parameters
117+ ----------
118+ user_item : UserItem
119+ The user item to update.
120+
121+ password : Optional[str]
122+ The new password for the user.
123+
124+ Returns
125+ -------
126+ UserItem
127+ The user item that was updated.
128+
129+ Raises
130+ ------
131+ MissingRequiredFieldError
132+ If the user item is missing an ID.
133+
134+ Examples
135+ --------
136+ >>> user = server.users.get_by_id('9f9e9d9c-8b8a-8f8e-7d7c-7b7a6f6d6e6d')
137+ >>> user.fullname = 'New Full Name'
138+ >>> updated_user = server.users.update(user)
139+
140+ """
50141 if not user_item .id :
51142 error = "User item missing ID."
52143 raise MissingRequiredFieldError (error )
@@ -61,6 +152,31 @@ def update(self, user_item: UserItem, password: Optional[str] = None) -> UserIte
61152 # Delete 1 user by id
62153 @api (version = "2.0" )
63154 def remove (self , user_id : str , map_assets_to : Optional [str ] = None ) -> None :
155+ """
156+ Removes a user from the site. You can also specify a user to map the
157+ assets to when you remove the user.
158+
159+ Parameters
160+ ----------
161+ user_id : str
162+ The ID of the user to remove.
163+
164+ map_assets_to : Optional[str]
165+ The ID of the user to map the assets to when you remove the user.
166+
167+ Returns
168+ -------
169+ None
170+
171+ Raises
172+ ------
173+ ValueError
174+ If the user ID is not specified.
175+
176+ Examples
177+ --------
178+ >>> server.users.remove('9f9e9d9c-8b8a-8f8e-7d7c-7b7a6f6d6e6d')
179+ """
64180 if not user_id :
65181 error = "User ID undefined."
66182 raise ValueError (error )
@@ -73,6 +189,39 @@ def remove(self, user_id: str, map_assets_to: Optional[str] = None) -> None:
73189 # Add new user to site
74190 @api (version = "2.0" )
75191 def add (self , user_item : UserItem ) -> UserItem :
192+ """
193+ Adds the user to the site.
194+
195+ To add a new user to the site you need to first create a new user_item
196+ (from UserItem class). When you create a new user, you specify the name
197+ of the user and their site role. For Tableau Cloud, you also specify
198+ the auth_setting attribute in your request. When you add user to
199+ Tableau Cloud, the name of the user must be the email address that is
200+ used to sign in to Tableau Cloud. After you add a user, Tableau Cloud
201+ sends the user an email invitation. The user can click the link in the
202+ invitation to sign in and update their full name and password.
203+
204+ Parameters
205+ ----------
206+ user_item : UserItem
207+ The user item to add to the site.
208+
209+ Returns
210+ -------
211+ UserItem
212+ The user item that was added to the site with attributes from the
213+ site populated.
214+
215+ Examples
216+ --------
217+ >>> import tableauserverclient as TSC
218+ >>> server = TSC.Server('https://SERVERURL')
219+ >>> # Login to the server
220+
221+ >>> new_user = TSC.UserItem(name='new_user', site_role=TSC.UserItem.Role.Unlicensed)
222+ >>> new_user = server.users.add(new_user)
223+
224+ """
76225 url = self .baseurl
77226 logger .info (f"Add user { user_item .name } " )
78227 add_req = RequestFactory .User .add_req (user_item )
@@ -122,6 +271,42 @@ def create_from_file(self, filepath: str) -> tuple[list[UserItem], list[tuple[Us
122271 # Get workbooks for user
123272 @api (version = "2.0" )
124273 def populate_workbooks (self , user_item : UserItem , req_options : Optional [RequestOptions ] = None ) -> None :
274+ """
275+ Returns information about the workbooks that the specified user owns
276+ and has Read (view) permissions for.
277+
278+ This method retrieves the workbook information for the specified user.
279+ The REST API is designed to return only the information you ask for
280+ explicitly. When you query for all the users, the workbook information
281+ for each user is not included. Use this method to retrieve information
282+ about the workbooks that the user owns or has Read (view) permissions.
283+ The method adds the list of workbooks to the user item object
284+ (user_item.workbooks).
285+
286+ Parameters
287+ ----------
288+ user_item : UserItem
289+ The user item to populate workbooks for.
290+
291+ req_options : Optional[RequestOptions]
292+ Optional request options to filter and sort the results.
293+
294+ Returns
295+ -------
296+ None
297+
298+ Raises
299+ ------
300+ MissingRequiredFieldError
301+ If the user item is missing an ID.
302+
303+ Examples
304+ --------
305+ >>> user = server.users.get_by_id('9f9e9d9c-8b8a-8f8e-7d7c-7b7a6f6d6e6d')
306+ >>> server.users.populate_workbooks(user)
307+ >>> for wb in user.workbooks:
308+ >>> print(wb.name)
309+ """
125310 if not user_item .id :
126311 error = "User item missing ID."
127312 raise MissingRequiredFieldError (error )
@@ -142,11 +327,62 @@ def _get_wbs_for_user(
142327 return workbook_item , pagination_item
143328
144329 def populate_favorites (self , user_item : UserItem ) -> None :
330+ """
331+ Populate the favorites for the user.
332+
333+ Parameters
334+ ----------
335+ user_item : UserItem
336+ The user item to populate favorites for.
337+
338+ Returns
339+ -------
340+ None
341+
342+ Examples
343+ --------
344+ >>> import tableauserverclient as TSC
345+ >>> server = TSC.Server('https://SERVERURL')
346+ >>> # Login to the server
347+
348+ >>> user = server.users.get_by_id('9f9e9d9c-8b8a-8f8e-7d7c-7b7a6f6d6e6d')
349+ >>> server.users.populate_favorites(user)
350+ >>> for obj_type, items in user.favorites.items():
351+ >>> print(f"Favorites for {obj_type}:")
352+ >>> for item in items:
353+ >>> print(item.name)
354+ """
145355 self .parent_srv .favorites .get (user_item )
146356
147357 # Get groups for user
148358 @api (version = "3.7" )
149359 def populate_groups (self , user_item : UserItem , req_options : Optional [RequestOptions ] = None ) -> None :
360+ """
361+ Populate the groups for the user.
362+
363+ Parameters
364+ ----------
365+ user_item : UserItem
366+ The user item to populate groups for.
367+
368+ req_options : Optional[RequestOptions]
369+ Optional request options to filter and sort the results.
370+
371+ Returns
372+ -------
373+ None
374+
375+ Raises
376+ ------
377+ MissingRequiredFieldError
378+ If the user item is missing an ID.
379+
380+ Examples
381+ --------
382+ >>> server.users.populate_groups(user)
383+ >>> for group in user.groups:
384+ >>> print(group.name)
385+ """
150386 if not user_item .id :
151387 error = "User item missing ID."
152388 raise MissingRequiredFieldError (error )
0 commit comments