You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Port spam-checker API callbacks `user_may_join_room`, `user_may_invite`, `user_may_send_3pid_invite`, `user_may_create_room`, `user_may_create_room_alias`, `user_may_publish_room`, `check_media_file_for_spam` to more powerful and less ambiguous `Union[Allow, Codes]`.
1
+
Port spam-checker API callbacks `user_may_join_room`, `user_may_invite`, `user_may_send_3pid_invite`, `user_may_create_room`, `user_may_create_room_alias`, `user_may_publish_room`, `check_media_file_for_spam` to more powerful and less ambiguous `Union[Literal["NOT_SPAM"], Codes]`. This is a followup to #12703, #12808, #12846 and builds towards giving the spam-checker API the ability to inform users of *why* their event or operation has been rejected.
Copy file name to clipboardexpand all lines: docs/modules/spam_checker_callbacks.md
+138-58
Original file line number
Diff line number
Diff line change
@@ -38,62 +38,83 @@ this callback.
38
38
39
39
_First introduced in Synapse v1.37.0_
40
40
41
+
_Changed in Synapse v1.60.0: `synapse.module_api.NOT_SPAM`and`synapse.module_api.errors.Codes` can be returned by this callback. Returning a boolean is now deprecated._
Called when a user is trying to join a room. The module must return a `bool` to indicate
46
-
whether the user can join the room. Return `False` to prevent the user from joining the
47
-
room; otherwise return`True` to permit the joining.
48
-
49
-
The user is represented by their Matrix user ID (e.g.
47
+
Called when a user is trying to join a room. The user is represented by their Matrix user ID (e.g.
50
48
`@alice:example.com`) and the room is represented by its Matrix ID (e.g.
51
49
`!room:example.com`). The module is also given a boolean to indicate whether the user
52
50
currently has a pending invite in the room.
53
51
54
-
This callback isn't called if the join is performed by a server administrator, or in the
55
-
context of a room creation.
52
+
The callback must return one of:
53
+
-`synapse.module_api.NOT_SPAM`, to allow the operation. Other callbacks may still
54
+
decide to reject it.
55
+
-`synapse.module_api.errors.Codes` to reject the operation with an error code. In case
56
+
of doubt, `synapse.module_api.errors.Codes.FORBIDDEN`is a good error code.
57
+
typically will not localize the error message to the user's preferred locale.
58
+
- (deprecated) `False`, which is the same as returning `synapse.module_api.NOT_SPAM`.
59
+
- (deprecated) `True`, which is the same as returning `synapse.module_api.errors.Codes.FORBIDDEN`.
56
60
57
61
If multiple modules implement this callback, they will be considered in order. If a
58
-
callback returns `True`, Synapse falls through to the next one. The value of the first
59
-
callback that does notreturn`True` will be used. If this happens, Synapse will not call
60
-
any of the subsequent implementations of this callback.
62
+
callback returns `synapse.module_api.NOT_SPAM`, Synapse falls through to the next one.
63
+
The value of the first callback that does notreturn`synapse.module_api.NOT_SPAM` will
64
+
be used. If this happens, Synapse will not call any of the subsequent implementations of
65
+
this callback.
66
+
67
+
68
+
This callback isn't called if the join is performed by a server administrator, or in the
69
+
context of a room creation.
61
70
62
71
### `user_may_invite`
63
72
64
73
_First introduced in Synapse v1.37.0_
65
74
75
+
_Changed in Synapse v1.60.0: `synapse.module_api.NOT_SPAM`and`synapse.module_api.errors.Codes` can be returned by this callback. Returning a boolean is now deprecated._
Called when processing an invitation. The module must return a `bool` indicating whether
71
-
the inviter can invite the invitee to the given room. Both inviter and invitee are
72
-
represented by their Matrix user ID (e.g. `@alice:example.com`). Return `False` to prevent
73
-
the invitation; otherwise return`True` to permit it.
81
+
Called when processing an invitation. Both inviter and invitee are
82
+
represented by their Matrix user ID (e.g. `@alice:example.com`).
83
+
84
+
85
+
The callback must return one of:
86
+
-`synapse.module_api.NOT_SPAM`, to allow the operation. Other callbacks may still
87
+
decide to reject it.
88
+
-`synapse.module_api.errors.Codes` to reject the operation with an error code. In case
89
+
of doubt, `synapse.module_api.errors.Codes.FORBIDDEN`is a good error code.
90
+
typically will not localize the error message to the user's preferred locale.
91
+
- (deprecated) `False`, which is the same as returning `synapse.module_api.NOT_SPAM`.
92
+
- (deprecated) `True`, which is the same as returning `synapse.module_api.errors.Codes.FORBIDDEN`.
74
93
75
94
If multiple modules implement this callback, they will be considered in order. If a
76
-
callback returns `True`, Synapse falls through to the next one. The value of the first
77
-
callback that does notreturn`True` will be used. If this happens, Synapse will not call
78
-
any of the subsequent implementations of this callback.
95
+
callback returns `synapse.module_api.NOT_SPAM`, Synapse falls through to the next one.
96
+
The value of the first callback that does notreturn`synapse.module_api.NOT_SPAM` will
97
+
be used. If this happens, Synapse will not call any of the subsequent implementations of
98
+
this callback.
99
+
79
100
80
101
### `user_may_send_3pid_invite`
81
102
82
103
_First introduced in Synapse v1.45.0_
83
104
105
+
_Changed in Synapse v1.60.0: `synapse.module_api.NOT_SPAM`and`synapse.module_api.errors.Codes` can be returned by this callback. Returning a boolean is now deprecated._
**Note**: If the third-party identifier is already associated with a matrix user ID,
116
137
[`user_may_invite`](#user_may_invite) will be used instead.
117
138
139
+
The callback must return one of:
140
+
-`synapse.module_api.NOT_SPAM`, to allow the operation. Other callbacks may still
141
+
decide to reject it.
142
+
-`synapse.module_api.errors.Codes` to reject the operation with an error code. In case
143
+
of doubt, `synapse.module_api.errors.Codes.FORBIDDEN`is a good error code.
144
+
typically will not localize the error message to the user's preferred locale.
145
+
- (deprecated) `False`, which is the same as returning `synapse.module_api.NOT_SPAM`.
146
+
- (deprecated) `True`, which is the same as returning `synapse.module_api.errors.Codes.FORBIDDEN`.
147
+
118
148
If multiple modules implement this callback, they will be considered in order. If a
119
-
callback returns `True`, Synapse falls through to the next one. The value of the first
120
-
callback that does notreturn`True` will be used. If this happens, Synapse will not call
121
-
any of the subsequent implementations of this callback.
149
+
callback returns `synapse.module_api.NOT_SPAM`, Synapse falls through to the next one.
150
+
The value of the first callback that does notreturn`synapse.module_api.NOT_SPAM` will
151
+
be used. If this happens, Synapse will not call any of the subsequent implementations of
152
+
this callback.
153
+
122
154
123
155
### `user_may_create_room`
124
156
125
157
_First introduced in Synapse v1.37.0_
126
158
159
+
_Changed in Synapse v1.60.0: `synapse.module_api.NOT_SPAM`and`synapse.module_api.errors.Codes` can be returned by this callback. Returning a boolean is now deprecated._
Called when processing a room creation request. The module must return a `bool` indicating
132
-
whether the given user (represented by their Matrix user ID) is allowed to create a room.
133
-
Return `False` to prevent room creation; otherwise return`True` to permit it.
165
+
Called when processing a room creation request.
166
+
167
+
The callback must return one of:
168
+
-`synapse.module_api.NOT_SPAM`, to allow the operation. Other callbacks may still
169
+
decide to reject it.
170
+
-`synapse.module_api.errors.Codes` to reject the operation with an error code. In case
171
+
of doubt, `synapse.module_api.errors.Codes.FORBIDDEN`is a good error code.
172
+
typically will not localize the error message to the user's preferred locale.
173
+
- (deprecated) `False`, which is the same as returning `synapse.module_api.NOT_SPAM`.
174
+
- (deprecated) `True`, which is the same as returning `synapse.module_api.errors.Codes.FORBIDDEN`.
134
175
135
176
If multiple modules implement this callback, they will be considered in order. If a
136
-
callback returns `True`, Synapse falls through to the next one. The value of the first
137
-
callback that does notreturn`True` will be used. If this happens, Synapse will not call
138
-
any of the subsequent implementations of this callback.
177
+
callback returns `synapse.module_api.NOT_SPAM`, Synapse falls through to the next one.
178
+
The value of the first callback that does notreturn`synapse.module_api.NOT_SPAM` will
179
+
be used. If this happens, Synapse will not call any of the subsequent implementations of
180
+
this callback.
181
+
182
+
139
183
140
184
### `user_may_create_room_alias`
141
185
142
186
_First introduced in Synapse v1.37.0_
143
187
188
+
_Changed in Synapse v1.60.0: `synapse.module_api.NOT_SPAM`and`synapse.module_api.errors.Codes` can be returned by this callback. Returning a boolean is now deprecated._
Called when trying to associate an alias with an existing room. The module must return a
149
-
`bool` indicating whether the given user (represented by their Matrix user ID) is allowed
150
-
to set the given alias. Return `False` to prevent the alias creation; otherwise return
151
-
`True` to permit it.
194
+
Called when trying to associate an alias with an existing room.
195
+
196
+
The callback must return one of:
197
+
-`synapse.module_api.NOT_SPAM`, to allow the operation. Other callbacks may still
198
+
decide to reject it.
199
+
-`synapse.module_api.errors.Codes` to reject the operation with an error code. In case
200
+
of doubt, `synapse.module_api.errors.Codes.FORBIDDEN`is a good error code.
201
+
typically will not localize the error message to the user's preferred locale.
202
+
- (deprecated) `False`, which is the same as returning `synapse.module_api.NOT_SPAM`.
203
+
- (deprecated) `True`, which is the same as returning `synapse.module_api.errors.Codes.FORBIDDEN`.
152
204
153
205
If multiple modules implement this callback, they will be considered in order. If a
154
-
callback returns `True`, Synapse falls through to the next one. The value of the first
155
-
callback that does notreturn`True` will be used. If this happens, Synapse will not call
156
-
any of the subsequent implementations of this callback.
206
+
callback returns `synapse.module_api.NOT_SPAM`, Synapse falls through to the next one.
207
+
The value of the first callback that does notreturn`synapse.module_api.NOT_SPAM` will
208
+
be used. If this happens, Synapse will not call any of the subsequent implementations of
209
+
this callback.
210
+
211
+
157
212
158
213
### `user_may_publish_room`
159
214
160
215
_First introduced in Synapse v1.37.0_
161
216
217
+
_Changed in Synapse v1.60.0: `synapse.module_api.NOT_SPAM`and`synapse.module_api.errors.Codes` can be returned by this callback. Returning a boolean is now deprecated._
Called when trying to publish a room to the homeserver's public rooms directory. The
167
-
module must return a `bool` indicating whether the given user (represented by their
168
-
Matrix user ID) is allowed to publish the given room. Return `False` to prevent the
169
-
room from being published; otherwise return`True` to permit its publication.
223
+
Called when trying to publish a room to the homeserver's public rooms directory.
224
+
225
+
The callback must return one of:
226
+
-`synapse.module_api.NOT_SPAM`, to allow the operation. Other callbacks may still
227
+
decide to reject it.
228
+
-`synapse.module_api.errors.Codes` to reject the operation with an error code. In case
229
+
of doubt, `synapse.module_api.errors.Codes.FORBIDDEN`is a good error code.
230
+
typically will not localize the error message to the user's preferred locale.
231
+
- (deprecated) `False`, which is the same as returning `synapse.module_api.NOT_SPAM`.
232
+
- (deprecated) `True`, which is the same as returning `synapse.module_api.errors.Codes.FORBIDDEN`.
170
233
171
234
If multiple modules implement this callback, they will be considered in order. If a
172
-
callback returns `True`, Synapse falls through to the next one. The value of the first
173
-
callback that does notreturn`True` will be used. If this happens, Synapse will not call
174
-
any of the subsequent implementations of this callback.
235
+
callback returns `synapse.module_api.NOT_SPAM`, Synapse falls through to the next one.
236
+
The value of the first callback that does notreturn`synapse.module_api.NOT_SPAM` will
237
+
be used. If this happens, Synapse will not call any of the subsequent implementations of
238
+
this callback.
239
+
240
+
175
241
176
242
### `check_username_for_spam`
177
243
@@ -239,21 +305,32 @@ this callback.
239
305
240
306
_First introduced in Synapse v1.37.0_
241
307
308
+
_Changed in Synapse v1.60.0: `synapse.module_api.NOT_SPAM`and`synapse.module_api.errors.Codes` can be returned by this callback. Returning a boolean is now deprecated._
0 commit comments