22
22
23
23
from typing import TYPE_CHECKING , Any
24
24
25
- from ..utils import UNCHANGED , get_url_from_template
25
+ from ..utils import UNCHANGED , _Sentinel , get_url_from_template
26
26
27
27
if TYPE_CHECKING :
28
28
import httpx
@@ -49,7 +49,7 @@ def _url_for(self, endpoint, **kwargs):
49
49
"""
50
50
return get_url_from_template (endpoint , self ._URL_TEMPLATES , kwargs )
51
51
52
- def users (self ) -> list [str ]:
52
+ def users (self ) -> list [dict ]:
53
53
"""
54
54
Get the list of available users.
55
55
@@ -83,9 +83,12 @@ def create_user(
83
83
pwd : str ,
84
84
fullname : str = "" ,
85
85
description : str = "" ,
86
+ email : str = "" ,
86
87
admin : bool = False ,
87
88
groups : list [str ] | None = None ,
88
89
resource_pool : str | None = None ,
90
+ opt_in : bool | None = None ,
91
+ tour_version : str = "" ,
89
92
) -> dict :
90
93
"""
91
94
Create a new user.
@@ -94,58 +97,76 @@ def create_user(
94
97
:param pwd: Desired password.
95
98
:param fullname: Full name.
96
99
:param description: Description.
100
+ :param email: Email address.
97
101
:param admin: Whether to create an admin user.
98
102
:param groups: List of groups to which the user should be added.
99
103
:param resource_pool: Resource pool to which the user should be added.
104
+ :param opt_in: Whether the user has seen the initial contact dialog.
105
+ :param tour_version: The version of the Workbench tour the user has completed.
100
106
:returns: User object.
101
107
"""
102
108
data = {
103
109
"username" : username ,
104
110
"password" : pwd ,
105
111
"fullname" : fullname ,
106
112
"description" : description ,
113
+ "email" : email ,
107
114
"admin" : admin ,
108
115
"groups" : groups or [],
109
116
"resource_pool" : resource_pool ,
117
+ "opt_in" : opt_in ,
118
+ "tour_version" : tour_version ,
110
119
}
111
120
url = self ._url_for ("users" )
112
121
return self ._session .post (url , json = data ).json ()
113
122
114
123
def update_user (
115
124
self ,
116
125
user_id : str ,
117
- fullname : str | None = UNCHANGED ,
118
- description : str | None = UNCHANGED ,
119
- groups : list [str ] | None = UNCHANGED ,
126
+ fullname : str | None = None ,
127
+ description : str | None = None ,
128
+ email : str | None = None ,
129
+ groups : list [str ] | None = None ,
120
130
admin : bool | None = None ,
121
131
password_dict : dict [str , str ] | None = None ,
122
- resource_pool : str | None = UNCHANGED ,
132
+ resource_pool : str | None | _Sentinel = UNCHANGED ,
133
+ opt_in : bool | None | _Sentinel = UNCHANGED ,
134
+ tour_version : str | None = None ,
123
135
) -> dict :
124
136
"""
125
137
Update an existing user.
126
138
127
139
:param user_id: User UUID4.
128
140
:param fullname: Full name.
129
141
:param description: Description.
142
+ :param email: Email address.
130
143
:param admin: Whether to create an admin user.
131
144
:param groups: List of groups to which the user should be added.
132
145
:param password_dict: Dictionary containing old and new passwords.
133
146
:param resource_pool: Resource pool to which the user should be added.
147
+ :param opt_in: Whether the user has seen the initial contact dialog.
148
+ :param tour_version: The version of the Workbench tour the user has completed.
134
149
:returns: User object.
135
150
"""
136
151
data : dict [str , Any ] = {}
137
- if fullname is not UNCHANGED :
152
+ if fullname is not None :
138
153
data ["fullname" ] = fullname
139
- if description is not UNCHANGED :
154
+ if description is not None :
140
155
data ["description" ] = description
156
+ if email is not None :
157
+ data ["email" ] = email
141
158
if admin is not None :
142
159
data ["admin" ] = admin
143
- if groups is not UNCHANGED :
160
+ if groups is not None :
144
161
data ["groups" ] = groups
145
162
if password_dict is not None :
146
163
data ["password" ] = password_dict
147
164
if resource_pool is not UNCHANGED :
148
165
data ["resource_pool" ] = resource_pool
166
+ if opt_in is not UNCHANGED :
167
+ data ["opt_in" ] = opt_in
168
+ if tour_version is not None :
169
+ data ["tour_version" ] = tour_version
149
170
150
171
url = self ._url_for ("user" , user_id = user_id )
151
172
return self ._session .patch (url , json = data ).json ()
0 commit comments