16
16
EmailStr ,
17
17
UserRole ,
18
18
InvitePending ,
19
- InviteRequest ,
19
+ InviteToOrgRequest ,
20
20
InviteOut ,
21
21
User ,
22
22
Organization ,
23
+ Subscription
23
24
)
24
25
from .users import UserManager
25
26
from .emailsender import EmailSender
@@ -71,6 +72,7 @@ async def add_new_user_invite(
71
72
new_user_invite : InvitePending ,
72
73
invite_token : UUID ,
73
74
org_name : str ,
75
+ subscription : Optional [Subscription ],
74
76
headers : Optional [dict ],
75
77
) -> None :
76
78
"""Add invite for new user"""
@@ -94,7 +96,12 @@ async def add_new_user_invite(
94
96
await self .invites .insert_one (new_user_invite .to_dict ())
95
97
96
98
await self .email .send_user_invite (
97
- new_user_invite , invite_token , org_name , True , headers
99
+ invite = new_user_invite ,
100
+ token = invite_token ,
101
+ org_name = org_name ,
102
+ is_new = True ,
103
+ subscription = subscription ,
104
+ headers = headers ,
98
105
)
99
106
100
107
# pylint: disable=too-many-arguments
@@ -130,7 +137,12 @@ async def add_existing_user_invite(
130
137
await self .invites .insert_one (existing_user_invite .to_dict ())
131
138
132
139
await self .email .send_user_invite (
133
- existing_user_invite , invite_token , org_name , False , headers
140
+ invite = existing_user_invite ,
141
+ token = invite_token ,
142
+ org_name = org_name ,
143
+ is_new = False ,
144
+ subscription = org .subscription ,
145
+ headers = headers ,
134
146
)
135
147
136
148
async def get_valid_invite (
@@ -173,7 +185,7 @@ async def remove_invite_by_email(
173
185
# pylint: disable=too-many-arguments
174
186
async def invite_user (
175
187
self ,
176
- invite : InviteRequest ,
188
+ invite : InviteToOrgRequest ,
177
189
user : User ,
178
190
user_manager : UserManager ,
179
191
org : Organization ,
@@ -199,9 +211,9 @@ async def invite_user(
199
211
id = uuid4 (),
200
212
oid = oid ,
201
213
created = dt_now (),
202
- role = invite .role if hasattr (invite , "role" ) else None ,
214
+ role = invite .role if hasattr (invite , "role" ) else UserRole . VIEWER ,
203
215
# URL decode email address just in case
204
- email = urllib .parse .unquote (invite .email ),
216
+ email = EmailStr ( urllib .parse .unquote (invite .email ) ),
205
217
inviterEmail = user .email ,
206
218
fromSuperuser = user .is_superuser ,
207
219
tokenHash = get_hash (invite_token ),
@@ -223,10 +235,11 @@ async def invite_user(
223
235
return False , invite_token
224
236
225
237
await self .add_new_user_invite (
226
- invite_pending ,
227
- invite_token ,
228
- org_name ,
229
- headers ,
238
+ new_user_invite = invite_pending ,
239
+ invite_token = invite_token ,
240
+ org_name = org_name ,
241
+ headers = headers ,
242
+ subscription = org .subscription ,
230
243
)
231
244
return True , invite_token
232
245
@@ -275,11 +288,10 @@ async def get_invite_out(
275
288
created = invite .created ,
276
289
inviterEmail = inviter_email ,
277
290
inviterName = inviter_name ,
278
- fromSuperuser = from_superuser ,
291
+ fromSuperuser = from_superuser or False ,
279
292
oid = invite .oid ,
280
293
role = invite .role ,
281
294
email = invite .email ,
282
- userid = invite .userid ,
283
295
)
284
296
285
297
if not invite .oid :
0 commit comments