35
35
36
36
from synapse .api .errors import SynapseError
37
37
from synapse .events import EventBase
38
- from synapse .events .presence_router import PresenceRouter
38
+ from synapse .events .presence_router import (
39
+ GET_INTERESTED_USERS_CALLBACK ,
40
+ GET_USERS_FOR_STATES_CALLBACK ,
41
+ PresenceRouter ,
42
+ )
43
+ from synapse .events .spamcheck import (
44
+ CHECK_EVENT_FOR_SPAM_CALLBACK ,
45
+ CHECK_MEDIA_FILE_FOR_SPAM_CALLBACK ,
46
+ CHECK_REGISTRATION_FOR_SPAM_CALLBACK ,
47
+ CHECK_USERNAME_FOR_SPAM_CALLBACK ,
48
+ USER_MAY_CREATE_ROOM_ALIAS_CALLBACK ,
49
+ USER_MAY_CREATE_ROOM_CALLBACK ,
50
+ USER_MAY_CREATE_ROOM_WITH_INVITES_CALLBACK ,
51
+ USER_MAY_INVITE_CALLBACK ,
52
+ USER_MAY_JOIN_ROOM_CALLBACK ,
53
+ USER_MAY_PUBLISH_ROOM_CALLBACK ,
54
+ USER_MAY_SEND_3PID_INVITE_CALLBACK ,
55
+ )
56
+ from synapse .events .third_party_rules import (
57
+ CHECK_EVENT_ALLOWED_CALLBACK ,
58
+ CHECK_THREEPID_CAN_BE_INVITED_CALLBACK ,
59
+ CHECK_VISIBILITY_CAN_BE_MODIFIED_CALLBACK ,
60
+ ON_CREATE_ROOM_CALLBACK ,
61
+ ON_NEW_EVENT_CALLBACK ,
62
+ )
63
+ from synapse .handlers .account_validity import (
64
+ IS_USER_EXPIRED_CALLBACK ,
65
+ ON_LEGACY_ADMIN_REQUEST ,
66
+ ON_LEGACY_RENEW_CALLBACK ,
67
+ ON_LEGACY_SEND_MAIL_CALLBACK ,
68
+ ON_USER_REGISTRATION_CALLBACK ,
69
+ )
70
+ from synapse .handlers .auth import (
71
+ CHECK_3PID_AUTH_CALLBACK ,
72
+ CHECK_AUTH_CALLBACK ,
73
+ ON_LOGGED_OUT_CALLBACK ,
74
+ AuthHandler ,
75
+ )
39
76
from synapse .http .client import SimpleHttpClient
40
77
from synapse .http .server import (
41
78
DirectServeHtmlResource ,
@@ -114,7 +151,7 @@ class ModuleApi:
114
151
can register new users etc if necessary.
115
152
"""
116
153
117
- def __init__ (self , hs : "HomeServer" , auth_handler ) :
154
+ def __init__ (self , hs : "HomeServer" , auth_handler : AuthHandler ) -> None :
118
155
self ._hs = hs
119
156
120
157
# TODO: Fix this type hint once the types for the data stores have been ironed
@@ -156,45 +193,119 @@ def __init__(self, hs: "HomeServer", auth_handler):
156
193
#################################################################################
157
194
# The following methods should only be called during the module's initialisation.
158
195
159
- @property
160
- def register_spam_checker_callbacks (self ):
196
+ def register_spam_checker_callbacks (
197
+ self ,
198
+ check_event_for_spam : Optional [CHECK_EVENT_FOR_SPAM_CALLBACK ] = None ,
199
+ user_may_join_room : Optional [USER_MAY_JOIN_ROOM_CALLBACK ] = None ,
200
+ user_may_invite : Optional [USER_MAY_INVITE_CALLBACK ] = None ,
201
+ user_may_send_3pid_invite : Optional [USER_MAY_SEND_3PID_INVITE_CALLBACK ] = None ,
202
+ user_may_create_room : Optional [USER_MAY_CREATE_ROOM_CALLBACK ] = None ,
203
+ user_may_create_room_with_invites : Optional [
204
+ USER_MAY_CREATE_ROOM_WITH_INVITES_CALLBACK
205
+ ] = None ,
206
+ user_may_create_room_alias : Optional [
207
+ USER_MAY_CREATE_ROOM_ALIAS_CALLBACK
208
+ ] = None ,
209
+ user_may_publish_room : Optional [USER_MAY_PUBLISH_ROOM_CALLBACK ] = None ,
210
+ check_username_for_spam : Optional [CHECK_USERNAME_FOR_SPAM_CALLBACK ] = None ,
211
+ check_registration_for_spam : Optional [
212
+ CHECK_REGISTRATION_FOR_SPAM_CALLBACK
213
+ ] = None ,
214
+ check_media_file_for_spam : Optional [CHECK_MEDIA_FILE_FOR_SPAM_CALLBACK ] = None ,
215
+ ) -> None :
161
216
"""Registers callbacks for spam checking capabilities.
162
217
163
218
Added in Synapse v1.37.0.
164
219
"""
165
- return self ._spam_checker .register_callbacks
220
+ return self ._spam_checker .register_callbacks (
221
+ check_event_for_spam = check_event_for_spam ,
222
+ user_may_join_room = user_may_join_room ,
223
+ user_may_invite = user_may_invite ,
224
+ user_may_send_3pid_invite = user_may_send_3pid_invite ,
225
+ user_may_create_room = user_may_create_room ,
226
+ user_may_create_room_with_invites = user_may_create_room_with_invites ,
227
+ user_may_create_room_alias = user_may_create_room_alias ,
228
+ user_may_publish_room = user_may_publish_room ,
229
+ check_username_for_spam = check_username_for_spam ,
230
+ check_registration_for_spam = check_registration_for_spam ,
231
+ check_media_file_for_spam = check_media_file_for_spam ,
232
+ )
166
233
167
- @property
168
- def register_account_validity_callbacks (self ):
234
+ def register_account_validity_callbacks (
235
+ self ,
236
+ is_user_expired : Optional [IS_USER_EXPIRED_CALLBACK ] = None ,
237
+ on_user_registration : Optional [ON_USER_REGISTRATION_CALLBACK ] = None ,
238
+ on_legacy_send_mail : Optional [ON_LEGACY_SEND_MAIL_CALLBACK ] = None ,
239
+ on_legacy_renew : Optional [ON_LEGACY_RENEW_CALLBACK ] = None ,
240
+ on_legacy_admin_request : Optional [ON_LEGACY_ADMIN_REQUEST ] = None ,
241
+ ) -> None :
169
242
"""Registers callbacks for account validity capabilities.
170
243
171
244
Added in Synapse v1.39.0.
172
245
"""
173
- return self ._account_validity_handler .register_account_validity_callbacks
246
+ return self ._account_validity_handler .register_account_validity_callbacks (
247
+ is_user_expired = is_user_expired ,
248
+ on_user_registration = on_user_registration ,
249
+ on_legacy_send_mail = on_legacy_send_mail ,
250
+ on_legacy_renew = on_legacy_renew ,
251
+ on_legacy_admin_request = on_legacy_admin_request ,
252
+ )
174
253
175
- @property
176
- def register_third_party_rules_callbacks (self ):
254
+ def register_third_party_rules_callbacks (
255
+ self ,
256
+ check_event_allowed : Optional [CHECK_EVENT_ALLOWED_CALLBACK ] = None ,
257
+ on_create_room : Optional [ON_CREATE_ROOM_CALLBACK ] = None ,
258
+ check_threepid_can_be_invited : Optional [
259
+ CHECK_THREEPID_CAN_BE_INVITED_CALLBACK
260
+ ] = None ,
261
+ check_visibility_can_be_modified : Optional [
262
+ CHECK_VISIBILITY_CAN_BE_MODIFIED_CALLBACK
263
+ ] = None ,
264
+ on_new_event : Optional [ON_NEW_EVENT_CALLBACK ] = None ,
265
+ ) -> None :
177
266
"""Registers callbacks for third party event rules capabilities.
178
267
179
268
Added in Synapse v1.39.0.
180
269
"""
181
- return self ._third_party_event_rules .register_third_party_rules_callbacks
270
+ return self ._third_party_event_rules .register_third_party_rules_callbacks (
271
+ check_event_allowed = check_event_allowed ,
272
+ on_create_room = on_create_room ,
273
+ check_threepid_can_be_invited = check_threepid_can_be_invited ,
274
+ check_visibility_can_be_modified = check_visibility_can_be_modified ,
275
+ on_new_event = on_new_event ,
276
+ )
182
277
183
- @property
184
- def register_presence_router_callbacks (self ):
278
+ def register_presence_router_callbacks (
279
+ self ,
280
+ get_users_for_states : Optional [GET_USERS_FOR_STATES_CALLBACK ] = None ,
281
+ get_interested_users : Optional [GET_INTERESTED_USERS_CALLBACK ] = None ,
282
+ ) -> None :
185
283
"""Registers callbacks for presence router capabilities.
186
284
187
285
Added in Synapse v1.42.0.
188
286
"""
189
- return self ._presence_router .register_presence_router_callbacks
287
+ return self ._presence_router .register_presence_router_callbacks (
288
+ get_users_for_states = get_users_for_states ,
289
+ get_interested_users = get_interested_users ,
290
+ )
190
291
191
- @property
192
- def register_password_auth_provider_callbacks (self ):
292
+ def register_password_auth_provider_callbacks (
293
+ self ,
294
+ check_3pid_auth : Optional [CHECK_3PID_AUTH_CALLBACK ] = None ,
295
+ on_logged_out : Optional [ON_LOGGED_OUT_CALLBACK ] = None ,
296
+ auth_checkers : Optional [
297
+ Dict [Tuple [str , Tuple [str , ...]], CHECK_AUTH_CALLBACK ]
298
+ ] = None ,
299
+ ) -> None :
193
300
"""Registers callbacks for password auth provider capabilities.
194
301
195
302
Added in Synapse v1.46.0.
196
303
"""
197
- return self ._password_auth_provider .register_password_auth_provider_callbacks
304
+ return self ._password_auth_provider .register_password_auth_provider_callbacks (
305
+ check_3pid_auth = check_3pid_auth ,
306
+ on_logged_out = on_logged_out ,
307
+ auth_checkers = auth_checkers ,
308
+ )
198
309
199
310
def register_web_resource (self , path : str , resource : Resource ):
200
311
"""Registers a web resource to be served at the given path.
@@ -216,7 +327,7 @@ def register_web_resource(self, path: str, resource: Resource):
216
327
# The following methods can be called by the module at any point in time.
217
328
218
329
@property
219
- def http_client (self ):
330
+ def http_client (self ) -> SimpleHttpClient :
220
331
"""Allows making outbound HTTP requests to remote resources.
221
332
222
333
An instance of synapse.http.client.SimpleHttpClient
@@ -226,7 +337,7 @@ def http_client(self):
226
337
return self ._http_client
227
338
228
339
@property
229
- def public_room_list_manager (self ):
340
+ def public_room_list_manager (self ) -> "PublicRoomListManager" :
230
341
"""Allows adding to, removing from and checking the status of rooms in the
231
342
public room list.
232
343
@@ -309,7 +420,7 @@ async def is_user_admin(self, user_id: str) -> bool:
309
420
"""
310
421
return await self ._store .is_server_admin (UserID .from_string (user_id ))
311
422
312
- def get_qualified_user_id (self , username ) :
423
+ def get_qualified_user_id (self , username : str ) -> str :
313
424
"""Qualify a user id, if necessary
314
425
315
426
Takes a user id provided by the user and adds the @ and :domain to
@@ -318,7 +429,7 @@ def get_qualified_user_id(self, username):
318
429
Added in Synapse v0.25.0.
319
430
320
431
Args:
321
- username (str) : provided user id
432
+ username: provided user id
322
433
323
434
Returns:
324
435
str: qualified @user:id
@@ -357,13 +468,13 @@ async def get_threepids_for_user(self, user_id: str) -> List[Dict[str, str]]:
357
468
"""
358
469
return await self ._store .user_get_threepids (user_id )
359
470
360
- def check_user_exists (self , user_id ):
471
+ def check_user_exists (self , user_id : str ):
361
472
"""Check if user exists.
362
473
363
474
Added in Synapse v0.25.0.
364
475
365
476
Args:
366
- user_id (str) : Complete @user:id
477
+ user_id: Complete @user:id
367
478
368
479
Returns:
369
480
Deferred[str|None]: Canonical (case-corrected) user_id, or None
0 commit comments