@@ -11,7 +11,7 @@ The available spam checker callbacks are:
11
11
### ` check_event_for_spam `
12
12
13
13
_ First introduced in Synapse v1.37.0_
14
- _ Signature extended to support Allow and Code in Synapse v1.60.0_
14
+ _ Signature extended to support Allow and Codes in Synapse v1.60.0_
15
15
_ Boolean and string return value types deprecated in Synapse v1.60.0_
16
16
17
17
``` python
@@ -38,14 +38,22 @@ will not call any of the subsequent implementations of this callback.
38
38
# ## `user_may_join_room`
39
39
40
40
_First introduced in Synapse v1.37.0_
41
+ _Signature extended to support Allow and Codes in Synapse v1.60.0_
42
+ _Boolean return value type deprecated in Synapse v1.60.0_
41
43
42
44
```python
43
- async def user_may_join_room (user : str , room : str , is_invited : bool ) -> bool
45
+ async def user_may_join_room (user : str , room : str , is_invited : bool ) -> Union[ " synapse.module_api.ALLOW " , " synapse.module_api.error.Codes " , bool ]
44
46
```
45
47
46
- Called when a user is trying to join a room. The module must return a `bool ` to indicate
47
- whether the user can join the room. Return `False ` to prevent the user from joining the
48
- room; otherwise return `True ` to permit the joining.
48
+ Called when a user is trying to join a room. The callback must return either:
49
+ - `synapse.module_api.ALLOW ` , to allow the operation. Other callbacks
50
+ may still decide to reject it.
51
+ - `synapse.api.Codes` to reject the operation with an error code. In case
52
+ of doubt, `synapse.api.error.Codes.FORBIDDEN ` is a good error code.
53
+ - (deprecated) on `True ` , behave as `ALLOW ` . Deprecated as confusing, as some
54
+ callbacks in expect `True ` to allow and others `True ` to reject.
55
+ - (deprecated) on `False ` , behave as `synapse.api.error.Codes.FORBIDDEN ` . Deprecated as confusing, as
56
+ some callbacks in expect `True ` to allow and others `True ` to reject.
49
57
50
58
The user is represented by their Matrix user ID (e.g.
51
59
`@ alice:example.com` ) and the room is represented by its Matrix ID (e.g.
@@ -55,46 +63,52 @@ currently has a pending invite in the room.
55
63
This callback isn' t called if the join is performed by a server administrator, or in the
56
64
context of a room creation.
57
65
58
- If multiple modules implement this callback, they will be considered in order. If a
59
- callback returns `True ` , Synapse falls through to the next one. The value of the first
60
- callback that does not return `True ` will be used. If this happens, Synapse will not call
61
- any of the subsequent implementations of this callback.
62
-
63
66
# ## `user_may_invite`
64
67
65
68
_First introduced in Synapse v1.37.0_
69
+ _Signature extended to support Allow and Codes in Synapse v1.60.0_
70
+ _Boolean return value type deprecated in Synapse v1.60.0_
66
71
67
72
```python
68
- async def user_may_invite(inviter: str , invitee: str , room_id: str ) -> bool
73
+ async def user_may_invite (inviter : str , invitee : str , room_id : str ) -> Union[ " synapse.module_api.ALLOW " , " synapse.module_api.error.Codes " , bool ]
69
74
```
70
75
71
- Called when processing an invitation. The module must return a `bool ` indicating whether
72
- the inviter can invite the invitee to the given room. Both inviter and invitee are
73
- represented by their Matrix user ID (e.g. `@ alice:example.com` ). Return `False ` to prevent
74
- the invitation; otherwise return `True ` to permit it.
76
+ Called when processing an invitation. Called when a user is trying to join a room. The callback must return either:
77
+ - `synapse.module_api.ALLOW ` , to allow the operation. Other callbacks
78
+ may still decide to reject it.
79
+ - `synapse.api.Codes` to reject the operation with an error code. In case
80
+ of doubt, `synapse.api.error.Codes.FORBIDDEN ` is a good error code.
81
+ - (deprecated) on `True ` , behave as `ALLOW ` . Deprecated as confusing, as some
82
+ callbacks in expect `True ` to allow and others `True ` to reject.
83
+ - (deprecated) on `False ` , behave as `synapse.api.error.Codes.FORBIDDEN ` . Deprecated as confusing, as
84
+ some callbacks in expect `True ` to allow and others `True ` to reject.
75
85
76
- If multiple modules implement this callback, they will be considered in order. If a
77
- callback returns `True ` , Synapse falls through to the next one. The value of the first
78
- callback that does not return `True ` will be used. If this happens, Synapse will not call
79
- any of the subsequent implementations of this callback.
80
86
81
87
# ## `user_may_send_3pid_invite`
82
88
83
89
_First introduced in Synapse v1.45.0_
90
+ _Signature extended to support Allow and Codes in Synapse v1.60.0_
91
+ _Boolean return value type deprecated in Synapse v1.60.0_
84
92
85
93
```python
86
94
async def user_may_send_3pid_invite (
87
95
inviter : str ,
88
96
medium : str ,
89
97
address : str ,
90
98
room_id : str ,
91
- ) -> bool
99
+ ) -> Union[ " synapse.module_api.ALLOW " , " synapse.module_api.error.Codes " , bool ]
92
100
```
93
101
94
- Called when processing an invitation using a third- party identifier (also called a 3PID ,
95
- e.g. an email address or a phone number). The module must return a `bool ` indicating
96
- whether the inviter can invite the invitee to the given room. Return `False ` to prevent
97
- the invitation; otherwise return `True ` to permit it.
102
+ Called when processing an invitation using a third- party identifier (also called a 3PID ,
103
+ e.g. an email address or a phone number). The callback must return either:
104
+ - `synapse.module_api.ALLOW ` , to allow the operation. Other callbacks
105
+ may still decide to reject it.
106
+ - `synapse.api.Codes` to reject the operation with an error code. In case
107
+ of doubt, `synapse.api.error.Codes.FORBIDDEN ` is a good error code.
108
+ - (deprecated) on `True ` , behave as `ALLOW ` . Deprecated as confusing, as some
109
+ callbacks in expect `True ` to allow and others `True ` to reject.
110
+ - (deprecated) on `False ` , behave as `synapse.api.error.Codes.FORBIDDEN ` . Deprecated as confusing, as
111
+ some callbacks in expect `True ` to allow and others `True ` to reject.
98
112
99
113
The inviter is represented by their Matrix user ID (e.g. `@ alice:example.com` ), and the
100
114
invitee is represented by its medium (e.g. " email" ) and its address
@@ -124,55 +138,62 @@ any of the subsequent implementations of this callback.
124
138
# ## `user_may_create_room`
125
139
126
140
_First introduced in Synapse v1.37.0_
141
+ _Signature extended to support Allow and Codes in Synapse v1.60.0_
142
+ _Boolean return value type deprecated in Synapse v1.60.0_
127
143
128
144
```python
129
- async def user_may_create_room(user: str ) -> bool
145
+ async def user_may_create_room(user: str ) -> Union[ " synapse.module_api.ALLOW " , " synapse.module_api.error.Codes " , bool ]
130
146
```
131
147
132
- Called when processing a room creation request. The module must return a `bool ` indicating
133
- whether the given user (represented by their Matrix user ID ) is allowed to create a room.
134
- Return `False ` to prevent room creation; otherwise return `True ` to permit it.
135
-
136
- If multiple modules implement this callback, they will be considered in order. If a
137
- callback returns `True ` , Synapse falls through to the next one. The value of the first
138
- callback that does not return `True ` will be used. If this happens, Synapse will not call
139
- any of the subsequent implementations of this callback.
148
+ Called when processing a room creation request. The callback must return either:
149
+ - `synapse.module_api.ALLOW ` , to allow the operation. Other callbacks
150
+ may still decide to reject it.
151
+ - `synapse.api.Codes` to reject the operation with an error code. In case
152
+ of doubt, `synapse.api.error.Codes.FORBIDDEN ` is a good error code.
153
+ - (deprecated) on `True ` , behave as `ALLOW ` . Deprecated as confusing, as some
154
+ callbacks in expect `True ` to allow and others `True ` to reject.
155
+ - (deprecated) on `False ` , behave as `synapse.api.error.Codes.FORBIDDEN ` . Deprecated as confusing, as
156
+ some callbacks in expect `True ` to allow and others `True ` to reject.
140
157
141
158
# ## `user_may_create_room_alias`
142
159
143
160
_First introduced in Synapse v1.37.0_
161
+ _Signature extended to support Allow and Codes in Synapse v1.60.0_
162
+ _Boolean return value type deprecated in Synapse v1.60.0_
144
163
145
164
```python
146
165
async def user_may_create_room_alias(user: str , room_alias: " synapse.types.RoomAlias" ) -> bool
147
166
```
148
167
149
- Called when trying to associate an alias with an existing room. The module must return a
150
- ` bool ` indicating whether the given user (represented by their Matrix user ID ) is allowed
151
- to set the given alias. Return ` False ` to prevent the alias creation; otherwise return
152
- ` True ` to permit it.
153
-
154
- If multiple modules implement this callback, they will be considered in order. If a
155
- callback returns ` True ` , Synapse falls through to the next one. The value of the first
156
- callback that does not return ` True ` will be used. If this happens, Synapse will not call
157
- any of the subsequent implementations of this callback .
168
+ Called when trying to associate an alias with an existing room. The callback must return either:
169
+ - `synapse.module_api. ALLOW ` , to allow the operation. Other callbacks
170
+ may still decide to reject it.
171
+ - `synapse.api.Codes ` to reject the operation with an error code. In case
172
+ of doubt, `synapse.api.error.Codes. FORBIDDEN ` is a good error code.
173
+ - (deprecated) on ` True ` , behave as ` ALLOW ` . Deprecated as confusing, as some
174
+ callbacks in expect ` True ` to allow and others ` True ` to reject.
175
+ - (deprecated) on ` False ` , behave as `synapse.api.error.Codes. FORBIDDEN ` . Deprecated as confusing, as
176
+ some callbacks in expect ` True ` to allow and others ` True ` to reject .
158
177
159
178
# ## `user_may_publish_room`
160
179
161
180
_First introduced in Synapse v1.37.0_
181
+ _Signature extended to support Allow and Codes in Synapse v1.60.0_
182
+ _Boolean return value type deprecated in Synapse v1.60.0_
162
183
163
184
```python
164
- async def user_may_publish_room(user: str , room_id: str ) -> bool
185
+ async def user_may_publish_room(user: str , room_id: str ) -> Union[ " synapse.module_api.ALLOW " , " synapse.module_api.error.Codes " , bool ]
165
186
```
166
187
167
- Called when trying to publish a room to the homeserver' s public rooms directory. The
168
- module must return a ` bool ` indicating whether the given user (represented by their
169
- Matrix user ID ) is allowed to publish the given room. Return ` False ` to prevent the
170
- room from being published; otherwise return ` True ` to permit its publication.
171
-
172
- If multiple modules implement this callback, they will be considered in order. If a
173
- callback returns ` True ` , Synapse falls through to the next one. The value of the first
174
- callback that does not return ` True ` will be used. If this happens, Synapse will not call
175
- any of the subsequent implementations of this callback .
188
+ Called when trying to publish a room to the homeserver' s public rooms directory. The callback must return either:
189
+ - `synapse.module_api. ALLOW ` , to allow the operation. Other callbacks
190
+ may still decide to reject it.
191
+ - `synapse.api.Codes ` to reject the operation with an error code. In case
192
+ of doubt, `synapse.api.error.Codes. FORBIDDEN ` is a good error code.
193
+ - (deprecated) on ` True ` , behave as ` ALLOW ` . Deprecated as confusing, as some
194
+ callbacks in expect ` True ` to allow and others ` True ` to reject.
195
+ - (deprecated) on ` False ` , behave as `synapse.api.error.Codes. FORBIDDEN ` . Deprecated as confusing, as
196
+ some callbacks in expect ` True ` to allow and others ` True ` to reject .
176
197
177
198
# ## `check_username_for_spam`
178
199
@@ -239,22 +260,25 @@ this callback.
239
260
# ## `check_media_file_for_spam`
240
261
241
262
_First introduced in Synapse v1.37.0_
263
+ _Signature extended to support Allow and Codes in Synapse v1.60.0_
264
+ _Boolean return value type deprecated in Synapse v1.60.0_
242
265
243
266
```python
244
267
async def check_media_file_for_spam(
245
268
file_wrapper: " synapse.rest.media.v1.media_storage.ReadableFileWrapper" ,
246
269
file_info: " synapse.rest.media.v1._base.FileInfo" ,
247
- ) -> bool
270
+ ) -> Union[ " synapse.module_api.ALLOW " , " synapse.module_api.error.Codes " , bool ]
248
271
```
249
272
250
- Called when storing a local or remote file . The module must return a `bool ` indicating
251
- whether the given file should be excluded from the homeserver' s media store. Return
252
- `True ` to prevent this file from being stored; otherwise return `False ` .
253
-
254
- If multiple modules implement this callback, they will be considered in order. If a
255
- callback returns `False ` , Synapse falls through to the next one. The value of the first
256
- callback that does not return `False ` will be used. If this happens, Synapse will not call
257
- any of the subsequent implementations of this callback.
273
+ Called when storing a local or remote file . The callback must return either:
274
+ - `synapse.module_api.ALLOW ` , to allow the operation. Other callbacks
275
+ may still decide to reject it.
276
+ - `synapse.api.Codes` to reject the operation with an error code. In case
277
+ of doubt, `synapse.api.error.Codes.FORBIDDEN ` is a good error code.
278
+ - (deprecated) on `True ` , behave as `ALLOW ` . Deprecated as confusing, as some
279
+ callbacks in expect `True ` to allow and others `True ` to reject.
280
+ - (deprecated) on `False ` , behave as `synapse.api.error.Codes.FORBIDDEN ` . Deprecated as confusing, as
281
+ some callbacks in expect `True ` to allow and others `True ` to reject.
258
282
259
283
# # Example
260
284
@@ -299,6 +323,8 @@ class ListSpamChecker:
299
323
resource = IsUserEvilResource(config),
300
324
)
301
325
302
- async def check_event_for_spam(self , event: " synapse.events.EventBase" ) -> Union[bool , str ]:
303
- return event.sender not in self .evil_users
326
+ async def check_event_for_spam(self , event: " synapse.events.EventBase" ) -> Union[" synapse.module_api.ALLOW" , " synapse.module_api.error.Codes" ]:
327
+ if event.sender not in self .evil_users:
328
+ return synapse.module_api.ALLOW
329
+ return synapse.module_api.error.Codes.FORBIDDEN
304
330
```
0 commit comments